Esempio n. 1
0
        def test_calendar_with_date_convention(self):
            sse_cal = Calendar('China.SSE')

            reference_date = Date(2015, 2, 14)
            test_date = sse_cal.adjust_date(
                reference_date, BizDayConventions.HalfMonthModifiedFollowing)
            self.assertEqual(test_date, Date(2015, 2, 13))

            reference_date = Date(2014, 2, 4)
            test_date = sse_cal.adjust_date(
                reference_date, BizDayConventions.ModifiedPreceding)
            self.assertEqual(test_date, Date(2014, 2, 7))

            reference_date = Date(2014, 2, 3)
            test_date = sse_cal.adjust_date(reference_date,
                                            BizDayConventions.Nearest)
            self.assertEqual(test_date, Date(2014, 2, 7))

            reference_date = Date(2014, 2, 2)
            test_date = sse_cal.adjust_date(reference_date,
                                            BizDayConventions.Nearest)
            self.assertEqual(test_date, Date(2014, 1, 30))

            with self.assertRaises(ValueError):
                _ = sse_cal.adjust_date(reference_date, -1)
Esempio n. 2
0
        def test_adjust_date(self):
            # April 30, 2005 is a working day under IB, but a holiday under SSE
            reference_date = Date(2005, Months.April, 30)

            sse_cal = Calendar('China.SSE')
            ib_cal = Calendar('China.IB')

            biz_day_conv = BizDayConventions.Unadjusted
            self.assertEqual(sse_cal.adjust_date(reference_date, biz_day_conv),
                             reference_date)
            self.assertEqual(ib_cal.adjust_date(reference_date, biz_day_conv),
                             reference_date)

            biz_day_conv = BizDayConventions.Following
            self.assertEqual(sse_cal.adjust_date(reference_date, biz_day_conv),
                             Date(2005, Months.May, 9))
            self.assertEqual(ib_cal.adjust_date(reference_date, biz_day_conv),
                             Date(2005, Months.April, 30))

            biz_day_conv = BizDayConventions.ModifiedFollowing
            self.assertEqual(sse_cal.adjust_date(reference_date, biz_day_conv),
                             Date(2005, Months.April, 29))
            self.assertEqual(ib_cal.adjust_date(reference_date, biz_day_conv),
                             Date(2005, Months.April, 30))