"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
factors: pin Carhart's skip month and correct the text that described the old formula
Haozhe Wu6365a9eba96c
diff --git a/agent/src/factors/zoo/academic/LICENSE.md b/agent/src/factors/zoo/academic/LICENSE.mdindex d9232b1e4..845a28924 100644--- a/agent/src/factors/zoo/academic/LICENSE.md+++ b/agent/src/factors/zoo/academic/LICENSE.md@@ -55,8 +55,9 @@ volume-derived proxy:sort in the original).- CMA: negative 60-day change in log average volume (vs. asset-growthsort in the original).-- Carhart UMD: 12-month minus 1-month return (matches the original- construction; cross-sectional z-score added for ranking).+- Carhart UMD: return from t-252 to t-21, skipping the most recent month+ (matches the original construction; cross-sectional z-score added for+ ranking).- BAB: rolling 252-day Cov(stock, equal-weighted market)/Var(market),cross-sectional z-scored negative (vs. value-weighted market + separate1y-vol/5y-correlation windows + explicit leverage in the original).diff --git a/agent/src/factors/zoo/academic/carhart_mom.py b/agent/src/factors/zoo/academic/carhart_mom.pyindex f9c2357db..e7a06d135 100644--- a/agent/src/factors/zoo/academic/carhart_mom.py+++ b/agent/src/factors/zoo/academic/carhart_mom.py@@ -34,7 +34,8 @@ __alpha_meta__ = {'decay_horizon': 60,'min_warmup_bars': 252,'notes': (- 'Carhart (1997) UMD momentum factor. 12-month return minus 1-month return, '+ 'Carhart (1997) UMD momentum factor. Return from 12 months ago to 1 month '+ 'ago, so the most recent month is skipped and today\'s price never enters; ''cross-sectional z-score per date for long-short ranking. Top z-scores = ''winners. Constructed directly from prices, so this matches the original ''definition modulo the z-score wrapper. Canonical 252d window; declared 'diff --git a/agent/src/skills/strategy-dev-manager/examples.md b/agent/src/skills/strategy-dev-manager/examples.mdindex 2bfcd23a8..e3b140504 100644--- a/agent/src/skills/strategy-dev-manager/examples.md+++ b/agent/src/skills/strategy-dev-manager/examples.md@@ -44,7 +44,7 @@ Deduplication check:alpha_bench(zoo="academic", universe="equity_us", period="2015-2025")```-Result: the existing `academic_carhart_momentum` alpha has IC 0.92 with our formula. This is a variant (not a duplicate, since IC < 0.99), so we proceed with a note.+Result: the existing `academic_carhart_mom` alpha has IC 0.92 with our formula. This is a variant (not a duplicate, since IC < 0.99), so we proceed with a note.Register:@@ -89,10 +89,11 @@ Then implement `signal_engine.py` using the factor template, filling in the mome```python# Inside generate():for symbol, df in data_map.items():- # 12-month cumulative return, skip most recent month- ret_12m = df["close"].pct_change(12, fill_method=None).shift(1)- ret_1m = df["close"].pct_change(1, fill_method=None)- mom_signal = ret_12m - ret_1m # skip the most recent month+ # 12-1 momentum on daily bars: the return from 252 bars ago to 21 bars+ # ago. Skipping the most recent month means today's price never enters;+ # subtracting a 1-month return from a 12-month one does not do that.+ close = df["close"]+ mom_signal = close.shift(21) / close.shift(252) - 1signals[symbol] = mom_signal```diff --git a/agent/tests/factors/test_academic_samples.py b/agent/tests/factors/test_academic_samples.pyindex 8da6ef03f..8fbc789d4 100644--- a/agent/tests/factors/test_academic_samples.py+++ b/agent/tests/factors/test_academic_samples.py@@ -74,3 +74,26 @@ def test_academic_factor_matches_golden(alpha_id: str) -> None:equal_nan=True,err_msg=f"{alpha_id} output diverged from golden",)+++def test_carhart_momentum_skips_the_most_recent_month() -> None:+ """The last bar's value must not move with any close inside the skipped month.++ The golden above was regenerated together with the formula, so on its own it+ cannot tell a skip-month return from ``r_252 - r_21``, which moves with+ today's close. This checks the definition directly: scale one stock's closes+ over the last 21 bars and its value on the last bar is unchanged; scale its+ close 21 or 252 bars back and the value moves.+ """+ registry = Registry()+ panel = _build_panel()+ base = registry.compute("academic_carhart_mom", panel).iloc[-1]++ def last_bar_after_scaling(rows) -> pd.Series:+ bumped = {name: frame.copy() for name, frame in panel.items()}+ bumped["close"].iloc[rows, 0] *= 1.25+ return registry.compute("academic_carhart_mom", bumped).iloc[-1]++ pd.testing.assert_series_equal(last_bar_after_scaling(slice(-21, None)), base)+ assert last_bar_after_scaling([-22]).iloc[0] != pytest.approx(base.iloc[0])+ assert last_bar_after_scaling([-253]).iloc[0] != pytest.approx(base.iloc[0])diff --git a/wiki/alpha-library/i18n.zh.json b/wiki/alpha-library/i18n.zh.jsonindex 0bbdd4866..f0e7fa1e8 100644--- a/wiki/alpha-library/i18n.zh.json+++ b/wiki/alpha-library/i18n.zh.json@@ -5,8 +5,8 @@"zh": "Frazzini & Pedersen (2014) 低贝塔策略(BAB)。纯价格代理:市场收益率取每日个股收益率的截面均值(等权,而非原文的市值加权)。贝塔为单一 252 日窗口上的 Cov(r_i, r_m) / Var(r_m)(论文分别使用 1y 波动率窗口与 5y 相关系数窗口)。因子得分为负贝塔,经截面 z 分数标准化,使低贝塔标的排名最高,与原文多空构造中的多头腿一致。"},"academic_carhart_mom": {- "en": "Carhart (1997) UMD momentum factor. 12-month return minus 1-month return, cross-sectional z-score per date for long-short ranking. Top z-scores = winners. Constructed directly from prices, so this matches the original definition modulo the z-score wrapper. Canonical 252d window; declared decay_horizon=60 due to registry schema cap (le=60); real signal horizon=252.",- "zh": "Carhart (1997) UMD 动量因子。12 个月收益率减去 1 个月收益率,按日期做截面 z 分数,用于多空排名。z 分数最高 = 赢家。直接由价格构造,因此除外层的 z 分数变换外与原始定义一致。采用标准的 252d 窗口;受注册表 schema 上限(le=60)所限,声明 decay_horizon=60;实际信号周期=252。"+ "en": "Carhart (1997) UMD momentum factor. Return from 12 months ago to 1 month ago, so the most recent month is skipped and today's price never enters; cross-sectional z-score per date for long-short ranking. Top z-scores = winners. Constructed directly from prices, so this matches the original definition modulo the z-score wrapper. Canonical 252d window; declared decay_horizon=60 due to registry schema cap (le=60); real signal horizon=252.",+ "zh": "Carhart (1997) UMD 动量因子。从 12 个月前到 1 个月前的收益率,跳过最近一个月,当天价格不参与计算;按日期做截面 z 分数,用于多空排名。z 分数最高 = 赢家。直接由价格构造,因此除外层的 z 分数变换外与原始定义一致。采用标准的 252d 窗口;受注册表 schema 上限(le=60)所限,声明 decay_horizon=60;实际信号周期=252。"},"academic_cma": {"en": "[PRICE PROXY] for the Fama-French (2015) CMA (Conservative Minus Aggressive) investment factor. The original definition uses total-asset growth from fundamental data; here we use the negative 60-day change in log average volume as an activity-growth proxy, then cross-sectional z-score per date for long-short ranking. Top z-scores = volume contraction (conservative / low-growth proxy).",