Trading Calendar thinks some trading days are holidays
Expected Behavior
The TradingDay for 2020-11-11 should not be marked as a public holiday.
Actual Behavior
The TradingDay for 2020-11-11 is marked as a public holiday even though it was not.
Potential Solution
Probably a data issue? I don’t know whether this is a one-off issue or whether there are more inaccuracies.
Reproducing the Problem
trading_day = self.trading_calendar.get_trading_day(datetime(2020, 11, 11))
assert not trading_day.public_holiday
System Information
n/a
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue
Hey @fumoboy007! mind clarifying which asset, security type/market the issue refers too?
@Martin-Molinero I am looking at the US equity market. I did a little more checking and it looks like the issue is pretty widespread.
Reproduction Code
The following code gets the daily trade bars for SPY and checks the corresponding TradingDay to see if it’s marked as a public holiday or a weekend. (These should never be marked as a public holiday or a weekend given that there is a daily trade bar for those days.)
class CheckTradingDayAccuracy(QCAlgorithm):
def initialize(self):
self.set_start_date(2005, 1, 1)
self._spy = self.add_equity(
ticker='SPY',
resolution=Resolution.DAILY,
fill_forward=False
).symbol
def on_data(
self,
data: Slice
):
bar = data.bars.get(self._spy)
if bar is None:
return
current_date = bar.time.date()
trading_day = self.trading_calendar.get_trading_day(
day=current_date
)
if trading_day.public_holiday:
self.debug(f"The Trading Calendar thinks {current_date.isoformat()} is a public holiday even though it is not.")
if trading_day.weekend:
self.debug(f"The Trading Calendar thinks {current_date.isoformat()} is a weekend even though it is not.")
Output
The Trading Calendar thinks 2005-10-10 is a public holiday even though it is not.
The Trading Calendar thinks 2005-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2006-10-09 is a public holiday even though it is not.
The Trading Calendar thinks 2006-11-10 is a public holiday even though it is not.
The Trading Calendar thinks 2007-10-08 is a public holiday even though it is not.
The Trading Calendar thinks 2007-11-12 is a public holiday even though it is not.
The Trading Calendar thinks 2008-10-13 is a public holiday even though it is not.
The Trading Calendar thinks 2008-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2009-10-12 is a public holiday even though it is not.
The Trading Calendar thinks 2009-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2010-10-11 is a public holiday even though it is not.
The Trading Calendar thinks 2010-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2010-12-31 is a public holiday even though it is not.
The Trading Calendar thinks 2011-10-10 is a public holiday even though it is not.
The Trading Calendar thinks 2011-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2012-10-08 is a public holiday even though it is not.
The Trading Calendar thinks 2012-11-12 is a public holiday even though it is not.
The Trading Calendar thinks 2013-10-14 is a public holiday even though it is not.
The Trading Calendar thinks 2013-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2014-10-13 is a public holiday even though it is not.
The Trading Calendar thinks 2014-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2015-10-12 is a public holiday even though it is not.
The Trading Calendar thinks 2015-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2016-10-10 is a public holiday even though it is not.
The Trading Calendar thinks 2016-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2017-10-09 is a public holiday even though it is not.
The Trading Calendar thinks 2017-11-10 is a public holiday even though it is not.
The Trading Calendar thinks 2018-10-08 is a public holiday even though it is not.
The Trading Calendar thinks 2018-11-12 is a public holiday even though it is not.
The Trading Calendar thinks 2019-10-14 is a public holiday even though it is not.
The Trading Calendar thinks 2019-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2020-10-12 is a public holiday even though it is not.
The Trading Calendar thinks 2020-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2021-10-11 is a public holiday even though it is not.
The Trading Calendar thinks 2021-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2021-12-31 is a public holiday even though it is not.
The Trading Calendar thinks 2022-10-10 is a public holiday even though it is not.
The Trading Calendar thinks 2022-11-11 is a public holiday even though it is not.
The Trading Calendar thinks 2023-10-09 is a public holiday even though it is not.
The Trading Calendar thinks 2023-11-10 is a public holiday even though it is not.
The Trading Calendar thinks 2024-10-14 is a public holiday even though it is not.
The Trading Calendar thinks 2024-11-11 is a public holiday even though it is not.
#8594 should fix this issue. I didn’t see an existing TradingCalendar test and I don’t have time to figure out how to set one up. @Martin-Molinero Can you help test?
trading_calendar will include holidays which might not affect every asset, suggest using the exchange hours on each asset which will be precise and allow different APIs, see the following example
var security = AddEquity("SPY", Resolution.Minute);
security.Exchange.DateIsOpen(...)
Edit: Leaving issue open though: we should potentially consider removing the usage of QLNet Calendar instances from this class, and instead relying 100% on the MHDB
Sounds good!