yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

Wrong time stamp for 1h time frame for versions after 0.2.44

Open indra5534 opened this issue 1 year ago • 10 comments

Describe bug

Whenever I am trying to download stock data for 1h time frame it shows wrong time frame. This problem was not present in 0.2.44 and previous versions. It was easier to use when it used to give output in local time frames

Simple code that reproduces your problem

import yfinance as yf

print("\nyfinance version:", yf.version) ticker = 'AAPL'
interval = '1h'
data = yf.download(ticker, period='1mo', interval=interval)

print("\nLast 7 Close Prices:") print(data['Close'].tail(7))

Debug log

I downloaded stock data of AAPL in 0.2.44 version this is the print out.
Last 7 Close Prices: Datetime 2024-11-25 11:30:00-05:00 230.206802 2024-11-25 12:30:00-05:00 230.414993 2024-11-25 13:30:00-05:00 230.684998 2024-11-25 14:30:00-05:00 230.520004 2024-11-25 15:30:00-05:00 232.880005 2024-11-26 09:30:00-05:00 234.360001 2024-11-26 10:30:00-05:00 235.139999

But when I downloaded stock data of AAPL in 0.2.50 version this is the print out.
Ticker AAPL Datetime
2024-11-25 16:30:00+00:00 230.206802 2024-11-25 17:30:00+00:00 230.414993 2024-11-25 18:30:00+00:00 230.684998 2024-11-25 19:30:00+00:00 230.520004 2024-11-25 20:30:00+00:00 232.880005 2024-11-26 14:30:00+00:00 234.360001 2024-11-26 15:30:00+00:00 235.313507

Bad data proof

1 2

yfinance version

0.2.50

Python version

3.10

Operating system

No response

indra5534 avatar Nov 26 '24 16:11 indra5534

Look at the time-zone part of the times. First line from version 0.2.44 says 2024-11-25 11:30:00-05:00 230.206802, whereas in version 0.2.50 it is 2024-11-25 16:30:00+00:00 230.206802. That looks like 5 hours later, which is what the time-zone is telling you: -05:00 = UTC-5 = US Eastern Standard Time = New York. IOW: 0.2.44 reports times in the zone of the stock exchange, whilst 0.2.50 is showing UTC. I would hazard a guess that the price difference in the last row "235.139999" vs "235.313507" could be due to corrections still in flight for the latest market session??

paulmcq avatar Nov 26 '24 17:11 paulmcq

Recent versions standardised the handling of timezones: https://github.com/ranaroussi/yfinance/blob/0c89fcd8f74764599c8a524f938f3f38ce757fd9/tests/test_prices.py#L47-L50

download is intended for multiple tickers potentially across multiple timezones. What is local then?

ValueRaider avatar Nov 26 '24 19:11 ValueRaider

@indra5534 don't need to repost the screenshots.

One option is localizing to the most common timezone.

ValueRaider avatar Nov 27 '24 09:11 ValueRaider

For 1h time frame api gives generalized time zone. For other time frames like 15m, 30m it gives localized time zone. I was trying to get data from user input time frame. But due to this I am unable to do so. For 1h it needs conversations to to localized time zone, for other time frame it doesn't need so. Please help. Version 0.2.44 used to give data for all time frames in the same time zone(localized).

indra5534 avatar Nov 27 '24 10:11 indra5534

Here's the problem https://github.com/ranaroussi/yfinance/blob/0c89fcd8f74764599c8a524f938f3f38ce757fd9/yfinance/multi.py#L109

ValueRaider avatar Nov 27 '24 21:11 ValueRaider

That isn't obviously a yfinance error. Comprehend what Pandas is saying.

ValueRaider avatar Nov 28 '24 09:11 ValueRaider

Ok fixed. thanks. If possible please remove default time zones for future versions. like 1h time frame has UTC time zone. and all other time frame dont have any default time zones. Its hard for me to adjust my code for every versions released.

indra5534 avatar Nov 29 '24 01:11 indra5534

This isn't fixed. My last message referred to a different error that you deleted.

ValueRaider avatar Nov 29 '24 09:11 ValueRaider

Sorry I meant to say, I removed time zones from that code that fixed it, it is wrong to ask you guys to Debug my code.

If you can standardize time zone for future updates that would be great. We don't have to localize or remove time zones from time stamps for various timeframes that makes accessing mutiple time frame at onec easier. That's it.

indra5534 avatar Nov 29 '24 11:11 indra5534

Revisiting this.

> yf.download('AAPL', period='1mo', interval='1h)
...
2024-11-25 16:30:00+00:00 230.206802
2024-11-25 17:30:00+00:00 230.414993

Problem is timezone is UTC when it should be local when all symbols on same exchange (USA -4h).

ValueRaider avatar Feb 16 '25 20:02 ValueRaider