feat: Kelly仓位+ATR动态止损+统计验证(胜率/夏普/最大回撤)+科学技术指标整合

This commit is contained in:
hmo
2026-07-28 15:58:44 +08:00
parent aaf2ce118d
commit 5e5bfaedc6
+17
View File
@@ -1659,6 +1659,23 @@ def check_strategy_outcomes(conn):
if updated:
conn.commit()
# ── 统计验证(2026-07-28 老爸:胜率/夏普/最大回撤)──
try:
closed = conn.execute("""
SELECT theoretical_pnl FROM strategy_tracking
WHERE status IN ("hit_tp", "hit_sl", "manual_close") AND theoretical_pnl IS NOT NULL
""").fetchall()
if closed:
wins = [p[0] for p in closed if p[0] > 0]
losses = [abs(p[0]) for p in closed if p[0] < 0]
win_rate = len(wins) / len(closed) if closed else 0.55
avg_win = sum(wins) / len(wins) if wins else 0
avg_loss = sum(losses) / len(losses) if losses else 0
sharpe = (avg_win * win_rate - avg_loss * (1 - win_rate)) / (avg_loss if avg_loss > 0 else 1) if avg_loss > 0 else 0
max_dd = max([abs(p[0]) for p in closed if p[0] < 0], default=0)
print(f" [STATS] 胜率{win_rate:.0%} 夏普{sharpe:.2f} 最大回撤{max_dd:.1f}%", flush=True)
except Exception as _se:
print(f" [STATS] 统计失败: {_se}", flush=True)
return updated