How to Calculate the Present Value using Python

You can use the following template to calculate the Present Value using Python:

FV = Future Value
r = Interest Rate
n = Number of Periods

PV = FV/(1+r/100)**n
print (PV)

In the next section, I’ll review an example with the steps to calculate the present value. I’ll also share with you the code to create the following tool to derive the present value:

How to Calculate the Present Value using Python

Steps to Calculate the Present Value using Python

Step 1: Gather your Data

To start, you’ll need to gather the data for the Present Value calculation.

For example, let’s say that you collected the following data:

  • Future Value (FV) = 1000
  • Interest Rate (r) = 4%
  • Number of Periods (n) = 7

Step 2: Calculate the Present Value

Next, you can use the template below in order to calculate the Present Value in Python:

FV = Future Value
r = Interest Rate
n = Number of Periods

PV = FV/(1+r/100)**n
print (PV)

This is the complete Python code that you may use for our example:

FV = 1000
r = 4
n = 7

PV = FV/(1+r/100)**n
print (PV)

Run the code in Python and you’ll get the PV of 759.917.

Tool to Calculate the Present Value

Here is the full Python code to create a tool that can be used for the Present Value calculations (this tool is based on the tkinter package):

import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 470, height = 480)
canvas1.pack()

label1 = tk.Label(root, text='Calculate Present Value')
label1.config(font=('helvetica', 14))
canvas1.create_window(235, 40, window=label1)

entry1 = tk.Entry (root) 
canvas1.create_window(330, 100, window=entry1)

entry2 = tk.Entry (root) 
canvas1.create_window(330, 140, window=entry2)

entry3 = tk.Entry (root) 
canvas1.create_window(330, 180, window=entry3)

entry4 = tk.Entry (root) 
canvas1.create_window(240, 380, window=entry4)

label1 = tk.Label(root, text='   Future Value (FV):')
label1.config(font=('helvetica', 10))
canvas1.create_window(160, 100, window=label1)

label2 = tk.Label(root, text='Interest Rate (r):')
label2.config(font=('helvetica', 10))
canvas1.create_window(160, 140, window=label2)

label3 = tk.Label(root, text='         Number of Periods (n):')
label3.config(font=('helvetica', 10))
canvas1.create_window(160, 180, window=label3)


def calcPV ():  
    FV = float(entry1.get())
    r = float(entry2.get())
    n = float(entry3.get())

    PV = FV/(1+r/100)**n
    
    label4 = tk.Label(root, text= PV,font=('helvetica', 10, 'bold'),bg='white')
    canvas1.create_window(240, 380, window=label4)

button1 = tk.Button(text='Calculate Present Value', command=calcPV, bg='green', fg='white', font=('helvetica', 9, 'bold'))
canvas1.create_window(240, 330, window=button1)

root.mainloop()

Run the Python code and you’ll see the following display:

How to Calculate the Present Value using Python

Let’s say that your goal is to derive the Present Value given the information below:

  • Future Value (FV) = 1000
  • Interest Rate (r) = 4%
  • Number of Periods (n) = 7

In that case, type the above parameters in the entry boxes as follows:

Derive the Present Value

Finally, click on the ‘Calculate Present Value’ button and you’ll get the value of 759.917:

Python program