Fixes for trading calendar holidays for weekend holidays.

- Removes New Year's on Saturday, in that case there is no New Year's observed.
- Adds Monday after a July 4th Sunday
- Adds Friday before a July 4th Saturday
- Adds Monday after a Christmas Sunday
- Adds Friday before a Christmas Saturday
This commit is contained in:
Eddie Hebert
2013-02-10 17:23:29 -05:00
parent 3e050dff9c
commit aa1caae261
2 changed files with 45 additions and 39 deletions
-29
View File
@@ -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
+45 -10
View File
@@ -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: