ranaroussi / yfinance

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

No data returned when using start/end parameters (rather than 'period') for history and download methods #1974

Closed JohnJordanDev closed 4 months ago

JohnJordanDev commented 4 months ago

Describe bug

The start and end parameters of download and history methods are no longer returning data, e.g.

start_date = '2024-06-25'
end_date = '2024-06-30'
d = yf.download(tickers="MSFT", start=start_date, end=end_date)
1 Failed download:
- MSFT: No data found for this date range, symbol may be delisted

Passing in the period parameter returns data as expected, e.g.

d = yf.download(tickers="MSFT", period='1wk')

gives:

                                  Open        High         Low       Close   Adj Close    Volume
Date
2024-06-24 00:00:00-04:00  449.799988  452.750000  446.410004  447.670013  447.670013  15913700
2024-06-25 00:00:00-04:00  448.250000  451.420013  446.750000  450.950012  450.950012  16747500
2024-06-26 00:00:00-04:00  449.000000  453.600006  448.190002  452.160004  452.160004  16507000
2024-06-27 00:00:00-04:00  452.179993  456.170013  451.769989  452.850006  452.850006  14806300
2024-06-28 00:00:00-04:00  453.070007  455.380005  446.410004  446.950012  446.950012  28333300

As far as I can tell, the start and end parameters are still valid: https://github.com/ranaroussi/yfinance/blob/main/yfinance/scrapers/history.py.

Simple code that reproduces your problem

import yfinance as yf
d = yf.download(tickers="MSFT", start=start_date, end=end_date)
print("\nData returned with start/end parameters:\n", d, "\n##################")
d = yf.download(tickers="MSFT", period='1wk')
print("\nData returned with 'period' parameters:\n", d, "\n##################")

msft = yf.Ticker("MSFT")

hist = msft.history(period="1wk")
print(f"\nMSFT with '1wk' period is:\n", hist, "\n##################")

hist = msft.history(start=start_date, end=end_date, interval="1d")
print(f"\nMSFT with start/end dates is:\n", hist, "\n##################")
quit()

Debug log

yf.enable_debug_mode() throws an error, since enable_debug_mode is not available on yf.

Bad data proof

[*********************100%***********************]  1 of 1 completed

1 Failed download:
- MSFT: No data found for this date range, symbol may be delisted

Data returned with start/end parameters:
 Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []
##################
[*********************100%***********************]  1 of 1 completed

Data returned with 'period' parameters:
                                  Open        High         Low       Close   Adj Close    Volume
Date
2024-06-24 00:00:00-04:00  449.799988  452.750000  446.410004  447.670013  447.670013  15913700
2024-06-25 00:00:00-04:00  448.250000  451.420013  446.750000  450.950012  450.950012  16747500
2024-06-26 00:00:00-04:00  449.000000  453.600006  448.190002  452.160004  452.160004  16507000
2024-06-27 00:00:00-04:00  452.179993  456.170013  451.769989  452.850006  452.850006  14806300
2024-06-28 00:00:00-04:00  453.070007  455.380005  446.410004  446.950012  446.950012  28333300
##################

MSFT with '1wk' period is:
                                  Open        High         Low       Close    Volume  Dividends  Stock Splits
Date
2024-06-24 00:00:00-04:00  449.799988  452.750000  446.410004  447.670013  15913700        0.0           0.0
2024-06-25 00:00:00-04:00  448.250000  451.420013  446.750000  450.950012  16747500        0.0           0.0
2024-06-26 00:00:00-04:00  449.000000  453.600006  448.190002  452.160004  16507000        0.0           0.0
2024-06-27 00:00:00-04:00  452.179993  456.170013  451.769989  452.850006  14806300        0.0           0.0
2024-06-28 00:00:00-04:00  453.070007  455.380005  446.410004  446.950012  28333300        0.0           0.0
##################
MSFT: No data found for this date range, symbol may be delisted

MSFT with start/end dates is:
 Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []
##################

yfinance version

0.2.4

Python version

3.11.4

Operating system

Windows 10

jonspython commented 4 months ago

I am having the same problem. It was working last night, but not today.

ValueRaider commented 4 months ago

Update yfinance