Contents
30 Apr 2025 • 21:11
Image by Barry A on Unsplash
Compound interest is often described as the “eighth wonder of the world” — and for good reason.
Unlike simple interest, compound interest grows your wealth by reinvesting gains, creating a powerful snowball effect over time.
This article revisits the core idea of compound interest, explores key formulas, and simulates different investing scenarios using Python to show just how big the impact can be.
Compound interest means you earn interest not only on your initial investment but also on the interest you've already earned.
The standard compound interest formula is:
A = P × (1 + r ÷ n) ^ (n × t)
Where:
A
: Final amount
P
: Initial principal
r
: Annual interest rate (in decimal)
n
: Number of times interest is compounded per year
t
: Time in years
As always, you can access the code in this guide on this GitHub Repository.
We’ll simulate and compare:
Compound interest over time.
Different compounding frequencies.
The effect of time vs. interest rate.
pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('dark_background')
# Formula
def compound_interest(P, r, n, t):
return P * (1 + r/n)**(n*t)
How much does $1,000 grow over 30 years at a 7% annual return, compounded monthly?
A
= the amount of money after time t
P=1000
= the initial investment
r=0.07
= annual interest rate (7%)
n=12
= number of compounding periods per year (monthly)
t=30
= number of years
Substituting the values:
A = 1000 × (1 + 0.07 ÷ 12) ^ (12 × 30)
= 1000 × (1 + 0.005833...) ^ 360
≈ 1000 × 8.1165
= 8116.50
# Parameters
P = 1000 # Initial investment
r = 0.07 # Annual interest rate (7%)
n = 12 # Compounded monthly
years = np.arange(0, 31) # From 0 to 30 years
# Calculate compound interest over time
amounts = [compound_interest(P, r, n, t) for t in years]
# Print final amount at year 30
final_amount = amounts[-1]
print(f"After {years[-1]} years, your investment grows from ${P} to ${final_amount:,.2f}.")
# Plotting
plt.figure(figsize=(12, 6))
plt.plot(years, amounts, label='7% Annual Return', color='dodgerblue')
plt.xlabel("Years")
plt.ylabel("Amount ($)")
plt.title("Compound Interest Over 30 Years (Monthly Compounding)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig("compound_interest.png", dpi=300)
plt.show()
Insight: You start with $1,000
By year 30, you have $8,116.50 — without adding a cent.
What if your return rate changes? Let’s compare:
rates = [0.03, 0.05, 0.07, 0.10]
# Create 12x6 inch figure
plt.figure(figsize=(12, 6))
# Plot and print final amounts for each rate
for rate in rates:
values = [compound_interest(P, rate, n, t) for t in years]
final_amount = values[-1]
print(f"After {years[-1]} years at {int(rate*100)}% annual return, the investment grows to ${final_amount:,.2f}.")
plt.plot(years, values, label=f"{int(rate * 100)}% Return")
# Labels and legend
plt.title("Compound Interest at Different Rates")
plt.xlabel("Years")
plt.ylabel("Amount ($)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig("compound_interest_rates.png", dpi=300)
plt.show()
Insight: The difference between 5% and 10% may seem small at first — but over time, the 10% curve explodes upward.
Annual Return | Amount ($) |
---|---|
3% | 2,456.84 |
5% | 4,467.74 |
7% | 8,116.50 |
10% | 19,837.40 |
Now let’s compare two people:
Alice starts investing early: $1,000 at 7% for 30 years.
Bob starts 10 years later but invests for 20 years at the same rate.
# Alice starts investing immediately
alice = [compound_interest(1000, 0.07, 12, t) for t in years]
# Bob starts investing 10 years later
bob = [compound_interest(1000, 0.07, 12, t - 10) if t >= 10 else 0 for t in years]
# Final values
alice_final = alice[-1]
bob_final = bob[-1]
print(f"Alice's investment after 30 years: ${alice_final:,.2f}")
print(f"Bob's investment after 30 years (starting 10 years late): ${bob_final:,.2f}")
print(f"Difference: ${alice_final - bob_final:,.2f}")
# Plot
plt.figure(figsize=(12, 6))
plt.plot(years, alice, label="Alice (Starts Year 0)")
plt.plot(years, bob, label="Bob (Starts Year 10)", linestyle='--')
plt.title("Starting Early Beats Starting Late")
plt.xlabel("Years")
plt.ylabel("Amount ($)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig("early_vs_late.png", dpi=300)
plt.show()
Insight: Alice didn’t invest more — she just started earlier. Time is your most powerful investing ally.
Investor | Amount ($) |
---|---|
Alice | 8,116.50 |
Bob | 4,038.74 |
Difference | 4,077.76 |
Principle | Why It Matters |
---|---|
Start Early | Time is more powerful than the amount invested |
Higher Returns Compound Faster | A small % increase makes a big difference over time |
Compound Often | Monthly > Annually compounding |