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

Inconsistet data between yf.download and yf.ticker.history #1999

Open juggernaut451 opened 4 months ago

juggernaut451 commented 4 months ago

Describe bug

there is inconsistent data between yf.dowlload function and yf.ticker.history

Simple code that reproduces your problem

import yfinance as yf

Define the stock symbol and the date range

stock_symbol = 'CANBK.NS' # Example: Apple Inc. start_date = '2010-11-01' end_date = '2010-11-10'

Download historical data for the specified stock symbol and date range

df = yf.download(stock_symbol, start=start_date, end=end_date)

Get data using ticker

ticker = yf.Ticker(stock_symbol) hist = ticker.history(start=start_date, end=end_date)

print(df) print(hist)

Debug log

DEBUG Entering download() DEBUG Disabling multithreading because DEBUG logging enabled DEBUG Entering history() DEBUG Entering history() DEBUG CANBK.NS: Yahoo GET parameters: {'period1': '2010-11-01 00:00:00+05:30', 'period2': '2010-11-10 00:00:00+05:30', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/CANBK.NS DEBUG params=frozendict.frozendict({'period1': 1288549800, 'period2': 1289327400, '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 = '1y62GCxaO6e' DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting get() DEBUG CANBK.NS: yfinance received OHLC data: 2010-11-01 03:45:00 -> 2010-11-09 03:45:00 DEBUG CANBK.NS: OHLC after cleaning: 2010-11-01 09:15:00+05:30 -> 2010-11-09 09:15:00+05:30 DEBUG CANBK.NS: OHLC after combining events: 2010-11-01 00:00:00+05:30 -> 2010-11-09 00:00:00+05:30 DEBUG CANBK.NS: yfinance returning OHLC: 2010-11-01 00:00:00+05:30 -> 2010-11-09 00:00:00+05:30 DEBUG Exiting history() DEBUG Exiting history() DEBUG Exiting download() DEBUG Entering history() DEBUG Entering history() DEBUG CANBK.NS: Yahoo GET parameters: {'period1': '2010-11-01 00:00:00+05:30', 'period2': '2010-11-10 00:00:00+05:30', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG CANBK.NS: yfinance received OHLC data: 2010-11-01 03:45:00 -> 2010-11-09 03:45:00 DEBUG CANBK.NS: OHLC after cleaning: 2010-11-01 09:15:00+05:30 -> 2010-11-09 09:15:00+05:30 DEBUG CANBK.NS: OHLC after combining events: 2010-11-01 00:00:00+05:30 -> 2010-11-09 00:00:00+05:30 DEBUG CANBK.NS: yfinance returning OHLC: 2010-11-01 00:00:00+05:30 -> 2010-11-09 00:00:00+05:30 DEBUG Exiting history() DEBUG Exiting history()

Bad data proof

              Open        High         Low       Close   Adj Close    Volume

Date
2010-11-01 141.229477 145.120087 141.229477 144.351700 111.878990 5514824 2010-11-02 143.943176 148.582748 143.301224 144.147430 111.720680 6253688 2010-11-03 144.594864 147.123764 144.468414 145.081192 112.444412 6602702 2010-11-04 145.684235 149.409500 145.479980 148.018600 114.721008 5554319 2010-11-08 149.205246 159.126328 147.337753 157.628433 122.169067 10537361 2010-11-09 158.153671 164.223038 154.846634 162.695969 126.096634 10811944

                       Open        High         Low       Close    Volume  Dividends  Stock Splits

Date
2010-11-01 00:00:00+05:30 109.459129 112.474524 109.459129 111.878990 5514824 0.0 0.0 2010-11-02 00:00:00+05:30 111.562374 115.158249 111.064832 111.720680 6253688 0.0 0.0 2010-11-03 00:00:00+05:30 112.067486 114.027497 111.969482 112.444412 6602702 0.0 0.0 2010-11-04 00:00:00+05:30 112.911771 115.799017 112.753465 114.721008 5554319 0.0 0.0 2010-11-08 00:00:00+05:30 115.640722 123.330002 114.193331 122.169067 10537361 0.0 0.0 2010-11-09 00:00:00+05:30 122.576151 127.280181 120.013049 126.096634 10811944 0.0 0.0

yfinance version

0.2.41

Python version

No response

Operating system

No response

ValueRaider commented 4 months ago

Duplicate

ValueRaider commented 3 days ago

My bad, this was not a duplicate.