Loan calculation using Python module numpy

vegaseat 3 Tallied Votes 4K Views Share

Just another loan calculation, this time using a handy function in Python module numpy.

calculate periodic payments on a given bank loan using module numpy
numpy.pmt(periodic_rate, period_number, loan_value, fv=0, when='end')

module numpy (numeric python extensions, high speed)
download free from:

I used numpy Windows installers

for docs see:

tested with Python27 and Python33  by  vegaseat  22oct2013

import numpy as np

# assume annual interest of 7.5%
interest = 7.5
annual_rate = interest/100.0
monthly_rate = annual_rate/12

# assume payment over 15 years
years = 15
number_month = years * 12

# assume a loan value of $200,000
loan_value = 200000

monthly_payment = abs(np.pmt(monthly_rate, number_month, loan_value))

sf1 = "Paying off a loan of ${:,} over {} years at"
sf2 = "{}% interest, your monthly payment will be ${:,.2f}"
print(sf1.format(loan_value, years))
print(sf2.format(interest, monthly_payment))

''' result ...
Paying off a loan of $200,000 over 15 years at
7.5% interest, your monthly payment will be $1,854.02
HiHe 174 Junior Poster

Numpy is not only fast, but in this case simple to use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.