fix(backtest): squeeze yfinance Close series to avoid DataFrame iteration error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dominik Moritz Roth 2026-05-26 17:49:05 +02:00
parent 727ad7cd6d
commit fb86443987

View File

@ -35,8 +35,12 @@ def _fetch_prices(ticker: str, start: datetime, end: datetime) -> dict[str, floa
if data.empty: if data.empty:
return cached return cached
close_series = data["Close"]
if hasattr(close_series, "squeeze"):
close_series = close_series.squeeze()
fetched: dict[str, float] = {} fetched: dict[str, float] = {}
for ts, close_val in data["Close"].items(): for ts, close_val in close_series.items():
date_key = ts.to_pydatetime().replace(tzinfo=None).strftime("%Y-%m-%d") date_key = ts.to_pydatetime().replace(tzinfo=None).strftime("%Y-%m-%d")
fetched[date_key] = float(close_val) fetched[date_key] = float(close_val)