def test_pmt(self): """ Test nper using values from excel conversions spreadsheet. """ # 12% is 1% per month (0.01) test_data = [ ({"rate": 0.01, "nperiods": 1, "pv": -100, "fv": 0, "pmt_type": 1}, 100.0), ({"rate": 0.01, "nperiods": 1, "pv": -100, "fv": 0, "pmt_type": 0}, 101.0), ({"rate": 0.02, "nperiods": 12, "pv": -12000, "fv": 0, "pmt_type": 0}, 1134.71515948), ({"rate": 0.0, "nperiods": 10, "pv": 0, "fv": 10000, "pmt_type": 1}, -1000.0), ({"rate": 0.01, "nperiods": 10, "pv": 0, "fv": 10000, "pmt_type": 1}, -946.35719358), ] for (params, desired) in test_data: actual = pmt(**params) self.assertAlmostEqual(actual, desired)
def calculate_monthly_payment(self): if self.qualified > 0: monthly_payment = pmt(self.rate / 12.0, self.monthly_term, -self.loan_amount) self.monthly_payment = Decimal(monthly_payment).quantize(Decimal('0.01'))