numpy_financial.pmt() in Python
Last Updated :
19 Mar, 2025
numpy_financial.pmt() function in Python is part of the numpy-financial library and is used for calculating the payment amount required for a loan or an investment, assuming that payments are constant and the interest rate remains unchanged throughout the term. This function is particularly useful for financial calculations involving loans, mortgages, or other types of payments spread over a series of periods.
To use the numpy_financial.pmt() function in Python, you need to install the numpy-financial library, which is an extension of NumPy for financial calculations. You can install the numpy-financial library using pip (Python's package manager):
pip install numpy-financial
Example:
Let’s calculate the monthly payment required for a $10,000 loan over 5 years with an annual interest rate of 6%.
Python
import numpy_financial as npf
# Given values
rate = 0.06 / 12
nper = 12 * 5
pv = 10000
# Calculate monthly payment
payment = npf.pmt(rate, nper, pv)
print(f"Monthly payment: {payment:.2f}")
Output
Monthly payment: -193.33
Explanation:
- rate = 0.06 / 12: Converts the annual interest rate (6%) to a monthly interest rate.
- nper = 12 * 5: Calculates the total number of periods (12 months per year for 5 years).
- pv = 10000: The loan amount is 10,000.
Understanding the Formula
The numpy_financial.pmt() function solves the following equation for the payment (pmt):
f v + p v \times (1 + rate)^{nper} + pmt \times \frac{(1 + rate \times when)}{rate} \times \left( (1 + rate)^{nper} - 1 \right) = 0
Syntax
numpy_financial.pmt(rate, nper, pv, fv=0, when='end')
Parameters
- rate: The interest rate for each period.
- nper: The total number of periods (e.g., months or years).
- pv: The present value (the loan amount or investment).
- fv: The future value, or the desired loan balance after the last payment (default is 0).
- when : Specifies whether the payment is made at the 'end' (default) or 'begin' of each period.
Return Value
The function returns the payment amount for each period.
Example of numpy_financial.pmt()
1. Investment Payment Calculation
Suppose we want to make monthly payments into an account with a future value of $50,000 after 10 years, assuming an annual interest rate of 4%.
Python
import numpy_financial as npf
# Parameters
rate = 0.04 / 12
nper = 10 * 12
fv = 50000
# Calculate the monthly payment
payment = npf.pmt(rate, nper, 0, fv)
print(f"Monthly Payment: ${payment:.2f}")
Output
Monthly Payment: $330.09
Explanation:
- The interest rate is converted to a monthly rate by dividing the annual rate (4%) by 12.
- The number of payments is calculated by multiplying 10 years by 12 months.
- The npf.pmt() function calculates the amount you need to pay monthly to achieve a future value of $50,000.
2. Mortgage Payment Calculation
In this example, we'll calculate the monthly mortgage payment for a house loan. You borrow $250,000 for 30 years at an annual interest rate of 3.5%. We will calculate the monthly payment using numpy_financial.pmt().
Java
import numpy_financial as npf
# Parameters
rate = 0.035 / 12 # Monthly interest rate (annual rate divided by 12)
nper = 30 * 12 # Total number of payments (30 years with monthly payments)
pv = 250000 # Present value (loan amount)
# Calculate the monthly mortgage payment
payment = npf.pmt(rate, nper, pv)
print(f"Monthly Mortgage Payment: ${payment:.2f}")
Output
Monthly Mortgage Payment: $1122.61
Explanation:
- The rate is calculated by dividing the annual interest rate 3.5% by 12 to get the monthly interest rate.
- The nper is calculated by multiplying 30 years by 12 months.
- The npf.pmt() function is used to calculate the monthly payment for the mortgage loan.
When to Use numpy_financial.pmt()
- Loan Payments: When you need to calculate the monthly payment for a loan or mortgage with a fixed interest rate and a fixed term.
- Investment Withdrawals: When calculating how much you can withdraw from an investment at regular intervals (like monthly) to deplete the entire amount by the end of a fixed term.
- Annuities: Useful for calculating annuity payments when the principal amount is withdrawn periodically over a set term.
Similar Reads
numpy.pmt() in Python
numpy.pmt(rate, nper, pv, fv, when = âendâ): This financial function helps user to compute payment value as per the principal and interest. Parameters : rate : [scalar or (M, )array] Rate of interest as decimal (not per cent) per period nper : [scalar or (M, )array] total compounding periods fv : [s
1 min read
numpy.ppmt() in Python
numpy.ppmt(rate, nper, pv, fv, when = âendâ) : This financial function helps user to compute payment value as per the principal value only. Parameters : rate : [scalar or (M, )array] Rate of interest as decimal (not per cent) per period nper : [scalar or (M, )array] total compounding periods fv : [s
2 min read
numpy.pv() in Python
numpy.fv(rate, nper, pmt, fv, when = 'end') : This financial function helps user to compute future values. Parameters : rate : [array_like] Rate of interest as decimal (not per cent) per period nper : [array_like] total compounding periods pmt : [array_like] fixed payment fv : [array_like, optional]
1 min read
numpy.fv() in Python
numpy.fv(rate, nper, pmt, pv, when = 'end') : This financial function helps user to compute future values. Parameters : rate : [scalar or (M, )array] Rate of interest as decimal (not per cent) per period nper : [scalar or (M, )array] total compounding periods pmt : [scalar or (M, )array] fixed payme
1 min read
numpy.i0() function | Python
numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev
1 min read
NumPy Array in Python
NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C
2 min read
numpy.irr() in Python
numpy.irr(values) : This financial function helps user to compute IRR Value i.e. Internal Rate of Return ie. âaverageâ periodically compounded rate of return.  Parameters : values : [array-like] Input cash flows per time period. net âdepositsâ are negative and net âwithdrawalsâ are positiveReturn
1 min read
numpy.finfo() function â Python
numpy.finfo() function shows machine limits for floating point types. Syntax : numpy.finfo(dtype) Parameters : dtype : [float, dtype, or instance] Kind of floating point data-type about which to get information. Return : Machine parameters for floating point types. Code #1 : Python3 # Python program
1 min read
numpy.iinfo() function â Python
numpy.iinfo() function shows machine limits for integer types. Syntax : numpy.iinfo(dtype) Parameters : dtype : [integer type, dtype, or instance] The kind of integer data type to get information about. Return : Machine limits for integer types. Code #1 : Python3 # Python program explaining # numpy.
1 min read
numpy.nper() in Python
numpy.pmt(rate, pmt, pv, fv, when = âendâ) : This financial function helps user to compute number of periodic payments. Parameters : rate : [scalar or (M, )array] Rate of interest as decimal (not per cent) per period pmt : [scalar or (M, )array] Payment value fv : [scalar or (M, )array] Future value
2 min read