investpy icon indicating copy to clipboard operation
investpy copied to clipboard

Inconsistent Economic Calendar Times

Open agftrading opened this issue 3 years ago • 12 comments

There seems to be some "randomisation" going on of the times when retrieving data from the economic calendar.

Example (run on 08/04/2021):

investpy.economic_calendar(time_zone=None,time_filter='time_only',importances=['high'],countries=['UK'])

On the first run returns:

id date time zone currency importance event actual forecast previous
426229 08/04/2021 10:30 united kingdom GBP high Construction PMI (Mar) 61.7 54.6 53.3
427371 08/04/2021 13:30 euro zone EUR high ECB Publishes Account of Monetary Policy Meeting None None None
427144 08/04/2021 14:30 united states USD high Initial Jobless Claims None 680K 719K
427152 08/04/2021 18:00 united states USD high Fed Chair Powell Speaks None None None

If I run it again it returns:

id date time zone currency importance event actual forecast previous
426229 08/04/2021 09:30 united kingdom GBP high Construction PMI (Mar) 61.7 54.6 53.3
427371 08/04/2021 12:30 euro zone EUR high ECB Publishes Account of Monetary Policy Meeting None None None
427144 08/04/2021 13:30 united states USD high Initial Jobless Claims None 680K 719K
427152 08/04/2021 17:00 united states USD high Fed Chair Powell Speaks None None None

If I run it multiple more times, it seems to switch randomly between the two sets of times.

In the above example, the first run returns incorrect (vs. what I would expect) times and the second run returns correct times. It does not make any sense to me why running exactly the same code might return different times in each case. The problem persists even if I specify the time_zone parameter explicitly.

Taking the first row of data as an example. The times are returned seemingly randomly when the code is run over and over again as outlined below.

Run with time_zone= 'GMT'. Returns, inconsistently, either 08:30 or 09:30. Run with time_zone = 'GMT -1:00'. Returns, inconsistently, either 07:30 or 08:30. Run with time_zone = 'GMT +1:00'. Rturns, incosistently, either 09:30 or 10:30.

agftrading avatar Apr 08 '21 12:04 agftrading

Hi @agftrading, thanks for reporting this issue! :+1:

I've labeled it not just as a bug but also as an Investing.com issue, as I think that the bug comes from the site and not from the Python package. Anyway, I'll reproduce the issue and try to solve it as it may also be that Investing.com updated the values from the timezones, which means that either the API method or the allowed parameters (so on the default value may be wrong, when timezone=None, which leads to this issue) are not valid anymore.

But as you mention that either using a defined timezone or its default value timezone=None, the times seem to be "random", so my guess is that the request parameters have been updated, maybe on the spring hour change some weeks ago... Also to let you know that Investing.com provides more than one identifier per GMT timezone so that the election is random between all the allowed values...

Thanks for reporting this! Consider it done or at least checked in the next couple of days :fire:

alvarobartt avatar Apr 14 '21 16:04 alvarobartt

That is great. Thanks!

agftrading avatar Apr 16 '21 16:04 agftrading

Hi,

May I know when this issue will be resolved?

mpresence avatar Sep 15 '21 17:09 mpresence

Hi @mpresence I didn't have time until now to work on my projects, but now I do, so I'll try to work on most of the relevant issues/bugs during this weekend so that later I can also focus on the feature requests 👍🏻

alvarobartt avatar Sep 16 '21 07:09 alvarobartt

Thanks @alvarobartt you have done a great job with this...keep it up 😊

mpresence avatar Sep 18 '21 19:09 mpresence

Maybe it's not the correct way of fixing this problem, I'm still a newbie in programming, but in the file "utils/constant.py" I modified the "TIMEZONES" set and only left one element for each time zone list, and now the function gives me the same hours, it doesn't switch anymore. I think the problem comes from there, some numbers in the lists dont correspond to the correct GMT zones.

rodrigoperales avatar Oct 27 '21 09:10 rodrigoperales

Mmm thanks for spotting that @rodrigoperales! TBH that may be the issue, but as far as I could check in the past in Investing.com they are using those selectors... Anyway I'll check this further later today so as to provide you a more detailed answer tomorrow!

So on, in case that's the issue feel free to open a PR once I give you a more detailed answer 👍🏻

alvarobartt avatar Oct 27 '21 11:10 alvarobartt

I did a inspection to see the values of the timezones in investing's website and these are the correct values now:

TIMEZONES = { 'GMT -11:00': [2,35], 'GMT -10:00': [3], 'GMT -8:00': [4], 'GMT -7:00': [37,36,5], 'GMT -6:00': [38,6], 'GMT -5:00': [42,39,7,40,41], 'GMT -4:00': [9,45,8,46,43], 'GMT -3:00': [44,10,12,48,49,51,47], 'GMT -2:30': [11], 'GMT -2:00': [50], 'GMT -1:00': [53], 'GMT': [14,55,56], 'GMT +1:00': [54,15,166,60], 'GMT +2:00': [16,57,58,65,67,59,61], 'GMT +3:00': [62,71,64,66,68,63,17,70,18,72], 'GMT +3:30': [19], 'GMT +4:00': [20,73], 'GMT +4:30': [21], 'GMT +5:00': [22,77], 'GMT +5:30': [23,79], 'GMT +5:45': [24], 'GMT +6:00': [25], 'GMT +6:30': [26], 'GMT +7:00': [27], 'GMT +8:00': [28,178,113], 'GMT +9:00': [29,88], 'GMT +10:00': [91,94], 'GMT +10:30': [30], 'GMT +11:00': [31,32], 'GMT +12:00': [1], 'GMT +13:00': [33] }

I checked it a little bit to see if it worked and it did. The problem I see with this approach is that they might change again in future, specially after next sunday time change in Europe at least.

I wish I could help more and made this more automatic but i lack the knowledge.

Thanks by the way for this amazing work.

rodrigoperales avatar Oct 27 '21 13:10 rodrigoperales

Thanks for the support and the kind words @rodrigoperales! :hugs:

No worries, I'll try that and I will also be looking forward to the time change so as to see whether those values change or not, so as to provide a more consistent solution, since using static data (not super easy to update) is obviously not the desired solution.

FYI I'm planning to deprecate as much of the static data as I can for investpy v2.0 🎉 Anyway, not sure whether that will be possible or not, still some more months of refactoring and testing stuff!

alvarobartt avatar Oct 28 '21 07:10 alvarobartt

That sounds great, it must be difficult to do that. Thanks

rodrigoperales avatar Oct 29 '21 09:10 rodrigoperales

Thanks @rodrigoperales this worked for me https://github.com/alvarobartt/investpy/issues/331#issuecomment-952944746

stevenm100 avatar Sep 26 '22 21:09 stevenm100

@rodrigoperales Hi Rodrigo, how did you get the values for the variable TIMEZONE in investings website?

albertcuspi avatar Aug 03 '23 08:08 albertcuspi