Skip to content

Commit

Permalink
Merge pull request quantopian#121 from philiptromans/xcbf-good-friday…
Browse files Browse the repository at this point in the history
…-always-a-holiday

Made Good Friday always a holiday in XCBF
  • Loading branch information
gerrymanoim authored Dec 9, 2021
2 parents 6f7e482 + b163c64 commit d1f4271
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
31 changes: 1 addition & 30 deletions exchange_calendars/exchange_calendar_xcbf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from datetime import time
from itertools import chain

import pandas as pd
from pandas.tseries.holiday import (
GoodFriday,
Holiday,
USLaborDay,
USPresidentsDay,
USThanksgivingDay,
Expand All @@ -25,33 +23,6 @@
)


def good_friday_unless_christmas_nye_friday(dt):
"""
Good Friday is a valid trading day if Christmas Day or New Years Day fall
on a Friday.
"""
year_str = str(dt.year)
christmas_weekday = Christmas.observance(
pd.Timestamp(year_str + "-12-25")
).weekday()
nyd_weekday = USNewYearsDay.observance(pd.Timestamp(year_str + "-01-01")).weekday()
if christmas_weekday != 4 and nyd_weekday != 4:
return GoodFriday._apply_rule(
pd.Timestamp(str(dt.year) + "-" + str(dt.month) + "-" + str(dt.day))
)
else:
# compatibility for pandas 0.18.1
return pd.NaT


GoodFridayUnlessChristmasNYEFriday = Holiday(
name="Good Friday XCBF",
month=1,
day=1,
observance=good_friday_unless_christmas_nye_friday,
)


class XCBFExchangeCalendar(ExchangeCalendar):
"""
Exchange calendar for the CBOE Futures Exchange (XCBF).
Expand Down Expand Up @@ -79,7 +50,7 @@ def regular_holidays(self):
USNewYearsDay,
USMartinLutherKingJrAfter1998,
USPresidentsDay,
GoodFridayUnlessChristmasNYEFriday,
GoodFriday,
USIndependenceDay,
USMemorialDay,
USLaborDay,
Expand Down
9 changes: 0 additions & 9 deletions tests/resources/xcbf.csv
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@
1992-04-14T00:00:00Z,1992-04-14T13:30:00Z,1992-04-14T20:15:00Z,,
1992-04-15T00:00:00Z,1992-04-15T13:30:00Z,1992-04-15T20:15:00Z,,
1992-04-16T00:00:00Z,1992-04-16T13:30:00Z,1992-04-16T20:15:00Z,,
1992-04-17T00:00:00Z,1992-04-17T13:30:00Z,1992-04-17T20:15:00Z,,
1992-04-20T00:00:00Z,1992-04-20T13:30:00Z,1992-04-20T20:15:00Z,,
1992-04-21T00:00:00Z,1992-04-21T13:30:00Z,1992-04-21T20:15:00Z,,
1992-04-22T00:00:00Z,1992-04-22T13:30:00Z,1992-04-22T20:15:00Z,,
Expand Down Expand Up @@ -828,7 +827,6 @@
1993-04-06T00:00:00Z,1993-04-06T13:30:00Z,1993-04-06T20:15:00Z,,
1993-04-07T00:00:00Z,1993-04-07T13:30:00Z,1993-04-07T20:15:00Z,,
1993-04-08T00:00:00Z,1993-04-08T13:30:00Z,1993-04-08T20:15:00Z,,
1993-04-09T00:00:00Z,1993-04-09T13:30:00Z,1993-04-09T20:15:00Z,,
1993-04-12T00:00:00Z,1993-04-12T13:30:00Z,1993-04-12T20:15:00Z,,
1993-04-13T00:00:00Z,1993-04-13T13:30:00Z,1993-04-13T20:15:00Z,,
1993-04-14T00:00:00Z,1993-04-14T13:30:00Z,1993-04-14T20:15:00Z,,
Expand Down Expand Up @@ -2093,7 +2091,6 @@
1998-04-07T00:00:00Z,1998-04-07T13:30:00Z,1998-04-07T20:15:00Z,,
1998-04-08T00:00:00Z,1998-04-08T13:30:00Z,1998-04-08T20:15:00Z,,
1998-04-09T00:00:00Z,1998-04-09T13:30:00Z,1998-04-09T20:15:00Z,,
1998-04-10T00:00:00Z,1998-04-10T13:30:00Z,1998-04-10T20:15:00Z,,
1998-04-13T00:00:00Z,1998-04-13T13:30:00Z,1998-04-13T20:15:00Z,,
1998-04-14T00:00:00Z,1998-04-14T13:30:00Z,1998-04-14T20:15:00Z,,
1998-04-15T00:00:00Z,1998-04-15T13:30:00Z,1998-04-15T20:15:00Z,,
Expand Down Expand Up @@ -2340,7 +2337,6 @@
1999-03-30T00:00:00Z,1999-03-30T14:30:00Z,1999-03-30T21:15:00Z,,
1999-03-31T00:00:00Z,1999-03-31T14:30:00Z,1999-03-31T21:15:00Z,,
1999-04-01T00:00:00Z,1999-04-01T14:30:00Z,1999-04-01T21:15:00Z,,
1999-04-02T00:00:00Z,1999-04-02T14:30:00Z,1999-04-02T21:15:00Z,,
1999-04-05T00:00:00Z,1999-04-05T13:30:00Z,1999-04-05T20:15:00Z,,
1999-04-06T00:00:00Z,1999-04-06T13:30:00Z,1999-04-06T20:15:00Z,,
1999-04-07T00:00:00Z,1999-04-07T13:30:00Z,1999-04-07T20:15:00Z,,
Expand Down Expand Up @@ -3607,7 +3603,6 @@
2004-04-06T00:00:00Z,2004-04-06T13:30:00Z,2004-04-06T20:15:00Z,,
2004-04-07T00:00:00Z,2004-04-07T13:30:00Z,2004-04-07T20:15:00Z,,
2004-04-08T00:00:00Z,2004-04-08T13:30:00Z,2004-04-08T20:15:00Z,,
2004-04-09T00:00:00Z,2004-04-09T13:30:00Z,2004-04-09T20:15:00Z,,
2004-04-12T00:00:00Z,2004-04-12T13:30:00Z,2004-04-12T20:15:00Z,,
2004-04-13T00:00:00Z,2004-04-13T13:30:00Z,2004-04-13T20:15:00Z,,
2004-04-14T00:00:00Z,2004-04-14T13:30:00Z,2004-04-14T20:15:00Z,,
Expand Down Expand Up @@ -4867,7 +4862,6 @@
2009-04-07T00:00:00Z,2009-04-07T13:30:00Z,2009-04-07T20:15:00Z,,
2009-04-08T00:00:00Z,2009-04-08T13:30:00Z,2009-04-08T20:15:00Z,,
2009-04-09T00:00:00Z,2009-04-09T13:30:00Z,2009-04-09T20:15:00Z,,
2009-04-10T00:00:00Z,2009-04-10T13:30:00Z,2009-04-10T20:15:00Z,,
2009-04-13T00:00:00Z,2009-04-13T13:30:00Z,2009-04-13T20:15:00Z,,
2009-04-14T00:00:00Z,2009-04-14T13:30:00Z,2009-04-14T20:15:00Z,,
2009-04-15T00:00:00Z,2009-04-15T13:30:00Z,2009-04-15T20:15:00Z,,
Expand Down Expand Up @@ -5114,7 +5108,6 @@
2010-03-30T00:00:00Z,2010-03-30T13:30:00Z,2010-03-30T20:15:00Z,,
2010-03-31T00:00:00Z,2010-03-31T13:30:00Z,2010-03-31T20:15:00Z,,
2010-04-01T00:00:00Z,2010-04-01T13:30:00Z,2010-04-01T20:15:00Z,,
2010-04-02T00:00:00Z,2010-04-02T13:30:00Z,2010-04-02T20:15:00Z,,
2010-04-05T00:00:00Z,2010-04-05T13:30:00Z,2010-04-05T20:15:00Z,,
2010-04-06T00:00:00Z,2010-04-06T13:30:00Z,2010-04-06T20:15:00Z,,
2010-04-07T00:00:00Z,2010-04-07T13:30:00Z,2010-04-07T20:15:00Z,,
Expand Down Expand Up @@ -6374,7 +6367,6 @@
2015-03-31T00:00:00Z,2015-03-31T13:30:00Z,2015-03-31T20:15:00Z,,
2015-04-01T00:00:00Z,2015-04-01T13:30:00Z,2015-04-01T20:15:00Z,,
2015-04-02T00:00:00Z,2015-04-02T13:30:00Z,2015-04-02T20:15:00Z,,
2015-04-03T00:00:00Z,2015-04-03T13:30:00Z,2015-04-03T20:15:00Z,,
2015-04-06T00:00:00Z,2015-04-06T13:30:00Z,2015-04-06T20:15:00Z,,
2015-04-07T00:00:00Z,2015-04-07T13:30:00Z,2015-04-07T20:15:00Z,,
2015-04-08T00:00:00Z,2015-04-08T13:30:00Z,2015-04-08T20:15:00Z,,
Expand Down Expand Up @@ -6621,7 +6613,6 @@
2016-03-22T00:00:00Z,2016-03-22T13:30:00Z,2016-03-22T20:15:00Z,,
2016-03-23T00:00:00Z,2016-03-23T13:30:00Z,2016-03-23T20:15:00Z,,
2016-03-24T00:00:00Z,2016-03-24T13:30:00Z,2016-03-24T20:15:00Z,,
2016-03-25T00:00:00Z,2016-03-25T13:30:00Z,2016-03-25T20:15:00Z,,
2016-03-28T00:00:00Z,2016-03-28T13:30:00Z,2016-03-28T20:15:00Z,,
2016-03-29T00:00:00Z,2016-03-29T13:30:00Z,2016-03-29T20:15:00Z,,
2016-03-30T00:00:00Z,2016-03-30T13:30:00Z,2016-03-30T20:15:00Z,,
Expand Down
10 changes: 1 addition & 9 deletions tests/test_xcbf_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def regular_holidays_sample(self):
"2016-01-01", # new years: jan 1
"2016-01-18", # mlk: jan 18
"2016-02-15", # presidents: feb 15
"2016-03-25", # good friday: mar 25
"2016-05-30", # mem day: may 30
"2016-07-04", # independence day: july 4
"2016-09-05", # labor day: sep 5
Expand All @@ -39,15 +40,6 @@ def adhoc_holidays_sample(self):
"2012-10-30", # - jan 2 2007
]

@pytest.fixture
def non_holidays_sample(self):
yield [
# Good Friday is not a holiday when Christas Day or New Year's Day falls
# on a Friday.
"2015-04-03",
"2016-03-25",
]

@pytest.fixture
def early_closes_sample(self):
yield ["2016-11-25"]
Expand Down

0 comments on commit d1f4271

Please sign in to comment.