ranaroussi / yfinance

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

End day data is missing in the resulting DataFrame #1906

Open ZmicierGT opened 7 months ago

ZmicierGT commented 7 months ago

Describe bug

Hi.

I see that the last day data is missing in the resulting DataFrame. For example, if I request data starting from 2020-08-28 till 2020-08-31, there will be no 2020-08-31 in the resulting DataFrame but actually this data exists on Yahoo.

Simple code that reproduces your problem

import yfinance as yf
yf.download('SPY', start="2020-08-28", end="2020-08-31")
[*********************100%%**********************]  1 of 1 completed
                  Open        High         Low       Close   Adj Close    Volume
Date                                                                            
2020-08-28  349.440002  350.720001  348.149994  350.579987  331.563324  48588900

yf.download('SPY', start="2020-08-28", end="2020-09-01")
[*********************100%%**********************]  1 of 1 completed
                  Open        High         Low       Close   Adj Close    Volume
Date                                                                            
2020-08-28  349.440002  350.720001  348.149994  350.579987  331.563385  48588900
2020-08-31  350.350006  351.299988  349.059998  349.309998  330.362244  66099200 

Debug log

yf.download('SPY', start="2020-08-28", end="2020-08-31")
DEBUG    Entering download()
DEBUG     Disabling multithreading because DEBUG logging enabled
DEBUG     Entering history()
DEBUG      Entering history()
DEBUG       SPY: Yahoo GET parameters: {'period1': '2020-08-28 00:00:00-04:00', 'period2': '2020-08-31 00:00:00-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG       Entering get()
DEBUG        url=https://query2.finance.yahoo.com/v8/finance/chart/SPY
DEBUG        params=frozendict.frozendict({'period1': 1598587200, 'period2': 1598846400, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'})
DEBUG        Entering _get_cookie_and_crumb()
DEBUG         cookie_mode = 'basic'
DEBUG         Entering _get_cookie_and_crumb_basic()
DEBUG          loaded persistent cookie
DEBUG          reusing cookie
DEBUG          crumb = 'Me.50YI13rf'
DEBUG         Exiting _get_cookie_and_crumb_basic()
DEBUG        Exiting _get_cookie_and_crumb()
DEBUG        response code=200
DEBUG       Exiting get()
DEBUG       SPY: yfinance received OHLC data: 2020-08-28 13:30:00 -> 2020-08-28 13:30:00
DEBUG       SPY: OHLC after cleaning: 2020-08-28 09:30:00-04:00 -> 2020-08-28 09:30:00-04:00
DEBUG       SPY: OHLC after combining events: 2020-08-28 00:00:00-04:00 -> 2020-08-28 00:00:00-04:00
DEBUG       SPY: yfinance returning OHLC: 2020-08-28 00:00:00-04:00 -> 2020-08-28 00:00:00-04:00
DEBUG      Exiting history()
DEBUG     Exiting history()
DEBUG    Exiting download()
yf.download('SPY', start="2020-08-28", end="2020-09-01")
DEBUG    Entering download()
DEBUG     Disabling multithreading because DEBUG logging enabled
DEBUG     Entering history()
DEBUG      Entering history()
DEBUG       SPY: Yahoo GET parameters: {'period1': '2020-08-28 00:00:00-04:00', 'period2': '2020-09-01 00:00:00-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG       Entering get()
DEBUG        url=https://query2.finance.yahoo.com/v8/finance/chart/SPY
DEBUG        params=frozendict.frozendict({'period1': 1598587200, 'period2': 1598932800, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'})
DEBUG        Entering _get_cookie_and_crumb()
DEBUG         cookie_mode = 'basic'
DEBUG         Entering _get_cookie_and_crumb_basic()
DEBUG          reusing cookie
DEBUG          reusing crumb
DEBUG         Exiting _get_cookie_and_crumb_basic()
DEBUG        Exiting _get_cookie_and_crumb()
DEBUG        response code=200
DEBUG       Exiting get()
DEBUG       SPY: yfinance received OHLC data: 2020-08-28 13:30:00 -> 2020-08-31 13:30:00
DEBUG       SPY: OHLC after cleaning: 2020-08-28 09:30:00-04:00 -> 2020-08-31 09:30:00-04:00
DEBUG       SPY: OHLC after combining events: 2020-08-28 00:00:00-04:00 -> 2020-08-31 00:00:00-04:00
DEBUG       SPY: yfinance returning OHLC: 2020-08-28 00:00:00-04:00 -> 2020-08-31 00:00:00-04:00
DEBUG      Exiting history()
DEBUG     Exiting history()
DEBUG    Exiting download()

Bad data proof

No response

yfinance version

0.2.37

Python version

3.9.10

Operating system

macOS 14.1.2

ValueRaider commented 7 months ago

Read the debug log. yfinance forwarded your request to Yahoo