How to compute the present value of an annuity in Python

1 min readFinanceDataFrameData Science
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

What is an annuity?

An annuity is a series of payments made at equal intervals.

In the real world, for example, it can be understood as regular deposits to a savings account.

As you can find on Wikipedia here is the ordinary annuity formula:

Where

  • PV: The present value of an ordinary annuity
  • PMT: Value of each payment
  • r: interest rate per period
  • n: number of periods

And in Python?

If we literally transpose this formula in Python.

def compute_annuity_pv(pmt, r, n):
    """Compute the present value of an annuity"""
    return pmt * ((1 - (1/(1+r)**n)) / r)
Here is the formula

If we take an example with

  • PMT = 100$ : Value at each payment
  • r = 7% or 0.07 : interest rate per period here 7% per annum.
  • n = 5 : 5 years
print(compute_annuity_pv(100, 0.07, 5))
# 410.019
Here is how to compute the present value of an annuity

Here you are! You now know how to compute the present value of an annuity.

More on financial analysis

If you want to know more about Financial Analysis in Python and avoid the headaches... check out the other articles I wrote by clicking just here:

Financial Analysis - The Python You Need
We gathered the only Python essentials that you will probably ever need.
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.