numpy_financial.pmt() in Python (original) (raw)

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:

Understanding the Formula

The numpy_financial.pmt() function solves the following equation for the payment (pmt):

[Tex]f v + p v \times (1 + rate)^{nper} + pmt \times \frac{(1 + rate \times when)}{rate} \times \left( (1 + rate)^{nper} – 1 \right) = 0[/Tex]

Syntax

numpy_financial.pmt(rate, nper, pv, fv=0, when=’end’)

Parameters

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:

**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:

When to Use numpy_financial.pmt()