yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

yfinance does not return the latest (current day during market session) day's data using 'max' parameter.

Open ceeyee opened this issue 9 months ago • 9 comments

Describe bug

During US market hours, the historical data yfinance returns doesn't contain the current day's data using 'max' parameter. The latest data row is only the previous day, while it should be the current day's latest available data.

This problem only happens with the 'max' parameter. "5y" "1y" work without such issue.

Please investigate and ideally fix it. Thanks.

Simple code that reproduces your problem

data = yf.download(tickers=TickersList, period='max', group_by='ticker', auto_adjust=True, threads=False, proxy=None)

Debug log from yf.enable_debug_mode()

.

Bad data proof

No response

yfinance version

0.2.54

Python version

3.12.4

Operating system

Windows 10

ceeyee avatar Mar 10 '25 15:03 ceeyee

Provide working code. I can't reproduce bug.

ValueRaider avatar Mar 10 '25 18:03 ValueRaider

I am getting randomly changing close value output from yf.download.

>>>import numpy as np
>>>import pandas as pd
>>>import yfinance as yf
>>>import datetime as dt

>>> yf.download('NVDA',start='2025-02-01',ignore_tz=False)
[*********************100%***********************]  1 of 1 completed
Price                           Close        High         Low        Open     Volume
Ticker                           NVDA        NVDA        NVDA        NVDA       NVDA
Date                                                                                
2025-02-03 05:00:00+00:00  116.660004  118.570000  113.010002  114.750000  371235700
2025-02-04 05:00:00+00:00  118.650002  121.199997  116.699997  116.959999  256550000
2025-02-05 05:00:00+00:00  124.830002  125.000000  120.760002  121.760002  262230800
2025-02-06 05:00:00+00:00  128.679993  128.770004  125.209999  127.419998  251483600
2025-02-07 05:00:00+00:00  129.839996  130.369995  125.000000  129.220001  228186300
2025-02-10 05:00:00+00:00  133.570007  135.000000  129.960007  130.089996  216989100
2025-02-11 05:00:00+00:00  132.800003  134.479996  131.020004  132.580002  178902400
2025-02-12 05:00:00+00:00  131.139999  132.240005  129.080002  130.020004  160278600
2025-02-13 05:00:00+00:00  135.289993  136.500000  131.169998  131.559998  197430000
2025-02-14 05:00:00+00:00  138.850006  139.250000  135.500000  136.479996  195479600
2025-02-18 05:00:00+00:00  139.399994  143.440002  137.929993  141.270004  219176600
2025-02-19 05:00:00+00:00  139.229996  141.360001  137.220001  139.509995  167536000
2025-02-20 05:00:00+00:00  140.110001  140.660004  136.789993  140.029999  143903600
2025-02-21 05:00:00+00:00  134.429993  141.460007  134.029999  140.039993  228217600
2025-02-24 05:00:00+00:00  130.279999  138.589996  130.080002  136.559998  251381100
2025-02-25 05:00:00+00:00  126.629997  130.199997  124.440002  129.979996  271428700
2025-02-26 05:00:00+00:00  131.279999  133.729996  128.490005  129.990005  322553800
2025-02-27 05:00:00+00:00  120.150002  135.009995  120.010002  135.000000  443175800
2025-02-28 05:00:00+00:00  124.919998  125.089996  116.400002  118.019997  389091100
2025-03-03 05:00:00+00:00  114.059998  123.699997  112.279999  123.510002  411381400
2025-03-04 05:00:00+00:00  115.989998  119.309998  110.110001  110.650002  398163300
2025-03-05 05:00:00+00:00  117.300003  118.279999  114.510002  117.580002  284337900
2025-03-06 05:00:00+00:00  110.570000  115.349998  110.220001  113.529999  321181900
2025-03-07 05:00:00+00:00  112.690002  113.480003  107.559998  111.250000  341058300
>>> yf.download('NVDA',start='2025-02-01',ignore_tz=False)
[*********************100%***********************]  1 of 1 completed
Price                           Close        High         Low        Open     Volume
Ticker                           NVDA        NVDA        NVDA        NVDA       NVDA
Date                                                                                
2025-02-03 05:00:00+00:00  116.660004  118.570000  113.010002  114.750000  371235700
2025-02-04 05:00:00+00:00  118.650002  121.199997  116.699997  116.959999  256550000
2025-02-05 05:00:00+00:00  124.830002  125.000000  120.760002  121.760002  262230800
2025-02-06 05:00:00+00:00  128.679993  128.770004  125.209999  127.419998  251483600
2025-02-07 05:00:00+00:00  129.839996  130.369995  125.000000  129.220001  228186300
2025-02-10 05:00:00+00:00  133.570007  135.000000  129.960007  130.089996  216989100
2025-02-11 05:00:00+00:00  132.800003  134.479996  131.020004  132.580002  178902400
2025-02-12 05:00:00+00:00  131.139999  132.240005  129.080002  130.020004  160278600
2025-02-13 05:00:00+00:00  135.289993  136.500000  131.169998  131.559998  197430000
2025-02-14 05:00:00+00:00  138.850006  139.250000  135.500000  136.479996  195479600
2025-02-18 05:00:00+00:00  139.399994  143.440002  137.929993  141.270004  219176600
2025-02-19 05:00:00+00:00  139.229996  141.360001  137.220001  139.509995  167536000
2025-02-20 05:00:00+00:00  140.110001  140.660004  136.789993  140.029999  143903600
2025-02-21 05:00:00+00:00  134.429993  141.460007  134.029999  140.039993  228217600
2025-02-24 05:00:00+00:00  130.279999  138.589996  130.080002  136.559998  251381100
2025-02-25 05:00:00+00:00  126.629997  130.199997  124.440002  129.979996  271428700
2025-02-26 05:00:00+00:00  131.279999  133.729996  128.490005  129.990005  322553800
2025-02-27 05:00:00+00:00  120.150002  135.009995  120.010002  135.000000  443175800
2025-02-28 05:00:00+00:00  124.919998  125.089996  116.400002  118.019997  389091100
2025-03-03 05:00:00+00:00  114.059998  123.699997  112.279999  123.510002  411381400
2025-03-04 05:00:00+00:00  115.989998  119.309998  110.110001  110.650002  398163300
2025-03-05 05:00:00+00:00  117.300003  118.279999  114.510002  117.580002  284337900
2025-03-06 05:00:00+00:00  110.570000  115.349998  110.220001  113.529999  321181900
2025-03-07 05:00:00+00:00  112.690002  113.480003  107.559998  111.250000  341058300
2025-03-10 04:00:00+00:00  107.729401  111.849998  105.459999  109.889999  304179061
>>> yf.download('NVDA',start='2025-02-01',ignore_tz=False)
[*********************100%***********************]  1 of 1 completed
Price                           Close        High         Low        Open     Volume
Ticker                           NVDA        NVDA        NVDA        NVDA       NVDA
Date                                                                                
2025-02-03 05:00:00+00:00  116.660004  118.570000  113.010002  114.750000  371235700
2025-02-04 05:00:00+00:00  118.650002  121.199997  116.699997  116.959999  256550000
2025-02-05 05:00:00+00:00  124.830002  125.000000  120.760002  121.760002  262230800
2025-02-06 05:00:00+00:00  128.679993  128.770004  125.209999  127.419998  251483600
2025-02-07 05:00:00+00:00  129.839996  130.369995  125.000000  129.220001  228186300
2025-02-10 05:00:00+00:00  133.570007  135.000000  129.960007  130.089996  216989100
2025-02-11 05:00:00+00:00  132.800003  134.479996  131.020004  132.580002  178902400
2025-02-12 05:00:00+00:00  131.139999  132.240005  129.080002  130.020004  160278600
2025-02-13 05:00:00+00:00  135.289993  136.500000  131.169998  131.559998  197430000
2025-02-14 05:00:00+00:00  138.850006  139.250000  135.500000  136.479996  195479600
2025-02-18 05:00:00+00:00  139.399994  143.440002  137.929993  141.270004  219176600
2025-02-19 05:00:00+00:00  139.229996  141.360001  137.220001  139.509995  167536000
2025-02-20 05:00:00+00:00  140.110001  140.660004  136.789993  140.029999  143903600
2025-02-21 05:00:00+00:00  134.429993  141.460007  134.029999  140.039993  228217600
2025-02-24 05:00:00+00:00  130.279999  138.589996  130.080002  136.559998  251381100
2025-02-25 05:00:00+00:00  126.629997  130.199997  124.440002  129.979996  271428700
2025-02-26 05:00:00+00:00  131.279999  133.729996  128.490005  129.990005  322553800
2025-02-27 05:00:00+00:00  120.150002  135.009995  120.010002  135.000000  443175800
2025-02-28 05:00:00+00:00  124.919998  125.089996  116.400002  118.019997  389091100
2025-03-03 05:00:00+00:00  114.059998  123.699997  112.279999  123.510002  411381400
2025-03-04 05:00:00+00:00  115.989998  119.309998  110.110001  110.650002  398163300
2025-03-05 05:00:00+00:00  117.300003  118.279999  114.510002  117.580002  284337900
2025-03-06 05:00:00+00:00  110.570000  115.349998  110.220001  113.529999  321181900
2025-03-07 05:00:00+00:00  112.690002  113.480003  107.559998  111.250000  341058300
2025-03-10 04:00:00+00:00  107.730003  111.849998  105.459999  109.889999  304320093
>>> 


yfinance version 0.2.54 python version 3.13.2 Mac OS 15.3.1 Apple Silicon M1

sunilshah avatar Mar 10 '25 19:03 sunilshah

For example, right now is 11:20am EST on 03/11/2025. My example program below downloads prices for SPY and QQQ. For QQQ the data is correct, while the last row downloaded from the program for SPY is still 03/10:

2025-03-10,567.5900268554688,569.5399780273438,555.5900268554688,560.5800170898438,98898700.0

As you can see, the issue happens one out of two tickers in this example.

Code:

import yfinance as yf import os

TickersList = ['SPY','QQQ']

data = yf.download(tickers=TickersList, period='max', group_by='ticker', auto_adjust=True, threads=False, proxy=None)

for ticker in TickersList: ticker_data = data[ticker].dropna() ticker_data.to_csv(os.path.join(os.path.dirname(os.path.realpath(file)), ticker + '.csv'), sep=',', encoding='utf-8')

ceeyee avatar Mar 11 '25 15:03 ceeyee

Next time run with yf.enable_debug_mode()

ValueRaider avatar Mar 11 '25 21:03 ValueRaider

import yfinance as yf import os

TickersList = ['SPY','QQQ'] yf.enable_debug_mode() data = yf.download(tickers=TickersList, period='max', group_by='ticker', auto_adjust=True, threads=False, proxy=None)

for ticker in TickersList: ticker_data = data[ticker].dropna() ticker_data.to_csv(os.path.join(os.path.dirname(os.path.realpath(file)), ticker + '.csv'), sep=',', encoding='utf-8')

DEBUG Entering download() DEBUG Entering history() DEBUG Entering history() DEBUG SPY: Yahoo GET parameters: {'period1': '1926-04-07 11:27:09-05:00', 'period2': '2025-03-13 12:27:09-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/SPY DEBUG params={'period1': -1380180771, 'period2': 1741883229, '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 = 'pGbRPL8JRDe' DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get() DEBUG SPY: yfinance received OHLC data: 1993-01-29 14:30:00 -> 2025-03-12 13:30:00 DEBUG SPY: OHLC after cleaning: 1993-01-29 09:30:00-05:00 -> 2025-03-12 09:30:00-04:00 DEBUG SPY: OHLC after combining events: 1993-01-29 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00 DEBUG SPY: yfinance returning OHLC: 1993-01-29 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00 DEBUG Exiting history() DEBUG Exiting history() DEBUG Entering history() DEBUG Entering history() DEBUG QQQ: Yahoo GET parameters: {'period1': '1926-04-07 11:27:10-05:00', 'period2': '2025-03-13 12:27:10-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/QQQ DEBUG params={'period1': -1380180770, 'period2': 1741883230, '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 _make_request() DEBUG Exiting get() DEBUG QQQ: yfinance received OHLC data: 1999-03-10 14:30:00 -> 2025-03-12 13:30:00 DEBUG QQQ: OHLC after cleaning: 1999-03-10 09:30:00-05:00 -> 2025-03-12 09:30:00-04:00 DEBUG QQQ: OHLC after combining events: 1999-03-10 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00 DEBUG QQQ: yfinance returning OHLC: 1999-03-10 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00 DEBUG Exiting history() DEBUG Exiting history() DEBUG Exiting download()

This time both SPY and QQQ are having the issue.

ceeyee avatar Mar 13 '25 16:03 ceeyee

These are the lines I wanted:

DEBUG SPY: yfinance received OHLC data: 1993-01-29 14:30:00 -> 2025-03-12 13:30:00
DEBUG SPY: OHLC after cleaning: 1993-01-29 09:30:00-05:00 -> 2025-03-12 09:30:00-04:00
DEBUG SPY: OHLC after combining events: 1993-01-29 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00
DEBUG SPY: yfinance returning OHLC: 1993-01-29 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00
...
DEBUG QQQ: yfinance received OHLC data: 1999-03-10 14:30:00 -> 2025-03-12 13:30:00
DEBUG QQQ: OHLC after cleaning: 1999-03-10 09:30:00-05:00 -> 2025-03-12 09:30:00-04:00
DEBUG QQQ: OHLC after combining events: 1999-03-10 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00
DEBUG QQQ: yfinance returning OHLC: 1999-03-10 00:00:00-05:00 -> 2025-03-12 00:00:00-04:00

Different start dates, but ends match. download() definitely returned missing end data? Then bug has to be when yfinance combines the data - can you debug?

ValueRaider avatar Mar 13 '25 19:03 ValueRaider

Yes, missing current day's data. However, it only happens with the 'max' parameter. When it's '5y' or '1y' it returns current day as the last row without issue. Remember in the first example above, even when in 'max', one ticker ('QQQ' in this case) returns correct data while the other ('SPY') does not. I don't have the knowledge to debug it. I can just point out the bug.

ceeyee avatar Mar 15 '25 02:03 ceeyee

Hi @ValueRaider ,

I use below code and had enabled enable_debug_mode() once started. The issue seems is also related to issues2179<Failed to get ticker '<Tickername>' reason: Expecting value: line 1 column 1 (char 0)>?

Python version 3.10.16 (main, Dec 11 2024, 10:24:41) [Clang 14.0.6 ] yfinance version 0.2.28

I noticed issues2179 has been closed and fixed in dev branch, could you please help to check ? Thanks!

import yfinance as yf
import os

yf.enable_debug_mode()

TickersList = ['AAPL']

data = yf.download(tickers=TickersList, period='1mo', group_by='ticker', auto_adjust=True, threads=False, proxy=None)

for ticker in TickersList:
    ticker_data = data[ticker].dropna()
    ticker_data.to_csv(os.path.join(os.path.dirname(os.path.realpath(file)), ticker + '.csv'), sep=',', encoding='utf-8')

Image

pangjac avatar Apr 03 '25 01:04 pangjac

yfinance version 0.2.28

@pangjac that's your problem

ValueRaider avatar Apr 03 '25 19:04 ValueRaider