From 845df7768b6efe031cdd3ecace5861b24da9767b Mon Sep 17 00:00:00 2001 From: xxm Date: Tue, 18 Aug 2026 21:02:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=87=E7=AA=97=E5=91=A8=E6=9C=9F(1m/?= =?UTF-8?q?6m/1y)cagr=E7=BC=BA=E5=A4=B1=E2=86=92=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E7=9F=A9=E9=98=B5=E4=B8=89=E9=A1=B9=E6=B0=B8=E4=B8=8D=E9=BD=90?= =?UTF-8?q?=E2=86=92=E5=85=A8=E7=81=AD=E3=80=82=E8=A1=A5=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E5=B9=B4=E5=8C=96(=E8=80=81=E8=8E=AB:=E4=B8=89=E6=B8=A9?= =?UTF-8?q?=E5=8C=BA=E9=83=BD=E6=9C=89=E5=90=88=E6=A0=BC=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E5=8D=B4=E6=B2=A1=E6=BF=80=E6=B4=BB=E6=98=AFbug)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/regime_perf_by_period.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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