fix: window_return改复利净值(8槽等权),修正窗口收益巨值bug
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user