Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
indra5534 opened this issue Nov 26, 2024 · 9 comments
Open

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

indra5534 opened this issue Nov 26, 2024 · 9 comments

Comments

@indra5534
Copy link

indra5534 commented Nov 26, 2024

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

@paulmcq
Copy link

paulmcq commented Nov 26, 2024

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??

@ValueRaider
Copy link
Collaborator

Recent versions standardised the handling of timezones:

def test_download_multi_small_interval(self):
use_tkrs = ["AAPL", "0Q3.DE", "ATVI"]
df = yf.download(use_tkrs, period="1d", interval="5m")
self.assertEqual(df.index.tz, _dt.timezone.utc)

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

Repository owner deleted a comment from indra5534 Nov 27, 2024
Repository owner deleted a comment from indra5534 Nov 27, 2024
@ValueRaider
Copy link
Collaborator

@indra5534 don't need to repost the screenshots.

One option is localizing to the most common timezone.

@indra5534
Copy link
Author

indra5534 commented Nov 27, 2024

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).

@ValueRaider
Copy link
Collaborator

Here's the problem

if interval[1:] in ['m', 'h']:

@ValueRaider
Copy link
Collaborator

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

@indra5534 indra5534 reopened this Nov 29, 2024
@indra5534
Copy link
Author

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.

@ValueRaider
Copy link
Collaborator

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

@indra5534
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants