fix: unhashable dict dans context narrative + normalisation tickers EUR/USD pour VaR

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-20 09:08:54 +02:00
parent e2d5bebef4
commit 1aadf98fe4
2 changed files with 10 additions and 3 deletions

View File

@@ -905,7 +905,7 @@ NOUVELLES IDÉES GÉNÉRÉES CE CYCLE ({len(new_pattern_names)} patterns ajouté
{_json.dumps(new_pattern_names, ensure_ascii=False)}
TOP 5 PATTERNS LES MIEUX SCORÉS MAINTENANT:
{_json.dumps([{{"name": s.get("geo_trigger","?"), "score": s.get("score"), "catalyst": s.get("key_catalyst","")[:80]}} for s in top_scored], ensure_ascii=False)}
{_json.dumps([{"name": s.get("geo_trigger","?"), "score": s.get("score"), "catalyst": s.get("key_catalyst","")[:80]} for s in top_scored], ensure_ascii=False)}
Ta tâche: Explique le RAISONNEMENT de ce cycle.
Pour chaque nouvelle idée générée:

View File

@@ -53,17 +53,24 @@ def _bs_delta(S: float, K: float, T_days: float, sigma: float, opt_type: str, di
def _fetch_returns(tickers: List[str], lookback: int) -> pd.DataFrame:
"""Download historical daily returns via yfinance. Returns {} on failure."""
from .database import _normalize_ticker
valid = [t for t in tickers if ":" not in t]
if not valid:
return pd.DataFrame()
# Map raw → yfinance ticker; keep reverse map for column rename
yf_map = {t: _normalize_ticker(t) for t in valid}
yf_tickers = list(yf_map.values())
reverse = {v: k for k, v in yf_map.items()}
try:
import yfinance as yf
end = datetime.now()
start = end - timedelta(days=lookback + 60)
raw = yf.download(valid, start=start, end=end, progress=False, auto_adjust=True)
raw = yf.download(yf_tickers, start=start, end=end, progress=False, auto_adjust=True)
if raw.empty:
return pd.DataFrame()
close = raw["Close"] if len(valid) > 1 else raw[["Close"]].rename(columns={"Close": valid[0]})
close = raw["Close"] if len(yf_tickers) > 1 else raw[["Close"]].rename(columns={"Close": yf_tickers[0]})
# Rename yfinance tickers back to original
close = close.rename(columns=reverse)
return close.pct_change().dropna().tail(lookback)
except Exception:
return pd.DataFrame()