feat: improve US alpha pipeline and regime filters

Expand alpha pipeline with additional factors and scoring logic.
Update regime filters and add comprehensive test coverage.
This commit is contained in:
2026-05-14 12:52:55 +08:00
parent 0a2d646b26
commit 47755ff630
3 changed files with 295 additions and 31 deletions

View File

@@ -124,6 +124,118 @@ class USAlphaPipelineTests(unittest.TestCase):
self.assertEqual(len(summary), 2)
self.assertTrue(summary[["CAGR", "Sharpe", "MaxDD", "TotalRet"]].notna().all().all())
def test_run_alpha_pipeline_includes_fundamental_variants_when_score_is_supplied(self):
from research.us_alpha_pipeline import run_alpha_pipeline
dates = pd.date_range("2023-01-01", periods=400, freq="D")
close = pd.DataFrame(
{
"AAA": [50.0 + 0.20 * i for i in range(400)],
"BBB": [55.0 + 0.12 * i for i in range(400)],
"CCC": [60.0 + 0.05 * i for i in range(400)],
},
index=dates,
)
high = close + 1.0
low = close - 1.0
volume = pd.DataFrame(
{
"AAA": [1_500_000.0] * 400,
"BBB": [1_400_000.0] * 400,
"CCC": [1_300_000.0] * 400,
},
index=dates,
)
etf_close = pd.DataFrame(
{
"SPY": [300.0 + 0.8 * i for i in range(400)],
"QQQ": [280.0 + 1.1 * i for i in range(400)],
"XLF": [200.0 + 0.4 * i for i in range(400)],
},
index=dates,
)
market_data = {
"close": close,
"high": high,
"low": low,
"volume": volume,
}
fundamental_score = pd.DataFrame(
{
"AAA": [0.9] * 400,
"BBB": [0.6] * 400,
"CCC": [0.3] * 400,
},
index=dates,
)
summary = run_alpha_pipeline(
market_data=market_data,
etf_close=etf_close,
pit_membership=None,
windows=(1,),
top_n=2,
fundamental_score=fundamental_score,
)
self.assertEqual(
set(summary["strategy"]),
{
"breakout_regime",
"rank_blend_regime",
"fundamental_regime",
"breakout_fundamental_regime",
"rank_blend_fundamental_regime",
},
)
def test_run_alpha_pipeline_close_only_fallback_skips_breakout_and_uses_spy_regime(self):
from research.us_alpha_pipeline import run_alpha_pipeline
dates = pd.date_range("2023-01-01", periods=400, freq="D")
close = pd.DataFrame(
{
"AAA": [50.0 + 0.20 * i for i in range(400)],
"BBB": [55.0 + 0.12 * i for i in range(400)],
"CCC": [60.0 + 0.05 * i for i in range(400)],
},
index=dates,
)
market_data = {
"close": close,
"high": pd.DataFrame(index=dates, columns=close.columns),
"low": pd.DataFrame(index=dates, columns=close.columns),
"volume": pd.DataFrame(index=dates, columns=close.columns),
}
etf_close = pd.DataFrame({"SPY": [300.0 + 0.8 * i for i in range(400)]}, index=dates)
fundamental_score = pd.DataFrame(
{
"AAA": [0.9] * 400,
"BBB": [0.6] * 400,
"CCC": [0.3] * 400,
},
index=dates,
)
summary = run_alpha_pipeline(
market_data=market_data,
etf_close=etf_close,
pit_membership=None,
windows=(1,),
top_n=2,
fundamental_score=fundamental_score,
)
self.assertEqual(
set(summary["strategy"]),
{
"rank_blend_regime",
"fundamental_regime",
"rank_blend_fundamental_regime",
},
)
self.assertTrue(summary[["CAGR", "Sharpe", "MaxDD", "TotalRet"]].notna().all().all())
def test_run_saved_pit_alpha_pipeline_reads_saved_inputs(self):
from research.us_alpha_pipeline import run_saved_pit_alpha_pipeline