示例#1
0
 def test_create_intereste_rate_with_daycounter_convention(self):
     rate = 0.05
     counter = Thirty360(ITALIAN)
     compounding = Compounded
     frequency = Monthly
     interest_rate = InterestRate(rate, counter, compounding, frequency)
     self.assertEqual(interest_rate.day_counter, counter)
示例#2
0
    def test_create_interest_rate_compounded_error(self):

        rate = 0.05
        counter = self.day_counter
        compounding = Compounded

        for frequency in [Once, NoFrequency]:
            with self.assertRaises(RuntimeError):
                InterestRate(rate, counter, compounding, frequency)
示例#3
0
    def test_repr(self):

        rate = 0.05
        counter = self.day_counter
        compounding = Compounded
        frequency = Monthly

        interest_rate = InterestRate(rate, counter, compounding, frequency)

        self.assertEqual(repr(interest_rate),
                         "0.05 Actual/360 Monthly compounding")
示例#4
0
    def test_linear_interpolation(self):
        interpolation_date = self.calendar.advance(self.today, 12, Months)
        t = self.term_structure.time_from_reference(interpolation_date)
        t1 = self.term_structure.time_from_reference(self.spread_dates[0])
        t2 = self.term_structure.time_from_reference(self.spread_dates[1])
        interpolated_zero_rate = (self.spreaded_term_structure.
                                  zero_rate(t, compounding=Continuous).rate)

        zero_rate = (self.term_structure.
                     zero_rate(t, compounding=Continuous, frequency=NoFrequency))
        expected_rate = zero_rate.rate + \
            (t - t1) / (t2 - t1 ) * self.spreads[1].value + \
            (t2 - t) / (t2 - t1) * self.spreads[0].value
        spreaded_rate = InterestRate(expected_rate,
                                     zero_rate.day_counter,
                                     zero_rate.compounding,
                                     zero_rate.frequency)

        self.assertAlmostEqual(interpolated_zero_rate,
                               spreaded_rate.equivalent_rate(Continuous, NoFrequency, t).rate)
示例#5
0
    def test_create_interest_rate_compounded(self):

        rate = 0.05
        counter = self.day_counter
        compounding = Compounded
        frequency = Monthly

        interest_rate = InterestRate(rate, counter, compounding, frequency)

        self.assertAlmostEqual(interest_rate.rate, rate)
        self.assertEqual(interest_rate.compounding, compounding)
        self.assertEqual(interest_rate.frequency, Monthly)
示例#6
0
    def test_create_interest_rate_frequency_makes_no_sense(self):

        rate = 0.05
        counter = self.day_counter
        compounding = Continuous
        frequency = Monthly

        interest_rate = InterestRate(rate, counter, compounding, frequency)

        self.assertAlmostEqual(interest_rate.rate, rate)
        self.assertEqual(interest_rate.compounding, compounding)

        # Returns NoFrequency when it does not make sense
        self.assertEqual(interest_rate.frequency, NoFrequency)

        # Broken check. DayCoonter != Actual360
        self.assertEqual(interest_rate.day_counter, Actual360())