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),