示例#1
0
    def test_invalid_offset(self):
        with self.assertRaises(ValueError):
            AfterOpen(hours=12, minutes=1)

        with self.assertRaises(ValueError):
            AfterOpen(hours=0, minutes=0)

        with self.assertRaises(ValueError):
            BeforeClose(hours=12, minutes=1)

        with self.assertRaises(ValueError):
            BeforeClose(hours=0, minutes=0)
示例#2
0
    def test_offset_too_far(self):
        minute_groups = minutes_for_days(self.cal, ordered_days=True)

        # Neither rule should ever fire, since they are configured to fire
        # 11+ hours after the open or before the close.  a NYSE session is
        # never longer than 6.5 hours.
        after_open_rule = AfterOpen(hours=11, minutes=11)
        after_open_rule.cal = self.cal

        before_close_rule = BeforeClose(hours=11, minutes=5)
        before_close_rule.cal = self.cal

        for session_minutes in minute_groups:
            for minute in session_minutes:
                self.assertFalse(after_open_rule.should_trigger(minute))
                self.assertFalse(before_close_rule.should_trigger(minute))
示例#3
0
    def test_offset_too_far(self):
        minute_groups = minutes_for_days(self.cal, ordered_days=True)

        # Neither rule should ever fire, since they are configured to fire
        # 11+ hours after the open or before the close.  a NYSE session is
        # never longer than 6.5 hours.
        after_open_rule = AfterOpen(hours=11, minutes=11)
        after_open_rule.cal = self.cal

        before_close_rule = BeforeClose(hours=11, minutes=5)
        before_close_rule.cal = self.cal

        for session_minutes in minute_groups:
            for minute in session_minutes:
                self.assertFalse(after_open_rule.should_trigger(minute))
                self.assertFalse(before_close_rule.should_trigger(minute))
示例#4
0
 def test_BeforeClose(self, ms):
     ms = list(ms)
     should_trigger = BeforeClose(hours=1, minutes=5).should_trigger
     for m in ms[0:-66]:
         self.assertFalse(should_trigger(m))
     for m in ms[-66:]:
         self.assertTrue(should_trigger(m))
示例#5
0
 def test_BeforeClose(self):
     should_trigger = BeforeClose(hours=1, minutes=5).should_trigger
     for d in self.trading_days:
         for m in d[0:-65]:
             self.assertFalse(should_trigger(m))
         for m in d[-65:]:
             self.assertTrue(should_trigger(m))
示例#6
0
 def setUpClass(cls):
     cls.env = TradingEnvironment()
     # On the AfterOpen and BeforeClose tests, we want ensure that the
     # functions are pure, and that running them with the same input will
     # provide the same output, regardless of whether the function is run 1
     # or N times. (For performance reasons, we cache some internal state
     # in AfterOpen and BeforeClose, but we don't want it to affect
     # purity). Hence, we use the same before_close and after_open across
     # subtests.
     cls.before_close = BeforeClose(hours=1, minutes=5)
     cls.after_open = AfterOpen(hours=1, minutes=5)
     cls.class_ = None  # Mark that this is the base class.
示例#7
0
 def market_close(offset=None, hours=None, minutes=None):
     return BeforeClose(offset=offset, hours=hours, minutes=minutes)