fix: only count matured setups in the live track record
Deploy / lint (push) Successful in 8s
Deploy / test (push) Successful in 1m1s
Deploy / deploy (push) Successful in 36s

The outcome stats were dominated by quick stop-outs: near stops resolve as losses
within days while far targets take weeks, so a young sample (mostly pending,
0 expired) skewed sharply negative (e.g. 13.8% hit / -0.46R vs the backtest's
35.8% / +0.18R) — a maturation artifact, not a real result.

get_performance_stats now counts only setups whose full ~30-day window has
elapsed (_MATURITY_DAYS), so winners had as long as losers (unbiased, and
comparable to the backtest). A new `maturing` count reports the younger setups
held back. The Track Record UI relabels "Evaluated" -> "Matured", shows the
maturing count, and explains the window in the empty state + methodology note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 13:41:48 +02:00
parent 8bcbbfcfd0
commit 7e9a6cd7ec
4 changed files with 62 additions and 10 deletions
+23
View File
@@ -317,3 +317,26 @@ class TestGetPerformanceStats:
stats = await get_performance_stats(db_session)
assert stats["overall"]["total"] == 1
async def test_immature_setups_excluded_and_counted_as_maturing(self, db_session: AsyncSession):
ticker = await _make_ticker(db_session)
now = datetime.now(timezone.utc)
# Matured (detected well beyond the window) → counted in the stats.
db_session.add(_make_setup(
ticker, rr=2.0, actual_outcome=OUTCOME_TARGET_HIT, detected=now - timedelta(days=90),
))
# Young but already resolved → excluded from stats, reported as maturing.
db_session.add(_make_setup(
ticker, rr=2.0, actual_outcome=OUTCOME_STOP_HIT, detected=now,
))
# Young and still pending → also maturing.
db_session.add(_make_setup(ticker, detected=now))
await db_session.flush()
stats = await get_performance_stats(db_session)
assert stats["overall"]["total"] == 1 # only the matured win
assert stats["overall"]["wins"] == 1
assert stats["overall"]["hit_rate"] == 100.0
assert stats["pending"] == 1
assert stats["maturing"] == 2 # young resolved + pending