From 46794959a2494e9f765985b2c1016f0e08cccc84 Mon Sep 17 00:00:00 2001 From: hmo Date: Sat, 15 Aug 2026 03:09:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20window=5Freturn=E6=94=B9=E5=A4=8D?= =?UTF-8?q?=E5=88=A9=E5=87=80=E5=80=BC(8=E6=A7=BD=E7=AD=89=E6=9D=83),?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=AA=97=E5=8F=A3=E6=94=B6=E7=9B=8A=E5=B7=A8?= =?UTF-8?q?=E5=80=BCbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/hk_backtest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deploy/profile-scripts/hk_backtest.py b/deploy/profile-scripts/hk_backtest.py index d2c4626c..3224feee 100644 --- a/deploy/profile-scripts/hk_backtest.py +++ b/deploy/profile-scripts/hk_backtest.py @@ -99,14 +99,16 @@ def portfolio_metrics(trades, capital=1000000, slots=8): pf = lab.portfolio_sim(trades, capital, max_positions=slots) years_span = 7.5 cagr = pf.get("cagr_pct") - # 时间窗收益(按 entry_date 过滤 trades 做简单等权组合) + # 时间窗收益(按 entry_date 过滤 trades,8槽等权复利净值) def window_return(months): cutoff = (datetime(2026, 7, 24) - timedelta(days=int(months * 30.4))).strftime("%Y-%m-%d") wt = [t for t in trades if t["entry_date"] >= cutoff] if not wt: return None - tot = sum(t["profit_pct"] for t in wt) / slots - return tot + nav = 1.0 + for t in sorted(wt, key=lambda x: x["entry_date"]): + nav *= (1 + t["profit_pct"] / 100 / slots) + return (nav - 1) * 100 return { "cagr": cagr, "year1": window_return(12),