79154667

Date: 2024-11-04 08:21:51
Score: 1
Natty:
Report link

There is an issue with data from yfinance (it has multicolumn)

Price                       Adj Close       Close  ...        Open     Volume
Ticker                            SPY         SPY  ...         SPY        SPY
Date                                               ...                       
2022-01-03 00:00:00+00:00  458.720367  477.709991  ...  476.299988   72668200
2022-01-04 00:00:00+00:00  458.566650  477.549988  ...  479.220001   71178700

There is an updated function

# Fetch historical SPY data
def fetch_data(symbol, start_date, end_date):
    data = yf.download(symbol, start=start_date, end=end_date)
    if isinstance(data.columns, pd.MultiIndex) and data.columns.nlevels > 1:
        data.columns = data.columns.droplevel(1)
    return data

result of your code

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Evgenii Lazarev