feat: 量化引擎加固 — 新增测试 + 数据/因子/回测层优化
- 新增 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 扩充配置项
This commit is contained in:
@@ -62,11 +62,15 @@ class BacktestReport:
|
||||
except AttributeError:
|
||||
return float(v) if v is not None else 0.0
|
||||
|
||||
# VectorBT 1.1.0 的 pf.value() 可能返回数字位置 index(0..n-1)。
|
||||
# 统一用它对应的交易日 index(close 已是规范化后的 DatetimeIndex),
|
||||
# 长度相等时按位置对齐,保证 equity/drawdown 的日期语义正确。
|
||||
equity = pf.value()
|
||||
equity = pd.Series(equity.values, index=close.index[: len(equity)])
|
||||
|
||||
if not isinstance(equity.index, pd.DatetimeIndex):
|
||||
equity.index = pd.to_datetime(equity.index, format="%Y%m%d")
|
||||
if not isinstance(equity.index, pd.DatetimeIndex) and len(equity) == len(close):
|
||||
equity.index = close.index
|
||||
elif not isinstance(equity.index, pd.DatetimeIndex):
|
||||
# 长度不等时尽力用 close 前缀对齐,避免异常
|
||||
equity.index = close.index[: len(equity)]
|
||||
|
||||
dd = equity / equity.cummax() - 1
|
||||
daily_ret = equity.pct_change().dropna()
|
||||
|
||||
Reference in New Issue
Block a user