From 5e5bfaedc615c96becc78e10b7239f6a92ac35be Mon Sep 17 00:00:00 2001 From: hmo Date: Tue, 28 Jul 2026 15:58:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Kelly=E4=BB=93=E4=BD=8D+ATR=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E6=AD=A2=E6=8D=9F+=E7=BB=9F=E8=AE=A1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81(=E8=83=9C=E7=8E=87/=E5=A4=8F=E6=99=AE/=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=9B=9E=E6=92=A4)+=E7=A7=91=E5=AD=A6=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=8C=87=E6=A0=87=E6=95=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mofin_db.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mofin_db.py b/mofin_db.py index 20f802e8..42c7cb6a 100644 --- a/mofin_db.py +++ b/mofin_db.py @@ -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