Python for Financial Mathematics

Compound Amount using Monthly Compounding


I live in Lagos, Nigeria the poverty capital of the world.

This year, I decided to study Financial Mathematics.

I am an Engineer with a BSc in Systems Engineering from the University of Lagos.

My decision to study Financial Mathematics stems from the knowledge that to solve a problem, I must thoroughly understand it.

Programming with Python

Whilst reading the book An Undergraduate Introduction to Financial Mathematics I realized that the formulas where jumping over my head.

Besides, its been a long time since I have done any Mathematics.

So I decided to write the compounding formula as a program. You can find the program below:

# Print out the purpose of the program
print("This program computes the compound amount using monthly compounding")
print("Reference: An Undergraduate Introduction to Financial Mathematics (Page 3)\n")

# Ask the user for the principal amount
principal = float(input("Please enter the principal amount: "))

# Ask the user for the rate as a percentage
rate = float(input("Please enter the rate: "))

# Ask the user for the number of years as a decimal value
years = float(input("Please enter the number of years as a decimal value: "))

# Compute the compound amount (Page 3)
r_n = rate / (12 * 100)
nt = years * 12
factor = (1 + r_n) ** nt
compound_amount = principal * factor
print("\nThe compound amount is:", round(compound_amount, 2))

In doing so, I have a ready made program that I can use to solve the exercises in the book without having to use a calculator.


The essence of code is to replace human rigour and tedium.

In creating this program, I had to study the formula and come up with my own program.

Now I understand the formula.

You can also find it on GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *