Calculating monthly repayment instalment for a loan using Python and numpy

The pmt() function in numpy computes the monthly repayment amount for a given loan. The returned amount includes both principal and interest components. The Python example uses pmt() for calculating repayment for a 20 years loan, with an annual interest rate of 8.35 percent.

NumPy Updated 20 Mar 2019 1 min read

Overview

  • The pmt() function in numpy calculates the monthly payment required for repaying a loan taken.
  • The repayment amount returned by the numpy.pmt() function is a sum consisting of both principal and interest parts.

Example

python
import numpy as np

interestRate        = 0.0835;

numberOfMonths      = 240;

principalBorrowed   = 2000000;

monthlyPayment      = np.pmt(interestRate/12, numberOfMonths, principalBorrowed);

print("Principal Borrowed:%7.2f"%principalBorrowed);

print("Annual Interest Rate:%5.2f"%(interestRate*100));

print("Loan tenure in number of years:%d"%int(numberOfMonths/12));

print("Monthly Repayment to be made:%5.2f"%abs(monthlyPayment));

Output

Output
Principal Borrowed:2000000.00

Annual Interest Rate: 8.35

Loan tenure in number of years:20

Monthly Repayment to be made:17167.06