feat(metrics): real Sharpe ratio from daily PnL curve with minimum-sample gate
CI/CD / build-and-push (push) Successful in 10s
CI/CD / build-and-push (push) Successful in 10s
sharpe_ratio was hardcoded to 0.0 in MetricsTracker and exposed as 'or 0' in /api/summary. With only 1 resolved trade (~40 flat days plus one +299 jump) any computed Sharpe is statistically meaningless, so: - bot/metrics/sharpe.py: annualized Sharpe (sqrt(365)) from daily total_pnl closes, normalized by bankroll; sharpe_with_gate() returns None + status until >=30 days observed AND >=10 resolved trades. - Database.get_daily_pnl_closes(): last metrics_daily snapshot per UTC day, oldest first — the return series input. - MetricsTracker: stores the real (gated) Sharpe in the snapshot, NULL below the gate; log line now includes sharpe. - /api/summary: live Sharpe + sharpe_status/days_observed/min_* fields explaining why it is null; resolved_count now live from COUNT(*). - promotion_ready: requires resolved>=10, days>=30, and non-null win_rate/calibration/sharpe plus existing thresholds — a single lucky resolved trade can no longer promote. - Dashboard Sharpe card shows the insufficient-sample explanation when null instead of a bare em dash. Tests: 13 new in tests/test_sharpe_gate.py (formula, gate, API contract, tracker snapshot); verified failing pre-fix. Suite: 62 passed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
1797b79f7b
commit
43d9577fb2
@@ -44,6 +44,7 @@ class FakeDB:
|
||||
"total_trades": self._total,
|
||||
"open_count": self._open,
|
||||
"closed_count": self._total - self._open,
|
||||
"resolved_count": 0,
|
||||
}
|
||||
|
||||
async def get_recently_closed_inverted(self, hours=24):
|
||||
@@ -52,6 +53,9 @@ class FakeDB:
|
||||
async def get_legacy_incomplete_count(self):
|
||||
return 0
|
||||
|
||||
async def get_daily_pnl_closes(self):
|
||||
return []
|
||||
|
||||
|
||||
def _run(db: FakeDB, monkeypatch) -> tuple[dict, PaperExecutor]:
|
||||
monkeypatch.setattr(api_main, "db", db)
|
||||
|
||||
Reference in New Issue
Block a user