Merge pull request #1296 from quantopian/fix_month_start_rule

BUG: get_first_trading_day_of_month needs to return normalized dt
This commit is contained in:
Andrew Liang
2016-06-21 12:55:06 -04:00
committed by GitHub
2 changed files with 13 additions and 7 deletions
+12 -6
View File
@@ -277,10 +277,15 @@ class TestStatelessRules(RuleTestCase):
cls.nyse_cal = get_calendar('NYSE')
# First day of 09/2014 is closed whereas that for 10/2014 is open
cls.sept_days = cls.nyse_cal.trading_days_in_range(
pd.Timestamp('2014-09-01'),
pd.Timestamp('2014-09-30'),
)
cls.oct_days = cls.nyse_cal.trading_days_in_range(
pd.Timestamp('2014-10-01'),
pd.Timestamp('2014-10-31'),
)
cls.sept_week = cls.nyse_cal.trading_minutes_for_days_in_range(
datetime.date(year=2014, month=9, day=21),
@@ -490,12 +495,13 @@ class TestStatelessRules(RuleTestCase):
rule = NthTradingDayOfMonth(n)
rule.cal = cal
should_trigger = rule.should_trigger
for n_tdays, d in enumerate(self.sept_days):
for m in self.nyse_cal.trading_minutes_for_day(d):
if should_trigger(m):
self.assertEqual(n_tdays, n)
else:
self.assertNotEqual(n_tdays, n)
for days_list in (self.sept_days, self.oct_days):
for n_tdays, d in enumerate(days_list):
for m in self.nyse_cal.trading_minutes_for_day(d):
if should_trigger(m):
self.assertEqual(n_tdays, n)
else:
self.assertNotEqual(n_tdays, n)
@subtest(param_range(MAX_MONTH_RANGE), 'n')
def test_NDaysBeforeLastTradingDayOfMonth(self, n):
+1 -1
View File
@@ -539,7 +539,7 @@ class NthTradingDayOfMonth(TradingDayOfMonthRule):
self.month = dt.month
dt = dt.replace(day=1)
first_day = (dt if self.cal.is_open_on_day(dt)
first_day = (normalize_date(dt) if self.cal.is_open_on_day(dt)
else self.cal.next_trading_day(dt))
return first_day