def test_german_calendar(self):

        frankfcal = Germany(FrankfurtStockExchange)
        first_date = Date(31, Oct, 2009)
        second_date = Date(1, Jan, 2010)

        Dec_30_2009 = Date(30, Dec, 2009)
        Jan_4_2010 = Date(4, Jan, 2010)

        self.assertEquals(Dec_30_2009,
                          frankfcal.adjust(second_date, Preceding))
        self.assertEquals(Jan_4_2010,
                          frankfcal.adjust(second_date, ModifiedPreceding))

        mat = Period(2, Months)

        self.assertEquals(
            Jan_4_2010,
            frankfcal.advance(first_date,
                              period=mat,
                              convention=Following,
                              end_of_month=False))
        self.assertEquals(
            Dec_30_2009,
            frankfcal.advance(first_date,
                              period=mat,
                              convention=ModifiedFollowing,
                              end_of_month=False))
        self.assertEquals(
            41,
            frankfcal.business_days_between(first_date, second_date, False,
                                            False))
    def test_equality(self):
        date1 = Date(1, 1, 2011)
        date2 = Date(1, 1, 2011)
        date3 = datetime.date(2011, 1, 1)

        self.assertEquals(date1, date2)

        self.assertEquals(date1, date3)
    def test_short_calculation_first_period_afb(self):
        day_counter = ActualActual(AFB)
        from_date = Date(1, February, 1999)
        to_date = Date(1, July, 1999)

        expected_result = 0.410958904110

        self.assertAlmostEquals(expected_result,
                                day_counter.year_fraction(from_date, to_date))
    def test_is_business_day(self):

        ukcal = UnitedKingdom()

        bank_holiday_date = Date(3, May, 2010)  #Early May Bank Holiday
        business_day = Date(28, March, 2011)

        self.assertFalse(ukcal.is_business_day(bank_holiday_date))
        self.assertTrue(ukcal.is_business_day(business_day))
    def test_short_calculation_second_period_isda(self):
        day_counter = ActualActual(ISDA)
        from_date = Date(1, July, 1999)
        to_date = Date(1, July, 2000)

        expected_result = 1.001377348600

        self.assertAlmostEquals(expected_result,
                                day_counter.year_fraction(from_date, to_date))
    def test_thirty360(self):

        day_counter = Thirty360(EUROBONDBASIS)
        from_date = Date(1, July, 1999)
        to_date = Date(1, July, 2000)

        expected_result = 1.000000000000

        self.assertAlmostEquals(expected_result,
                                day_counter.year_fraction(from_date, to_date))
    def test_end_of_month(self):

        date1 = Date(16, Feb, 2011)

        date2 = end_of_month(date1)
        print date2

        expected_date = Date(28, Feb, 2011)

        self.assertTrue(expected_date == date2)
    def test_united_states_calendar(self):

        uscal = UnitedStates()
        holiday_date = Date(4, Jul, 2010)

        self.assertTrue(uscal.is_holiday(holiday_date))

        uscal = UnitedStates(market=NYSE)
        holiday_date = Date(5, Sep, 2011)  # Labor day

        self.assertTrue(uscal.is_holiday(holiday_date))
    def test_date_creation(self):

        date1 = Date(19, Nov, 1998)
        self.assertEquals(11, date1.month)

        date2 = Date(29, Feb, 2008)
        self.assertEquals(2, date2.month)

        with self.assertRaises(RuntimeError):
            # getting an invalid day
            date2 = Date(29, Feb, 2009)
    def test_short_calculation_first_period_isma(self):
        day_counter = ActualActual(ISMA)
        from_date = Date(1, February, 1999)
        to_date = Date(1, July, 1999)
        ref_start = Date(1, July, 1998)
        ref_end = Date(1, July, 1999)
        expected_result = 0.410958904110

        self.assertAlmostEquals(
            expected_result,
            day_counter.year_fraction(from_date, to_date, ref_start, ref_end))
    def test_short_calculation_second_period_isma(self):
        day_counter = ActualActual(ISMA)
        from_date = Date(1, July, 1999)
        to_date = Date(1, July, 2000)
        ref_start = Date(1, July, 1999)
        ref_end = Date(1, July, 2000)

        expected_result = 1.000000000000

        self.assertAlmostEquals(
            expected_result,
            day_counter.year_fraction(from_date, to_date, ref_start, ref_end))
    def test_calendar_date_advance(self):
        ukcal = UnitedKingdom()

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

        advanced_date = ukcal.advance(bank_holiday_date, step=6, units=Months)
        expected_date = Date(3, November, 2010)
        self.assertTrue(expected_date == advanced_date)

        period_10days = Period(10, Days)
        advanced_date = ukcal.advance(bank_holiday_date, period=period_10days)
        expected_date = Date(17, May, 2010)
        self.assertTrue(expected_date == advanced_date)
Beispiel #13
0
    def test_arithmetic_operators(self):

        # addition
        date1 = Date(19, Nov, 1998)
        date2 = date1 + 5
        expected_date = Date(24, Nov, 1998)
        self.assertTrue(expected_date == date2)

        # iadd
        date1 = Date(19, Nov, 1998)
        date1 += 3
        expected_date = Date(22, Nov, 1998)
        self.assertTrue(expected_date == date1)

        # substraction
        date1 = Date(19, Nov, 1998)
        date3 = date1 - 5
        expected_date = Date(14, Nov, 1998)
        self.assertTrue(expected_date == date3)

        # isub
        date1 = Date(19, Nov, 1998)
        date1 -= 3
        expected_date = Date(16, Nov, 1998)
        self.assertTrue(expected_date == date1)
Beispiel #14
0
    def test_next_weekday(self):
        ''' Test next weekday

        The Friday following Tuesday, January 15th, 2002 was January 18th, 2002.
        see http://www.cpearson.com/excel/DateTimeWS.htm
        '''

        date1 = Date(15, Jan, 2002)
        date2 = next_weekday(date1, Friday)

        expected_date = Date(18, Jan, 2002)
        print expected_date
        print date2
        self.assertTrue(expected_date == date2)
    def test_business_days_between_dates(self):

        ukcal = UnitedKingdom()

        date1 = Date(30, May, 2011)

        # 30st of May is Spring Bank Holiday
        date2 = Date(3, June, 2011)

        day_count = ukcal.business_days_between(date1,
                                                date2,
                                                include_last=True)

        self.assertEquals(4, day_count)
    def test_christmas_is_holiday(self):

        calendar = TARGET()

        date = Date(24, 12, 2011)

        self.assertTrue(calendar.is_holiday(date))
    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
        )


        for date in self.schedule.dates():
            print date
Beispiel #18
0
    def test_adding_period_to_date(self):

        date1 = Date(1, May, 2011)

        period = Period(1, Months)
        date2 = date1 + period
        expected_date = Date(1, Jun, 2011)
        self.assertTrue(expected_date == date2)

        period = Period(Bimonthly)
        date2 = date1 + period
        expected_date = Date(1, Jul, 2011)
        self.assertTrue(expected_date == date2)

        period = Period(10, Months)
        date2 = date1 + period
        expected_date = Date(1, Mar, 2012)
        self.assertTrue(expected_date == date2)
Beispiel #19
0
    def test_substracting_period_to_date(self):

        date1 = Date(1, May, 2011)

        period = Period(1, Months)
        date2 = date1 - period
        expected_date = Date(1, Apr, 2011)
        self.assertTrue(expected_date == date2)

        period = Period(Bimonthly)
        date2 = date1 - period
        expected_date = Date(1, Mar, 2011)
        self.assertTrue(expected_date == date2)

        period = Period(10, Days)
        date2 = date1 - period
        expected_date = Date(21, Apr, 2011)
        self.assertTrue(expected_date == date2)
Beispiel #20
0
    def test_nth_weekday(self):
        ''' The 4th Thursday of Mar, 1998 was Mar 26th, 1998.
        see http://www.cpearson.com/excel/DateTimeWS.htm
        '''

        date1 = nth_weekday(4, Thursday, Mar, 1998)

        expected_date = Date(26, Mar, 1998)
        self.assertTrue(expected_date == date1)
Beispiel #21
0
    def test_comparison_with_datetime(self):

        date_nov_98 = Date(19, Nov, 1998)
        datetime_date_nov_98 = datetime.date(1998, 11, 19)

        self.assertTrue(date_nov_98 == datetime_date_nov_98)
        self.assertEquals(cmp(date_nov_98, datetime_date_nov_98), 0)

        datetime_date_oct_98 = datetime.date(1998, 10, 19)
        self.assertTrue(date_nov_98 > datetime_date_oct_98)
Beispiel #22
0
    def test_from_datetime_classmethod(self):

        date1 = Date(19, Nov, 1998)

        datetime_date = datetime.date(1998, 11, 19)
        from_datetime_date = Date.from_datetime(datetime_date)
        self.assertEquals(from_datetime_date.serial, date1.serial)

        datetime_datetime = datetime.datetime(1998, 11, 19, 01, 00)
        from_datetime_datetime = Date.from_datetime(datetime_datetime)
        self.assertEquals(from_datetime_datetime.serial, date1.serial)
    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)
        print expected_date, self.schedule.at(1)
        
        self.assertTrue(expected_date == self.schedule.at(1))
    def test_simple(self):

        periods = [3, 6, 12]
        expected_times = [0.25, 0.5, 1.0]
        first = Date(1, January, 2002)

        day_counter = SimpleDayCounter()

        for index, period in enumerate(periods):
            end = first + Period(period, Months)
            calculated = day_counter.year_fraction(first, end)
            self.assertAlmostEquals(expected_times[index], calculated)
    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) 
        print expected_date, fwd_schedule.next_date(from_date)
        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))
    def test_create_schedule(self):

        from_date = Date(1, Jan, 2011)
        to_date = Date(31, Dec, 2011)
        tenor = Period(3, Weeks)
        calendar = UnitedKingdom()
        convention = Following
        termination_convention = Following
        rule = Forward

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

        for date in schedule.dates():
            print date

        self.assert_(schedule is not None)

        # Constructor using the defaults for the different conventions
        schedule = Schedule(from_date, to_date, tenor, calendar)

        self.assert_(schedule is not None)
    def test_iteration_on_date_list(self):

        date_iterator = holiday_list(TARGET(), Date(1, Jan, 2000),
                                     Date(1, Jan, 2001))

        holidays = [
            Date(21, Apr, 2000),
            Date(24, Apr, 2000),
            Date(1, May, 2000),
            Date(25, Dec, 2000),
            Date(26, Dec, 2000),
            Date(1, Jan, 2001)
        ]

        for date in date_iterator:
            self.assertIn(date, holidays)
    def test_today(self):

        pydate = date(2030, 7, 1)

        cf_date = Date(1, 7, 2030)
        cf_amount = 100.0

        test_cf = cf.SimpleCashFlow(cf_amount, cf_date)

        self.assertEquals(test_cf.amount, cf_amount)
        self.assertEquals(test_cf.date, cf_date)

        leg = ((cf_amount, cf_date), )

        test_leg = cf.SimpleLeg(leg)

        self.assertEquals(test_leg.size, 1)
        self.assertEquals(test_leg.items, [(100.0, pydate)])
    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)
    def test_holiday_list_acces_and_modification(self):

        ukcal = UnitedKingdom()

        holidays = list(
            holiday_list(ukcal, Date(1, Jan, 2011), Date(31, 12, 2011)))
        self.assertEquals(8, len(holidays))

        new_holiday_date = Date(23, August, 2011)

        ukcal.add_holiday(new_holiday_date)

        holidays = list(
            holiday_list(ukcal, Date(1, Jan, 2011), Date(31, 12, 2011)))
        self.assertEquals(9, len(holidays))

        ukcal.remove_holiday(new_holiday_date)

        holidays = list(
            holiday_list(ukcal, Date(1, Jan, 2011), Date(31, 12, 2011)))
        self.assertEquals(8, len(holidays))