yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

How to stop yfinance from giving me back a row with empty NaN values?

Open AndresJaramillo95 opened this issue 4 years ago • 7 comments

Greetings,

is there a reason why sometimes when I use a bulk download, such as data = pdr.get_data_yahoo(tickers, start= weeks52, end=today)

image

I get a row of data with NaN values? I understand that yfinance only updates closing data. I have never had to deal with NaN row from yfinance so im a little bewildered.

Usually yfinance only returns back the most recent market data that is available. This hasn't caused me any trouble in the passed except for today... I've also noticed that this only appears to be an issue when I download data for multiple tickers. The ticker variable above is a list of 500 stocks.

How can this be solved from my end? I know this is not too big of an issue as I can just ignore the row with NaN values. But I'm automating a program that assumes the dataframe index position for most recent data will always be the same.

Anyone else experiencing something similar?

AndresJaramillo95 avatar Aug 07 '20 19:08 AndresJaramillo95

In my case for some tickers it also returns this line, but even with 2-3 rows of data.

Leggerla avatar Nov 03 '20 19:11 Leggerla

This is a BUG. Nobody to fix it. Even if there is PR, it is never merged. 👎

GF-Huang avatar Feb 23 '21 02:02 GF-Huang

has this issue been solved?

olearyw avatar Apr 27 '21 02:04 olearyw

This seems to happen when I request options data too. It is intermittent.

pchaganti avatar Apr 27 '21 12:04 pchaganti

It seems like this library is not being actively maintained.

Here are some options:

  • Identify the problem, create a PR, solve the problem, then contact the owner of this repo to request a merge.
  • Work around the bug (not optimal I know but what else can you do?)
  • Use a different Python library/API to achieve your goal.

AndresJaramillo95 avatar Apr 28 '21 04:04 AndresJaramillo95

When using history function with start/end parameter , the last date return NaN , the trick is to have "endDay+1" and ignore last row... its not optimized because it require to pre-process date but does perfectly fine. If you use your "end" date that return Nan value , as a "start" in another case , it will have a value.

AtonLerin avatar Mar 08 '22 13:03 AtonLerin

My timezone fixes should resolve this issue, which I will personally merge in soon once it's been sufficiently tested. https://github.com/ranaroussi/yfinance/pull/1048

ValueRaider avatar Sep 20 '22 22:09 ValueRaider