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
Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam
3 min read
Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Input and Output in Python Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is
8 min read