Skip to content

Commit

Permalink
Fix conflict between holidays and special dates
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
maread99 committed Jun 30, 2021
1 parent 23431fe commit bcbd5d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
11 changes: 10 additions & 1 deletion exchange_calendars/exchange_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,16 @@ def _special_dates(self, calendars, ad_hoc_dates, start_date, end_date):
return pd.Series([], dtype="datetime64[ns, UTC]")

result = pd.concat(merged).sort_index()
return result.loc[(result >= start_date) & (result <= end_date)]
result = result.loc[(result >= start_date) & (result <= end_date)]
# exclude any special date that conincides with a holiday
adhoc_holidays = pd.DatetimeIndex(self.adhoc_holidays, tz="UTC")
result = result[~result.index.isin(adhoc_holidays)]
reg_holidays = self.regular_holidays.holidays(
start_date.tz_convert(None), end_date.tz_convert(None)
)
if not reg_holidays.empty:
result = result[~result.index.isin(reg_holidays.tz_localize("UTC"))]
return result

def _calculate_special_opens(self, start, end):
return self._special_dates(
Expand Down
16 changes: 1 addition & 15 deletions exchange_calendars/exchange_calendar_xist.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,5 @@ def special_closes(self):

@property
def special_closes_adhoc(self):
# Some early close days fall on holidays, so we must filter those out
# of the early close list
collisions = [
# CAYS Day on May 19
pd.Timestamp("1994-05-19"),
# Day before Eid al Fitr observed as holiday in 2003
pd.Timestamp("2003-11-24"),
]

early_close_days = EidAlFitrHalfDay + EidAlAdhaHalfDay

early_close_days = [day for day in early_close_days if day not in collisions]

return [
(self.regular_early_close, early_close_days),
]
return [(self.regular_early_close, early_close_days)]
17 changes: 1 addition & 16 deletions exchange_calendars/exchange_calendar_xkls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from datetime import time
from itertools import chain

import pandas as pd
from pytz import timezone

from .exchange_calendar import HolidayCalendar, ExchangeCalendar
Expand Down Expand Up @@ -122,19 +121,5 @@ def adhoc_holidays(self):
@property
def special_closes_adhoc(self):
# Regular early closes on Chinese New Years Eve, Eid al-Fitr Eve
early_close_days = ChineseNewYearsHalfDay + EidAlFitrHalfDay

collisions = [
# Chinese New Year's Eve was a holiday until 2005
pd.Timestamp("1997-02-07"),
pd.Timestamp("1998-01-28"),
pd.Timestamp("2002-02-11"),
pd.Timestamp("2003-01-31"),
pd.Timestamp("2004-01-21"),
# Eid al-Fitr Eve was a holiday in 2003
pd.Timestamp("2003-11-24"),
]

early_close_days = list(set(early_close_days) - set(collisions))

early_close_days = list(set(ChineseNewYearsHalfDay + EidAlFitrHalfDay))
return [(self.regular_early_close, early_close_days)]

0 comments on commit bcbd5d3

Please sign in to comment.