def test_NthTradingDayOfMonth(self, n): cal = get_calendar('NYSE') 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)
def test_invalid_offsets(self): with self.assertRaises(ValueError): NthTradingDayOfWeek(5) with self.assertRaises(ValueError): NthTradingDayOfWeek(-1) with self.assertRaises(ValueError): NthTradingDayOfMonth(-1) with self.assertRaises(ValueError): NthTradingDayOfMonth(24)
def test_NthTradingDayOfMonth(self, n): cal = get_calendar('NYSE') rule = NthTradingDayOfMonth(n) rule.cal = cal should_trigger = rule.should_trigger for sessions_list in (self.sept_sessions, self.oct_sessions): for n_tdays, session in enumerate(sessions_list): for m in self.nyse_cal.minutes_for_session(session): if should_trigger(m): self.assertEqual(n_tdays, n) else: self.assertNotEqual(n_tdays, n)
def test_NthTradingDayOfMonth(self): for n in range(MAX_MONTH_RANGE): rule = NthTradingDayOfMonth(n) rule.cal = self.cal should_trigger = rule.should_trigger for sessions_list in (self.sept_sessions, self.oct_sessions): for n_tdays, session in enumerate(sessions_list): # just check the first 10 minutes of each session for m in self.cal.minutes_for_session(session)[0:10]: if should_trigger(m): self.assertEqual(n_tdays, n) else: self.assertNotEqual(n_tdays, n)
def test_NthTradingDayOfMonth(self, n): should_trigger = NthTradingDayOfMonth(n).should_trigger for n_tdays, d in enumerate(self.sept_days): for m in self.env.market_minutes_for_day(d): if should_trigger(m): self.assertEqual(n_tdays, n) else: self.assertNotEqual(n_tdays, n)