Esempio n. 1
0
 def test_NthTradingDayOfWeek_day_zero(self):
     """
     Test that we don't blow up when trying to call week_start's
     should_trigger on the first day of a trading environment.
     """
     cal = get_calendar('NYSE')
     rule = NthTradingDayOfWeek(0)
     rule.cal = cal
     self.assertTrue(rule.should_trigger(self.nyse_cal.all_trading_days[0]))
Esempio n. 2
0
 def test_NthTradingDayOfWeek_day_zero(self):
     """
     Test that we don't blow up when trying to call week_start's
     should_trigger on the first day of a trading environment.
     """
     cal = get_calendar('NYSE')
     rule = NthTradingDayOfWeek(0)
     rule.cal = cal
     self.assertTrue(
         rule.should_trigger(self.nyse_cal.all_trading_days[0])
     )
Esempio n. 3
0
    def test_edge_cases_for_TradingDayOfWeek(self):
        """
        Test that we account for midweek holidays. Monday 01/20 is a holiday.
        Ensure that the trigger date for that week is adjusted
        appropriately, or thrown out if not enough trading days. Also, test
        that if we start the simulation on a day where we miss the trigger
        for that week, that the trigger is recalculated for next week.
        """

        #    December 2013
        # 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

        #    January 2014
        # 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

        # Include last day of 2013 to exercise case where the first day of a
        # week is in the previous year.

        # `week_start`
        rule = NthTradingDayOfWeek(0)
        rule.cal = self.cal

        expected = {
            # A Monday before the New Year.
            '2013-12-30': True,
            # Should not trigger on day after.
            '2013-12-31': False,
            # Should not trigger at market open of 1-2, a Thursday,
            # day after a holiday.
            '2014-01-02': False,
            # Test that the next Monday, which is at a start of a
            # 'normal' week successfully triggers.
            '2014-01-06': True,
            # Test around a Monday holiday, MLK day, to exercise week
            # start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            '2014-01-21': True,
            # Should not trigger at market open of 01-22, a Wednesday.
            '2014-01-22': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)

        # Ensure that offset from start of week also works around edge cases.
        rule = NthTradingDayOfWeek(1)
        rule.cal = self.cal

        expected = {
            # Should trigger at market open of 12-31, day after week start.
            '2013-12-31': True,
            # Should not trigger at market open of 1-2, a Thursday,
            # day after a holiday.
            '2014-01-02': False,
            # Test around a Monday holiday, MLK day, to exercise
            # week start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            # Should trigger at market open, two days after Monday hoilday.
            '2014-01-22': True,
            # Should not trigger at market open of 01-23, a Thursday.
            '2014-01-23': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)

        # `week_end`
        rule = NDaysBeforeLastTradingDayOfWeek(0)
        rule.cal = self.cal

        expected = {
            # Should trigger at market open of the Friday of the first week.
            '2014-01-03': True,
            # Should not trigger day before the end of the week.
            '2014-01-02': False,
            # Test around a Monday holiday, MLK day, to exercise week
            # start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            # Should trigger at market open, on Friday after the holiday.
            '2014-01-24': True,
            # Should not trigger at market open of 01-23, a Thursday.
            '2014-01-23': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)
Esempio n. 4
0
    def test_edge_cases_for_TradingDayOfWeek(self):
        """
        Test that we account for midweek holidays. Monday 01/20 is a holiday.
        Ensure that the trigger date for that week is adjusted
        appropriately, or thrown out if not enough trading days. Also, test
        that if we start the simulation on a day where we miss the trigger
        for that week, that the trigger is recalculated for next week.
        """

        #    December 2013
        # 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

        #    January 2014
        # 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

        # Include last day of 2013 to exercise case where the first day of a
        # week is in the previous year.

        # `week_start`
        rule = NthTradingDayOfWeek(0)
        rule.cal = self.cal

        expected = {
            # A Monday before the New Year.
            '2013-12-30': True,
            # Should not trigger on day after.
            '2013-12-31': False,
            # Should not trigger at market open of 1-2, a Thursday,
            # day after a holiday.
            '2014-01-02': False,
            # Test that the next Monday, which is at a start of a
            # 'normal' week successfully triggers.
            '2014-01-06': True,
            # Test around a Monday holiday, MLK day, to exercise week
            # start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            '2014-01-21': True,
            # Should not trigger at market open of 01-22, a Wednesday.
            '2014-01-22': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)

        # Ensure that offset from start of week also works around edge cases.
        rule = NthTradingDayOfWeek(1)
        rule.cal = self.cal

        expected = {
            # Should trigger at market open of 12-31, day after week start.
            '2013-12-31': True,
            # Should not trigger at market open of 1-2, a Thursday,
            # day after a holiday.
            '2014-01-02': False,
            # Test around a Monday holiday, MLK day, to exercise
            # week start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            # Should trigger at market open, two days after Monday hoilday.
            '2014-01-22': True,
            # Should not trigger at market open of 01-23, a Thursday.
            '2014-01-23': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)

        # `week_end`
        rule = NDaysBeforeLastTradingDayOfWeek(0)
        rule.cal = self.cal

        expected = {
            # Should trigger at market open of the Friday of the first week.
            '2014-01-03': True,
            # Should not trigger day before the end of the week.
            '2014-01-02': False,
            # Test around a Monday holiday, MLK day, to exercise week
            # start on a Tuesday.
            # MLK is 2014-01-20 in 2014.
            # Should trigger at market open, on Friday after the holiday.
            '2014-01-24': True,
            # Should not trigger at market open of 01-23, a Thursday.
            '2014-01-23': False,
        }

        results = {
            x: rule.should_trigger(self.cal.next_open(T(x)))
            for x in expected.keys()
        }

        self.assertEquals(expected, results)