-
Notifications
You must be signed in to change notification settings - Fork 173
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
Not properly accounting for market holydays (data shifts) #65
Comments
I'm still working on this issue, and unfortunately uncovered more timestamp troubles. Here's an example, using the same NQZ2024 contract. The timestamps returned by TV seem to not account for the specific day the day savings time start and end. Below is an extract from the returned data as a Timestamp and as a number. The data was downloaded from the Europe/Paris timezone (GMT+1 and GMT+2 when on day savings time).
When changing the time zone from which you download data (like when using a VPN), the timestamps returned change as well, and they follow the local timezone from which you're downloading. However, the issue with the wrong day of DST end persists. The problem seems to lie in the TV data itself and will require an ugly patch to fix, unless I am missing something, like perhaps a way to request timestamps explicitly in UTC. I tried changing the wss message like this:
but the returned timestamps were identical. I'm out of ideas. |
This looks like it's an issue for specific symbols. E.g. testing it shape: (5_059, 8)
The 9th was a trading holiday due to Jimmy Carter's death. But shape: (5_000, 8)
You can see here the date is off multiple times. The 8th is supposed to be the 10th. It looks like multiple bugs at once. What's happening here is TV is passing data in blindly from other sources. In this example FRED. FRED for some sort of reason missed the holiday and the data for the 10th says it's the 9th. (source) If I look at the TV webpage the the last date is the 9th, but if I have multiple data sources open into one plot the same data that said the 9th now says the 10th, which is correct. Somehow TV knows to fix the FRED data when multiple data sources are up on a single plot. Then there is the bug in tvdatafeed that is listing the days one day off. The 5th should be Monday the 6th, and so on. One theory I have is |
It looks like market holydays are not taken into account. For example, Thanksgiving 2024 was on Nov.28th, 2024. There was no market.
Downloading the daily NQ future from TV, I get a candle on 2024-11-28 and I'm missing the candle on 2024-11-29 which was the real open market day as follows:
The data for 2024-11-28 should actually be the candle of 2024-11-29 (OHLCV values are correct for the 2024-11-29 date).
Further, looking at the TradingView Chart, i can confirm that the Candle for 2024-11-28 is missing, and the data is present only for 2024-11-27 and 2024-11-29.
My guess (to be verified) is that the same issue occurs on all market holidays and the data is shifted.
EDIT: Verifying the data that comes from TV, I see that the json value contains:
This means that, assuming the TV data is correct, some offset/timezone mangling is necessary to properly align the timestamp to a correct date.
A proposed fix:
Digging further, my guess is that:
With these assumpions, he below proposed fix produces the correct timestamps:
the two functions
is_business_day
andnext_business_day
can be implemented using the pypi "holidays" package or thepandas_market_calendars
package.your-local-timezone
is the timezone of your TV account, or the default timezone if not using an account.With this proposed fix, here's the corrected dates from the NQZ2024 contact:
The text was updated successfully, but these errors were encountered: