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

Trading Calendar thinks some trading days are holidays #8592

Open
4 tasks done
fumoboy007 opened this issue Feb 18, 2025 · 5 comments
Open
4 tasks done

Trading Calendar thinks some trading days are holidays #8592

fumoboy007 opened this issue Feb 18, 2025 · 5 comments

Comments

@fumoboy007
Copy link

fumoboy007 commented Feb 18, 2025

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

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
@Martin-Molinero
Copy link
Member

Hey @fumoboy007! mind clarifying which asset, security type/market the issue refers too?

@fumoboy007
Copy link
Author

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

@fumoboy007 fumoboy007 changed the title Trading Calendar thinks 2020-11-11 is a holiday Trading Calendar thinks some trading days are holidays Feb 18, 2025
fumoboy007 added a commit to fumoboy007/Lean that referenced this issue Feb 18, 2025
@fumoboy007
Copy link
Author

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

@Martin-Molinero
Copy link
Member

Martin-Molinero commented Feb 19, 2025

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

@fumoboy007
Copy link
Author

Sounds good!

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