- 新增 finance/tests/ 6 个测试套件(agents/backtest/dao_upsert/factors/features/fundamental_lookahead) - 数据层: data_manager / dao 优化,新增 upsert 逻辑 - 因子层: 基本面因子抽象定位 _mapping、ROE/PE/PB 重构 - 回测层: vectorbt/engine 大改动(251 行),report 增强 - ML 层: features/backtest_integration 特征工程与回测优化 - CLI: agent_cli 重构 - config/settings 扩充配置项
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""
|
|
Agent 抽象基类。
|
|
|
|
每个 Agent 负责一个独立任务,通过构造函数注入已有引擎,组合而非重建。
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from datetime import datetime
|
|
|
|
|
|
class BaseAgent(ABC):
|
|
"""Agent 基类。"""
|
|
|
|
name: str = ""
|
|
description: str = ""
|
|
|
|
def __init__(self, **engines):
|
|
"""
|
|
注入已有基础设施。
|
|
|
|
支持的引擎:
|
|
dm: DataManager
|
|
fe: FactorEngine
|
|
bt: VectorBTEngine
|
|
opt: OptunaEngine
|
|
sent: SentimentEngine
|
|
ml_models: dict[str, BaseModel]
|
|
feature_engine: FeatureEngine(已用模型训练集 fit 过,ML 打分需要)
|
|
"""
|
|
self.dm = engines.get("dm")
|
|
self.fe = engines.get("fe")
|
|
self.bt = engines.get("bt")
|
|
self.opt = engines.get("opt")
|
|
self.sent = engines.get("sent")
|
|
self.ml_models = engines.get("ml_models", {})
|
|
self.feature_engine = engines.get("feature_engine")
|
|
|
|
@abstractmethod
|
|
def execute(self, **kwargs) -> dict:
|
|
"""执行 Agent 任务,返回结构化结果。"""
|
|
...
|
|
|
|
def log(self, msg: str):
|
|
print(f"[{self.name}] {msg}")
|
|
|
|
def _today(self) -> str:
|
|
return datetime.now().strftime("%Y%m%d")
|