ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.96k stars 2.45k forks source link

Issue - loading cryptos such as BTC-USD result in returning NaN. #1097

Closed josebsalazar closed 2 years ago

bruce1095 commented 2 years ago

Yes. The issue also applies to currencies like 'EURUSD=X' , certain indices like'^STOXX50E', symbols from non-US exchanges, like 'IS0L.DE'

ValueRaider commented 2 years ago

Check you are running latest version, then provide code that reproduces error because I don't see error.

And provide the error message, in case I can't reproduce.

josebsalazar commented 2 years ago

@ValueRaider , it just started working. I did updated and checked. It wasn't working.

(pandas) jxs@jxs-MacBook-Pro-M1 quant % pip show yfinance Name: yfinance Version: 0.1.79

ValueRaider commented 2 years ago

Were you using old version?

josebsalazar commented 2 years ago

Were you using old version?

(pandas) jxs@jxs-MacBook-Pro-M1 quant % pip show yfinance Name: yfinance Version: 0.1.79

No, I wasn't. I updated then restarted.

bruce1095 commented 2 years ago

Still not working, even on latest version.

Here's the code and output:

import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import math

import warnings warnings.filterwarnings("ignore")

fix_yahoo_finance is used to fetch data

import yfinance as yf yf.pdr_override()

symbols = ['^GSPC','^STOXX50E','^RUT'] start = '2018-01-01' end = '2022-12-30'

df = pd.DataFrame() for s in symbols: df[s] = yf.download(s,start,end)['Adj Close']

df.head()

OUTPUT

^GSPC ^STOXX50E ^RUT Date
2018-01-02 00:00:00-05:00 2695.810059 NaN 1550.010010 2018-01-03 00:00:00-05:00 2713.060059 NaN 1552.579956 2018-01-04 00:00:00-05:00 2723.989990 NaN 1555.719971 2018-01-05 00:00:00-05:00 2743.149902 NaN 1560.010010 2018-01-08 00:00:00-05:00 2747.709961 NaN 1561.810059

df.tail()

OUTPUT

^GSPC ^STOXX50E ^RUT Date
2022-10-17 00:00:00-04:00 3677.949951 NaN 1735.750000 2022-10-18 00:00:00-04:00 3719.979980 NaN 1755.959961 2022-10-19 00:00:00-04:00 3695.159912 NaN 1725.760010 2022-10-20 00:00:00-04:00 3665.780029 NaN 1704.390015 2022-10-21 00:00:00-04:00 3752.750000 NaN 1742.239990

ValueRaider commented 2 years ago

Oh I see the issue now. You can workaround immediately by just doing:

df = yf.download(symbols, start, end)['Adj Close']
bruce1095 commented 2 years ago

Oh I see the issue now. You can workaround immediately by just doing:

df = yf.download(symbols, start, end)['Adj Close']

Awesome! Thank you