diff --git a/tests/test_tradingcalendar.py b/tests/test_tradingcalendar.py index c297bec1..0a9b7e03 100644 --- a/tests/test_tradingcalendar.py +++ b/tests/test_tradingcalendar.py @@ -53,35 +53,6 @@ If NYE falls on a weekend, {0} the Tuesday after is the first trading day. """.strip().format(first_trading_day_after_new_years_sunday) ) - # January 2005 - # Su Mo Tu We Th Fr Sa - # 1 - # 2 3 4 5 6 7 8 - # 9 10 11 12 13 14 15 - # 16 17 18 19 20 21 22 - # 23 24 25 26 27 28 29 - # 30 31 - - day_after_new_years_saturday = datetime.datetime( - 2005, 1, 3, tzinfo=pytz.utc) - - self.assertNotIn(day_after_new_years_saturday, - tradingcalendar.trading_days, - """ -If NYE falls on a weekend, {0} the Monday after is a holiday. -""".strip().format(day_after_new_years_saturday) - ) - - first_trading_day_after_new_years_saturday = datetime.datetime( - 2005, 1, 4, tzinfo=pytz.utc) - - self.assertIn(first_trading_day_after_new_years_saturday, - tradingcalendar.trading_days, - """ -If NYE falls on a weekend, {0} the Tuesday after is the first trading day. -""".strip().format(first_trading_day_after_new_years_saturday) - ) - # January 2013 # Su Mo Tu We Th Fr Sa # 1 2 3 4 5 diff --git a/zipline/utils/tradingcalendar.py b/zipline/utils/tradingcalendar.py index d5065fec..46fbbf71 100644 --- a/zipline/utils/tradingcalendar.py +++ b/zipline/utils/tradingcalendar.py @@ -56,16 +56,6 @@ def get_non_trading_days(start, end): ) non_trading_rules.append(new_years_sunday) - new_years_saturday = rrule.rrule( - rrule.MONTHLY, - byyearday=3, - byweekday=rrule.MO, - cache=True, - dtstart=start, - until=end - ) - non_trading_rules.append(new_years_saturday) - mlk_day = rrule.rrule( rrule.MONTHLY, bymonth=1, @@ -115,6 +105,28 @@ def get_non_trading_days(start, end): ) non_trading_rules.append(july_4th) + july_4th_sunday = rrule.rrule( + rrule.MONTHLY, + bymonth=7, + bymonthday=5, + byweekday=rrule.MO, + cache=True, + dtstart=start, + until=end + ) + non_trading_rules.append(july_4th_sunday) + + july_4th_saturday = rrule.rrule( + rrule.MONTHLY, + bymonth=7, + bymonthday=3, + byweekday=rrule.FR, + cache=True, + dtstart=start, + until=end + ) + non_trading_rules.append(july_4th_saturday) + labor_day = rrule.rrule( rrule.MONTHLY, bymonth=9, @@ -145,6 +157,29 @@ def get_non_trading_days(start, end): ) non_trading_rules.append(christmas) + christmas_sunday = rrule.rrule( + rrule.MONTHLY, + bymonth=12, + bymonthday=26, + byweekday=rrule.MO, + cache=True, + dtstart=start, + until=end + ) + non_trading_rules.append(christmas_sunday) + + # If Christmas is a Saturday then 24th, a Friday is observed. + christmas_saturday = rrule.rrule( + rrule.MONTHLY, + bymonth=12, + bymonthday=24, + byweekday=rrule.FR, + cache=True, + dtstart=start, + until=end + ) + non_trading_rules.append(christmas_saturday) + non_trading_ruleset = rrule.rruleset() for rule in non_trading_rules: