How to compute the present value of an annuity in Python

1 min

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.