コード例 #1
0
class ScheduleMethodTestCase(unittest.TestCase):
    def setUp(self):
        self.from_date = Date(1, Jan, 2011)
        self.to_date = Date(31, Dec, 2011)
        self.tenor = Period(4, Weeks)
        self.calendar = UnitedKingdom()
        self.convention = Following
        self.termination_convention = Preceding
        self.rule = Twentieth

        self.schedule = Schedule(self.from_date, self.to_date, self.tenor,
                                 self.calendar, self.convention,
                                 self.termination_convention, self.rule)

    def test_size(self):

        self.assertEquals(15, self.schedule.size())

    def test_dates(self):

        expected_dates_length = self.schedule.size()
        dates = list(self.schedule.dates())

        self.assertEquals(expected_dates_length, len(dates))

    def test_at(self):

        expected_date = self.calendar.adjust(self.from_date, Following)
        self.assertTrue(expected_date == self.schedule.at(0))

        next_date = self.calendar.adjust(self.from_date + Period(4, Weeks),
                                         Following)
        expected_date = Date(20, next_date.month, next_date.year)

        self.assertTrue(expected_date == self.schedule.at(1))

    def test_previous_next_reference_date(self):
        from_date = Date(3, Sep, 2011)
        to_date = Date(15, Dec, 2011)
        tenor = Period(1, Months)
        calendar = UnitedKingdom()
        convention = Following
        termination_convention = Following
        rule = Forward

        fwd_schedule = Schedule(from_date, to_date, tenor, calendar,
                                convention, termination_convention, rule)

        expected_date = Date(5, Sep, 2011)
        self.assert_(expected_date == fwd_schedule.next_date(from_date))

        rule = Backward

        bwd_schedule = Schedule(from_date, to_date, tenor, calendar,
                                convention, termination_convention, rule)

        expected_date = Date(15, Nov, 2011)
        self.assert_(expected_date == bwd_schedule.previous_date(to_date))
コード例 #2
0
ファイル: test_calendar.py プロジェクト: AlexArgus/pyql
    def test_adjust_business_day(self):

        ukcal = UnitedKingdom()

        bank_holiday_date = Date(3, May, 2010)  # Early May Bank Holiday

        adjusted_date = ukcal.adjust(bank_holiday_date)
        following_date = bank_holiday_date + 1
        self.assertTrue(following_date == adjusted_date)

        adjusted_date = ukcal.adjust(bank_holiday_date, convention=Preceding)
        following_date = bank_holiday_date - 3  # bank holiday is a Monday
        self.assertTrue(following_date == adjusted_date)

        adjusted_date = ukcal.adjust(bank_holiday_date, convention=ModifiedPreceding)
        following_date = bank_holiday_date + 1  # Preceding is on a different
        # month
        self.assertTrue(following_date == adjusted_date)
コード例 #3
0
ファイル: test_calendar.py プロジェクト: vishalbelsare/pyql
    def test_adjust_business_day(self):

        ukcal = UnitedKingdom()

        bank_holiday_date = Date(3, May, 2010)  #Early May Bank Holiday

        adjusted_date = ukcal.adjust(bank_holiday_date)
        following_date = bank_holiday_date + 1
        self.assertTrue(following_date == adjusted_date)

        adjusted_date = ukcal.adjust(bank_holiday_date, convention=Preceding)
        following_date = bank_holiday_date - 3  # bank holiday is a Monday
        self.assertTrue(following_date == adjusted_date)

        adjusted_date = ukcal.adjust(bank_holiday_date,
                                     convention=ModifiedPreceding)
        following_date = bank_holiday_date + 1  # Preceding is on a different
        # month
        self.assertTrue(following_date == adjusted_date)
コード例 #4
0
ファイル: test_schedule.py プロジェクト: enthought/pyql
class ScheduleMethodTestCase(unittest.TestCase):

    def setUp(self):
        self.from_date = Date(1, Jan, 2011)
        self.to_date = Date(31, Dec, 2011)
        self.tenor = Period(4, Weeks)
        self.calendar = UnitedKingdom()
        self.convention = Following
        self.termination_convention = Preceding
        self.rule = Twentieth

        self.schedule = Schedule.from_rule(
            self.from_date, self.to_date, self.tenor, self.calendar,
            self.convention, self.termination_convention, self.rule
        )

    def test_size(self):

        self.assertEqual(15, self.schedule.size())
        self.assertEqual(15, len(self.schedule))

    def test_dates(self):

        expected_dates_length = self.schedule.size()
        dates = list(self.schedule.dates())

        self.assertEqual(expected_dates_length, len(dates))

    def test_iter_dates(self):

        expected_dates_length = self.schedule.size()
        dates= [date for date in self.schedule]

        self.assertEqual(expected_dates_length, len(dates))

    def test_at(self):

        expected_date = self.calendar.adjust(self.from_date, Following)
        self.assertEqual(expected_date, self.schedule.at(0))
        self.assertEqual(expected_date, self.schedule[0])

        next_date = self.calendar.adjust(
            self.from_date + Period(4, Weeks), Following
        )
        expected_date = Date(20, next_date.month, next_date.year)

        self.assertEqual(expected_date, self.schedule.at(1))
        self.assertEqual(expected_date, self.schedule[1])

    def test_previous_next_reference_date(self):
        from_date = Date(3, Sep, 2011)
        to_date = Date(15, Dec, 2011)
        tenor = Period(1, Months)
        calendar = UnitedKingdom()
        convention = Following
        termination_convention = Following
        rule = Forward

        fwd_schedule = Schedule.from_rule(from_date, to_date,
                tenor, calendar, convention, termination_convention, rule)

        expected_date = Date(5, Sep, 2011)
        self.assertEqual(expected_date, fwd_schedule.next_date(from_date))

        rule = Backward

        bwd_schedule = Schedule.from_rule(from_date, to_date,
                tenor, calendar, convention, termination_convention, rule)

        expected_date = Date(15, Nov, 2011)
        self.assertEqual(expected_date, bwd_schedule.previous_date(to_date))

    def test_schedule_from_dates(self):
        dates = [Date(3, Sep, 2011),
                 Date(5, Nov, 2011),
                 Date(15, Dec, 2011)]
        tenor = Period(1, Months)
        calendar = UnitedKingdom()
        convention = Following
        termination_convention = Following
        rule = Forward

        schedule = Schedule.from_dates(dates,
                calendar, convention, termination_convention, tenor, rule)

        expected_date = Date(3, Sep, 2011)
        self.assert_(expected_date == schedule.next_date(Date(3, Sep, 2011)))

        expected_date = Date(5, Nov, 2011)
        self.assert_(expected_date == schedule.next_date(Date(4, Sep, 2011)))

        expected_date = Date(15, Dec, 2011)
        self.assert_(expected_date == schedule.next_date(Date(6, Nov, 2011)))