fix: IV rank fallback to history when live options fetch fails + Entrée date from cycle logs

- iv_engine/options_vol: when get_atm_iv() returns None (yfinance chain unavailable),
  fall back to most recent iv_history row so IV Rank is always computable from
  bootstrapped data; live vs history source tagged as iv_source field
- Dashboard: build mtmMap from tradeMtmData.trades (trade_entry_prices, cycle auto-log)
  keyed by pattern_id; getAddedInfo() falls back to mtmMap so Entrée/Durée columns
  populate automatically after each AI cycle without manual portfolio add
- OptionsLab: show '~' prefix and 'IV estimée' label when IV comes from history fallback;
  fix near-invisible text-slate-700 on 'Sans historique' section header

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-18 11:55:57 +02:00
parent 592918c230
commit 3b4e035819
4 changed files with 43 additions and 9 deletions

View File

@@ -396,10 +396,19 @@ def get_full_iv_snapshot(ticker: str) -> Dict[str, Any]:
skew = get_skew(ticker, target_days=30)
flow = get_options_flow(ticker)
live_iv = iv_current is not None
# Fallback: use most recent historical IV when live options fetch fails
if iv_current is None:
from services.database import get_iv_history
recent = get_iv_history(proxy, days=5)
if recent:
iv_current = recent[0]["iv_current"]
rank_data: Dict[str, Any] = {}
if iv_current:
# Save to history first, then calculate rank
save_iv_snapshot(proxy, today, iv_current, term.get("iv_30d"), term.get("iv_60d"), term.get("iv_90d"))
if live_iv:
# Only persist to history when we have a fresh live IV
save_iv_snapshot(proxy, today, iv_current, term.get("iv_30d"), term.get("iv_60d"), term.get("iv_90d"))
rank_data = get_iv_rank_percentile(proxy, iv_current)
return {
@@ -415,6 +424,7 @@ def get_full_iv_snapshot(ticker: str) -> Dict[str, Any]:
"skew": skew,
"options_flow": flow,
"fetched_at": datetime.utcnow().isoformat(),
"iv_source": "live" if live_iv else ("history" if iv_current else "none"),
}