How to Calculate Compound Interest
One of the most powerful tools available to those able to participate in our free economy is the ability to take advantage of Compound Interest. The average retiree depends on it to make ends meet after their working years and some investing gurus such as Warren Buffet have turned simple ingenuity into tens of Billions of dollars.
In this article I will cover exactly what Compound Interest is and how to calculate it.
I will give you compound interest formulae, examples and even Python code to create your own compound interest calculator. I will show you how calculating compound growth differs with varying time horizons such as compounding daily vs compounding monthly and yearly.
Below are the topics we will cover in this article starting with simple interest.
Calculating Compound Interest Topics
What is Simple Interest?
Simple interest is a way of calculating interest that does not compound over time. The amount of interest is calculated only once. It uses an interest rate at the beginning but the amount of total interest either earned or charged does not change for each period.
Simple interest is the type of interest you typically see on car loans.
Simple interest is calculated purely off the original starting principal. Compound Interest, as we will find out shortly, is calculated on a rolling basis depending on the time period selected.
How is Simple Interest Calculated?
Simple interest is calculated at the beginning of repayment or earning period. Since all datapoints are known at the outset, it can be calculated with a formula very quickly.
Simple Interest Formula
The formula for simple interest requires knowing the following 3 pieces of information:
- The Principal (p) – The Principal is the starting loan or capital for which the interest will be calculated.
- The Interest Rate (r) – The Rate of Interest Charged at an annual rate expressed as a percentage.
- The Number of Years (y) – Typically loans and investment periods are measured in years. Other time lengths can be used as long as the interest rate (r) is adjusted accordingly.
The formula is as follows:
Simple Interest = p * y * (r / 100)
What is Compound Interest?
Compound Interest is when interest is recalculated for each selected period. In essence compound interest allows you to earn interest on your principal and interest.
Over time, compounding returns implies that the total value of such an account could increase drastically.
Investing in the Stock Market is a great way to leverage the power of compounding returns. Alternatively, using credit cards is a great way to be a victim of compounding. With credit cards, your account is charged interest for a previous month’s balance including any previous interest accrued but left unpaid.
Compound Interest Meaning
The term ‘Compound’ is derived from the fact that the effect of interest on the principal is calculated multiple times resulting in a different, usually larger, result each time. As seen above, simple interest is a one-time calculation.
A rate is multiplied by the number of periods and then by the principal.
Compound interest multiplies the interest by the remaining previous period’s balance. Each period’s interest is a result of the multiplication of the previous period’s principal & interest. Thus, the results are compounded.
Compound Interest Formula
Where simple interest required 3 pieces of information (the principal, interest rate, and number of periods) the compound interest formula requires a 4th term. This additional term is ‘n’ or the number of times compounded per year (y).
Here is the formula for compound interest generally used for investing.
results = p * (1 + r/n)n * y
By toggling the value for n, we can modify the formula to compound daily, monthly or even yearly.
Daily Compounded Interest
Daily compound interest is often used when trying to calculate credit card fees. Usually, the interest charged to a consumer is based off the daily balance being held. In this case, the daily formula should be used to determine the ending account balance.
Daily Compound Interest Formula
The daily compound interest rate formula is simply a modification of the original formula. With the exception of leap year, there are 365 days in a year. Thus, 365 is simply used for the variable n.
The Daily Compound Interest Formula is:
results = p * (1 + r/365)365y
Daily Compound Interest Example
As an example, let’s assume we have a credit card that charges us a rate of 20% per year compounded daily. Our initial account balance is $1,000. If we don’t add any more to the balance by making purchases or pay down the balance here is how our variables would be defined:
results = 1000 * (1 + 0.20/365)^(365*1) = 1000 * (1.000548)^365 = 1000 * 1.22133 = $1,221.33
Daily Compound Interest Calculator in Python
Around the web there are a number of valid compound interest calculators, however doing it yourself is the best way to ensure that you both understand the concept and are getting an accurate result. Using Python to generate the results is a quick and easy way to do this.
Below is a code snippet that can be used in any python environment to quickly recreate our formula from above.
# Set our variables
p = 1000
r = 0.20
y = 1
# Calculate the interest and store it in a variable
interestCalculator = p * (1 + r / 365)**(365 * y)
# Print out the results of our Daily Compound Interest Formula
print("The total final amount when compounded daily is: $", round(interestCalculator, 2))
The total final amount when compounded daily is: $ 1221.34
Monthly Compounded Interest
Interest compounded monthly is more appropriate for those with loans or investments that compound approximately monthly. Although the use cases are less than for daily and yearly compounded, it may make sense given specific set conditions.
Monthly Compound Interest Formula
As with the daily formula, the monthly formula will use the original compound interest formula and tweak the number of compounding periods to 12.
The Monthly Compound Interest Formula is:
results = p * (1 + r/12)12y
Monthly Compound Interest Example
To give a relevant example, let’s assume that you have purchased an investment instrument that compounds monthly. Your starting investment is $10,000. The rate of return is 12%. The instrument is expected to fully mature after 5 years. Knowing this information, we can calculate the final balance after interest has accumulated at the end of the term.
First, let’s rehash what our starting variables would be:
p = 10,000
r = 0.12
y = 5
results = 10000 * (1 + 0.12/12)(12*5)
= 10000 * (1.01)^60
= 10000 * 1.81669
= $18,166.90
Monthly Compound Interest Calculator in Python
Using Python to once again compute our own results versus relying on an outside calculator can be seen below. These calculations are possible using just the base commands avaialable in any Python environment… no special packages required.
# Set our variables for calculation
p = 10000
r = 0.12
y = 5
# Calculate the interest and store it in a variable
interestCalculator = p * (1 + r / 12)**(12 * y)
# Print out the results of our Monthly Compound Interest Formula
print("The total final amount when compounded monthly is: $", round(interestCalculator, 2))
The total final amount when compounded monthly is: $ 18166.97
Despite some rounding issues of $0.07 we can see that our result from using Python is exactly the same. The power of using this code and Python in general to make more complicated comparisons should not be discounted.
Yearly Compounded Interest
When it comes to trying to forecast possible investment returns over a long period, compounding yearly is an incredibly powerful tool. By making assumptions about possible investment returns we can plug and play various best and worst case scenarios to give us an idea on how we may tweak our savings strategies.
The yearly compound interest formula gives us an ability to reliably generate yard posts for our future retirement and investment expectations.
Yearly Compound Interest Formula
Despite the power this formula can bestow upon those who use it, it is simply just a small tweak away from the other formulae we have used so far. Just like before, tweaking the value for n, the number of compounding periods, we can convert our past work into a yearly form.
In this case the number of times compounded is once per year.
The Yearly Compound Interest Formula is:
results = p * (1 + r)y
Thus, knowing our principal (p), annual interest rate (r), and the number of years of compounding (y) we can fully calculate the final amount of our result.
Yearly Compound Interest Example
Now, as mentioned, yearly compounding is often seen in the wild when trying to forecast investment growth. An appropriate example of yearly compounding will require us to make a few assumptions to set the starting values to our variables.
Over the long term, the total return of the entire U.S. Stock Market has been 12%. Thus, the value for r in our example will be 12%. Also, let’s assume that we start with a principal of $100,000 at the age of 30 and want to see what it could be worth after 30 years when we turn 60.
In this example our variables would be set like the following:
p = 100,000
r = 0.12
y = 30
results = 100000 * (1 + 0.12)(30)
= 100000 * (1.12)^30
= 100000 * 29.9599
= $2,995,992.21
You read that number correctly. If you invest $100,000 for 30 years and earn the Total Return Average of the Stock Market for 30 years you will have approximately $3 Million.
What’s even more striking is that you can see that whatever amount of principal you started with would have been multiplied by 30x. So if you started with $1 you would have about $30 in 30 years.
A good way to put this information to work in your daily life is to assume that every dollar that you spend today that you don’t save for retirement in 30 years you could be losing out on $29. That $5 coffee is making you miss out on $145 during retirement. As you can see, the effect of our decisions today snowball quite drastically over the course of 30 years.
Yearly Compound Interest Calculator in Python
Now to make sure that our calculations for our above example are correct I will execute a Python code block with our equation and initial parameters. Notice how much simpler this formula is when compared to the daily and monthly variation.
# Our initial 3 variables need to be set
p = 100000
r = 0.12
y = 30
# Calculate the final amount and store in a variable
interestCalculator = p * (1 + r)**y
# Print out the results of our Yearly Compound Interest Formula
print("The total final amount when compounded yearly is: $", round(interestCalculator, 2))
The total final amount when compounded yearly is: $ 2995992.21
As expected, our result matches to the penny. Incorporating this code into a plot with various assumptions would be a good way to start a retirement savings plan. Plotting out various starting amounts with different interest rate assumptions could help you bound expectations for your retirement nest egg.
Continuously Compounded Interest
As we have seen so far, interest can be calculated for different time frames. But what if we want to calculate interest using the smallest time frame possible? Would that be an hour, minute or second? What about smaller?
If you take the mathematical limit of the time frame as it approaches 0 you will calculate something called the continuous compound interest.
When it comes to Finance or Personal Finance, the continuous form of interest calculation is not something you really need in your kit bag. The differences between what is calculated on a continuous basis just doesn’t differ very much from a what is calculated on a daily basis.
All that said, we have seen how credit card companies use a daily approach and investment planning uses a yearly approach. There aren’t any real word examples that use a continuous method.
Continuously Compounded Interest Formula
Thankfully, you’ve come to the place where I will spare you the derivation. Suffice it to say it requires a bit of Calculus. The formula for continuously compounded interest is short but does require the use of e.
This is not a variable but in fact something known as ‘Euler’s Number’. e is a constant and can be approximated by the value 2.71828.
results = p * er * t
Continuously Compounded Interest Example
Previously, for the yearly example, we assumed we had a starting principal of $100,000 and a rate of 12%. We wanted to see what the final principal would be if we waited for interest to compound for 30 years.
Given how the continuous formula is set up we know that it will give us a larger number than the yearly formula. Thus we know that using this formula in this way probably doesn’t make sense. For this example let’s switch things up.
Let’s make the assumption we know the final amount to be $2,995,992.21 (the amount output from our yearly example). Let’s also set our period to 30 years and the initial principal to $100,000. The only unknown variable is r.
results = 2,995,992.21
p = 100,000
r = ?
y = 30
results = p * e^(r*t)
results = 100000 * e^(r * 30)
2,995,992.21 / 100,000 = e^(r * 30)
29.96 = e^(r * 30)
ln(29.96) = ln(e^(r * 30))
3.40 = r * 30
r = .113
Compound Interest with Contributions
In all of the cases we have considered so far, we have only been able to compound an initial principal. But what if you are actively contributing to the starting principal over time? This would be analogous to contributing to a 401(k) into the future while also already having some saved up.
This situation calls for the ability to calculate compound interest with contributions. In fact, if you are interested in learning more about how to calculate this in Python I wrote an article that will walk you through all the steps called ‘Calculate Compound Interest with Contributions in Python.’
Compound Interest with Contributions Formula
The formula for including contributions into your compound interest calculation is a bit more complex. This is because the formula will have to essentially iteratively calculate the effect of interest at each and every single point where a contribution is made.
Given that most folks would like to consider using this type of calculation on a monthly basis, the below formula will include a parameter called M, or the amount to be contributed monthly.
results = p * (1 + r/12)12t + M ((1 + r/12)12t-1)/(r/12)
If you look carefully, you will see that if the monthly contribution (M) is set to 0 the formula reduces down to our monthly compound interest formula.
Compound Interest with Contributions Example
For our next example, let’s assume that a future retiree has \$10,000 saved as a starting principal. Over the next 30 years they intend to save $100 per month. Given advice by their financial advisor, they have decided to assume that they can likely earn 10% on average over the long term.
These are how are variables are defined:
p = 10,000
r = 0.10
y = 30
M = 100
results = P(1+r/12)^12t + M((1 + r/12)^12t -1)/(r/12)
= 10000(1 + (.1)/12)^12(30) + 100((1 + .1/12)^12(30) - 1)/(.1/12)
= 10000(1.0083)^(360) + 100((1.0083)^360 -1)/(.0083)
= 10000(19.61) + 100(19.61 - 1)/(.0083)
= 196,100 + 100(18.61)/(.0083)
= 196,100 + 224,216.87
= $420,316.87
Compound Interest with Contributions Calculator in Python
Using Python to crunch these numbers really makes things easy. Especially if you are looking to rerun the numbers based on various assumptions. Below is the code necessary in base Python to quickly calculate compound interest with contributions.
# Our initial 4 variables are set
p = 10000
r = 0.10
y = 30
M = 100
# Calculate the final amount and store in a variable
interestCalculator = p*(1 + r / 12)**(12 * y)+(M)*((1+ r / 12 )**(12 * y)-1)/(r / 12)
# Print out the results of our Yearly Compound Interest Formula
print("The total final amount when compounded yearly with contributions is: $", round(interestCalculator, 2))
The total final amount when compounded yearly with contributions is: $ 424422.79
Note the amount is off by a few thousand. That’s what happens when you use a calculator by hand and round several times prior to using an exponential. Suffice it to say that both are accurate but our Python code gives us the precise answer.
Conclusion
The ability to calculate compounding interest at varying levels of periodicity is a powerful tool that can help you accomplish various things. Compounding on a daily basis will give you a tool to see how credit card debt may grow over time.
Compounding at a monthly or yearly level could give you the ability to evaluate various investing and retirement strategies. Furthermore, by taking the calculations to the next level and implementing them into Python you can quickly analyze various financial situations.
I hope you enjoyed this article. If you have any other thoughts on the topic please feel free to add them in the comments below.
Guy Money
As a formally trained Data Scientist I find excitement in writing about Personal Finance and how to view it through a lens filtered by data. I am excited about helping others build financial moats while at the same time helping to make the world a more livable and friendly place.