示例#1
0
    def test__calculate_principal_schedule(self):
        loan = Mortgage()
        loan.principal = 200e3
        loan.tenor = 30
        loan.loan_periods = np.arange(30 * 12) + 1

        loan.rate = 0
        loan._calculate_principal_schedule()
        expected = [200000 / 30 / 12] * 30 * 12
        self.assertEquals(loan.principal_schedule, expected)

        loan.rate = 6.5 / 100
        loan._calculate_principal_schedule()
        # Assert size, first element, last element, and sum
        self.assertEquals(len(loan.principal_schedule), 30 * 12)
        self.assertAlmostEquals(loan.principal_schedule[0], 180.80, places=2)
        self.assertAlmostEquals(loan.principal_schedule[-1], 1257.33, places=2)
        self.assertAlmostEquals(sum(loan.principal_schedule), 200e3, places=2)
示例#2
0
    def test__calculate_interest_schedule(self):
        loan = Mortgage()
        loan.principal = 200e3
        loan.tenor = 30
        loan.loan_periods = np.arange(30 * 12) + 1

        loan.rate = 0
        loan._calculate_interest_schedule()
        expected = [0] * 30 * 12
        np.testing.assert_array_equal(loan.interest_schedule, expected)

        loan.rate = 6.5 / 100
        loan._calculate_interest_schedule()

        # Assert size, first element, last element, and sum
        self.assertEquals(len(loan.interest_schedule), 30 * 12)
        self.assertAlmostEquals(loan.interest_schedule[0], 1083.33, places=2)
        self.assertAlmostEquals(loan.interest_schedule[-1], 6.81, places=2)
        self.assertAlmostEquals(sum(loan.interest_schedule),
                                255088.98,
                                places=2)