fix: порядок переменных в calc_metrics (UnboundLocalError)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-08 12:35:42 +10:00
co-authored by Claude Opus 4.6
parent 2b7d6f915e
commit c6e8f08164
+5 -6
View File
@@ -447,18 +447,17 @@ def calc_metrics(trades, label=""):
dd = (t["equity"] - peak) / peak
max_dd = min(max_dd, dd)
# Sharpe: annualize based on actual trading frequency, not assumed weekly
first_date = trades[0]["date"]
last_date = trades[-1]["date"]
years = (last_date - first_date).days / 365.25
# Sharpe: annualize based on actual trading frequency
trade_rets = [t["pnl_pct"] / 100 for t in trades]
if len(trade_rets) > 2 and np.std(trade_rets) > 0:
years = (last_date - first_date).days / 365.25
trades_per_year = len(trade_rets) / years if years > 0 else 52
sharpe = np.mean(trade_rets) / np.std(trade_rets) * np.sqrt(trades_per_year)
else:
sharpe = 0
first_date = trades[0]["date"]
last_date = trades[-1]["date"]
years = (last_date - first_date).days / 365.25
annual_ret = ((final_eq / INITIAL_EQUITY) ** (1 / years) - 1) * 100 if years > 0 else 0
return {