ranaroussi / yfinance

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

History does have NaN values #134

Closed slapslash closed 3 years ago

slapslash commented 4 years ago

when downloading the history of a ticker it does have rows with nan values in it. as there is a quotes.dropna(inplace=True) in base.py I do assume, this is not intended. I narrowed it to at least being dates, where splits or dividends happened. By the way, those rows do not always show up in yahoo's data :/

stock = yf.Ticker('RAW.DE')
history = stock.history(period='max', auto_adjust=True, back_adjust=True, rounding=True, actions=False)
             Open   High    Low  Close   Volume
Date                                           
2012-06-27    NaN    NaN    NaN    NaN      NaN
2013-07-03    NaN    NaN    NaN    NaN      NaN
2014-06-11    NaN    NaN    NaN    NaN      NaN
2018-04-03  29.36  29.36  28.62  28.90   9553.0
2018-04-04  28.74  28.78  28.01  28.27  11568.0
...           ...    ...    ...    ...      ...
2019-11-14  22.75  22.75  22.09  22.09   6361.0
2019-11-15  21.76  21.80  21.65  21.80   1670.0
2019-11-18  21.80  21.80  21.25  21.43   3765.0
2019-11-19  21.80  21.85  21.68  21.85    107.0
2019-11-20  21.58  21.68  21.58  21.68    100.0
silvavn commented 3 years ago

This is no longer the case.

abishekh commented 3 years ago

Can confirm this is still happening.

silvavn commented 3 years ago

@abishekh Please provide reproduction code

masayang commented 2 years ago

stock = yf.Ticker('SPY') history = stock.history(period='max', auto_adjust=True, back_adjust=True, rounding=True, actions=False, interval="1wk") print(history.to_string())

2022-03-14 417.78 441.57 412.72 444.52 5.559255e+08 2022-03-18 NaN NaN NaN NaN NaN 2022-03-21 442.43 451.03 438.78 452.69 3.842645e+08 2022-03-28 450.12 460.08 447.21 452.92 4.455269e+08 2022-04-04 451.18 455.86 441.56 447.57 3.980834e+08 2022-04-11 442.20 443.83 434.77 437.79 3.460740e+08 2022-04-18 434.93 448.07 423.61 426.04 4.269370e+08 2022-04-25 421.85 427.79 409.44 412.00 5.966142e+08 2022-05-02 410.30 427.81 403.28 411.34 7.272885e+08 2022-05-09 403.36 404.66 383.49 401.72 6.597095e+08 2022-05-16 398.26 406.81 378.90 389.63 5.092695e+08 2022-05-23 391.14 413.59 385.30 415.26 4.262736e+08 2022-05-30 411.77 415.64 405.18 410.54 3.340067e+08 2022-06-06 413.00 414.82 388.07 389.80 4.003150e+08 2022-06-13 378.22 382.25 360.61 365.86 6.452707e+08 2022-06-17 NaN NaN NaN NaN NaN 2022-06-20 371.89 390.09 370.18 390.08 3.442137e+08 2022-06-27 391.05 393.16 372.56 381.24 4.055825e+08 2022-07-04 375.88 390.64 372.90 388.67 2.887879e+08 2022-07-11 385.85 386.87 371.04 385.13 3.735759e+08 2022-07-18 388.38 400.18 380.66 395.09 3.506546e+08 2022-07-25 395.75 413.03 389.95 411.99 3.498078e+08 2022-08-01 409.15 415.68 406.82 413.47 3.036657e+08 2022-08-08 415.25 427.21 410.22 427.10 2.886179e+08 2022-08-15 424.77 431.73 424.71 429.70 1.133373e+08 2022-08-17 425.91 429.50 424.54 426.65 6.336088e+07

ValueRaider commented 2 years ago

I noticed that too, happens with weekly data when dividends during week. Good news - this PR fixes it https://github.com/ranaroussi/yfinance/pull/1049. Bad news - not been merged in yet.