feat(portfolio): M8.2 Portfolio Engine 模块化(等权收敛 + 约束显式标注)

- research.PortfolioSpec(weighting=equal;max_position_pct/max_industry_weight_pct 预留)
  + ResearchSpec.portfolio;config_snapshot 自动记录组合配置
- quant/portfolio.py:equal_weight_budget(与既有等权回测语义一致,行为收敛到本模块)+
  unimplemented_notes(设置约束即在结果中显式标注未建模,禁止假装支持)
- TopKBacktestRunner 预算与 unimplemented 改用 portfolio 模块;默认配置数值不变
  (一致性/quant 引擎回归通过);tests 补约束标注与 config_snapshot;全量 pytest 通过
This commit is contained in:
Simon
2026-09-09 00:36:38 +08:00
parent ba52edc2d6
commit 692bdb3be5
4 changed files with 72 additions and 2 deletions
+3 -2
View File
@@ -32,6 +32,7 @@ from app.quant.composite import ( # noqa: F401 —— re-export(模块化后
cross_sectional_zscore,
)
from app.quant.evaluation import run_factor_test
from app.quant.portfolio import equal_weight_budget, unimplemented_notes
TRADING_DAYS = 252
_DEFAULT_UNIMPLEMENTED = [
@@ -169,7 +170,7 @@ class TopKBacktestRunner:
targets.append(s)
if targets:
budget = cash / len(targets)
budget = equal_weight_budget(cash, len(targets))
for s in targets:
c = float(close_d[s])
price_in = c * (1 + self.costs.slippage_rate)
@@ -263,7 +264,7 @@ class TopKBacktestRunner:
positions=positions,
trades=trades,
turnover_pct=round(sum(notional) / max(init, 1) * 100, 2),
unimplemented=list(_DEFAULT_UNIMPLEMENTED),
unimplemented=list(_DEFAULT_UNIMPLEMENTED) + unimplemented_notes(self.spec.portfolio),
config_snapshot=self.spec.model_dump(mode="json"),
)