diff --git a/deploy/profile-scripts/regime_perf_by_period.py b/deploy/profile-scripts/regime_perf_by_period.py index fe9770ec..857d852b 100644 --- a/deploy/profile-scripts/regime_perf_by_period.py +++ b/deploy/profile-scripts/regime_perf_by_period.py @@ -160,6 +160,19 @@ def process_slice_period(conn, market, period_tag): pnl = sum(t.get('profit_pct') or 0 for t in reg_trades) hold = sum(t.get('hold_days') or 0 for t in reg_trades) n = len(reg_trades) + # 2026-08-18 修复:1m/6m/1y 切窗周期 cagr 缺失 → 激活矩阵三项永不齐 → 全灭。 + # 切窗数据短,用线性年化(total_return × 365/窗口实际跨度),与脚本头"线性放大"一致。 + _cagr = None + try: + _eds = [t.get('entry_date') for t in reg_trades if t.get('entry_date')] + if _eds and len(_eds) >= 2: + from datetime import datetime as _dts + _d0 = _dts.strptime(min(_eds), '%Y-%m-%d') + _d1 = _dts.strptime(max(_eds), '%Y-%m-%d') + _span = max((_d1 - _d0).days, 30) + _cagr = round(pnl * (365.0 / _span), 1) + except Exception: + _cagr = None conn.execute( "INSERT OR REPLACE INTO strategy_regime_perf_by_period " "(strategy, market, regime, period_tag, trades, win_rate, avg_pnl, avg_hold_days, " @@ -168,7 +181,7 @@ def process_slice_period(conn, market, period_tag): "universality_valid_years, universality_score, universality_leave1, updated_at) " "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (v, market, reg, period_tag, n, round(wins / n * 100, 1), round(pnl / n, 2), - round(hold / n, 1), round(pnl, 1), None, None, 0, n, None, None, + round(hold / n, 1), round(pnl, 1), _cagr, None, 0, n, None, None, 0, 0, 0, 0, 0, now)) written += 1 return written