From 18ca670de718cd89b7af6f6116f21273d0f78e25 Mon Sep 17 00:00:00 2001 From: 0x7d0 Date: Fri, 10 Oct 2025 14:26:16 +0200 Subject: [PATCH] fix: Handle yfinance data structure and auto_adjust warning in portfolio metrics --- tradingagents/portfolio/metrics.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tradingagents/portfolio/metrics.py b/tradingagents/portfolio/metrics.py index 174ae37a..304defa6 100644 --- a/tradingagents/portfolio/metrics.py +++ b/tradingagents/portfolio/metrics.py @@ -30,15 +30,29 @@ def fetch_historical_prices( tickers, start=start.strftime('%Y-%m-%d'), end=end.strftime('%Y-%m-%d'), - progress=False + progress=False, + auto_adjust=False # Explicitly set to avoid warning ) # Handle single ticker vs multiple tickers if len(tickers) == 1: - prices = data['Adj Close'].to_frame() - prices.columns = tickers + if 'Adj Close' in data.columns: + prices = data['Adj Close'].to_frame() + prices.columns = tickers + else: + # Fallback to Close if Adj Close not available + prices = data['Close'].to_frame() + prices.columns = tickers else: - prices = data['Adj Close'] + if 'Adj Close' in data.columns: + prices = data['Adj Close'] + else: + # For newer yfinance versions, the structure might be different + try: + prices = data['Adj Close'] + except KeyError: + # Fallback: use Close prices + prices = data['Close'] return prices