feat(factor): C1 因子相关性分析(横截面 Spearman 矩阵 + API)
- evaluation.factor_correlation_report:多因子共同日期 ∩ 后逐日横截面 Spearman 相关 取均值 → FactorCorrelationReport(冗余剔除前置,v3 §12 Correlation→Redundancy) - ResearchService.run_factor_correlation + POST /api/factor-correlations (universe/factors/period;与其它研究同装配口径) - tests/test_factor_correlation.py:矩阵对角=1/近线性±相关符号/对称/无共同日期补零、 API 冒烟;全量 pytest 通过
This commit is contained in:
@@ -17,6 +17,7 @@ import pandas as pd
|
||||
|
||||
from app.domain.entities.research import (
|
||||
BacktestResult,
|
||||
FactorCorrelationReport,
|
||||
FactorTestReport,
|
||||
ResearchSpec,
|
||||
)
|
||||
@@ -24,7 +25,9 @@ from app.domain.repositories.market import (
|
||||
DailyBarRepository,
|
||||
StockRepository,
|
||||
)
|
||||
from app.quant.composite import build_factor_panels
|
||||
from app.quant.engine import QuantEngine
|
||||
from app.quant.evaluation import factor_correlation_report
|
||||
from app.quant.universe import filter_stocks, resolve_members # noqa: F401 —— 范围过滤
|
||||
|
||||
# 流式路径每攒多少行落一个 DataFrame 分片(控制 concat 峰值)
|
||||
@@ -129,6 +132,12 @@ class ResearchService:
|
||||
daily = self._load_daily(spec)
|
||||
return self._engine.run_backtest(daily, spec)
|
||||
|
||||
def run_factor_correlation(self, spec: ResearchSpec) -> FactorCorrelationReport:
|
||||
"""多因子两两相关(v3 §12):同 universe/period 装配 → 横截面相关矩阵。"""
|
||||
daily = self._load_daily(spec)
|
||||
panels = {fs.name: build_factor_panels(daily, [fs])[0][1] for fs in spec.factors}
|
||||
return factor_correlation_report(panels)
|
||||
|
||||
# ---- 数据装配 ----
|
||||
|
||||
def _load_daily(self, spec: ResearchSpec) -> pd.DataFrame:
|
||||
|
||||
Reference in New Issue
Block a user