fix: populate early-warning/combined on the latest snapshot + recent history
The early-warning score showed n/a because it required an exact date match between the live benchmark (Alpaca, may have today's bar) and the stored universe breadth (DB, often a day behind), which blanked the newest snapshot — the one the UI displays. - Look up the divergence as-of the snapshot date (newest value within a 7-day lag) instead of requiring an exact match. - Backfill early_warning + combined onto recent existing snapshots (the index history predates this signal) so the 7/30-day trends populate on the first run rather than only filling in over the coming weeks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,15 @@ def test_attach_early_warning_none_falls_back_to_index():
|
||||
assert result["combined"]["score"] == 80.0 # no early warning -> just the index
|
||||
|
||||
|
||||
def test_divergence_asof_tolerates_small_lag():
|
||||
from app.services.regime_monitor_service import _divergence_asof
|
||||
items = [(date(2026, 6, 1), 55.0), (date(2026, 6, 3), 60.0)]
|
||||
assert _divergence_asof(items, date(2026, 6, 3)) == 60.0 # exact date
|
||||
assert _divergence_asof(items, date(2026, 6, 4)) == 60.0 # 1-day lag -> newest
|
||||
assert _divergence_asof(items, date(2026, 6, 20)) is None # too stale
|
||||
assert _divergence_asof([], date(2026, 6, 3)) is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Price sub-scores
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user