🛠️ToolsShed

Compound Interest Calculator

Calculate compound interest growth for investments over time.

Compound Interest Calculator shows how an investment or savings account grows over time when interest is earned not just on the principal but also on the accumulated interest from previous periods. Albert Einstein reportedly called compound interest the eighth wonder of the world — small differences in rate or time can result in dramatically different outcomes over long periods.

Enter your principal amount, annual interest rate, compounding frequency (daily, monthly, quarterly, or annually), and the number of years. The calculator shows the final balance, total interest earned, and a year-by-year breakdown so you can see exactly how growth accelerates over time.

Understanding compound interest is essential for retirement planning, evaluating savings accounts, comparing loan costs, and making informed investment decisions. The key insight is that starting early and reinvesting returns can produce significantly more wealth than a higher rate started later.

Frequently Asked Questions

Code Implementation

def compound_interest(principal, annual_rate, years, n=12, contribution=0):
    """
    Calculate compound interest with optional regular contributions.

    Parameters:
        principal    - initial investment
        annual_rate  - annual interest rate (e.g. 0.07 for 7%)
        years        - investment duration in years
        n            - compounding frequency per year (12 = monthly)
        contribution - periodic contribution (same frequency as n)

    Returns dict with final balance, total invested, and total interest.
    """
    r = annual_rate / n
    periods = int(years * n)
    balance = principal
    for _ in range(periods):
        balance = balance * (1 + r) + contribution
    total_invested = principal + contribution * periods
    return {
        "final_balance":  balance,
        "total_invested": total_invested,
        "total_interest": balance - total_invested,
    }

def rule_of_72(annual_rate):
    """Estimate years to double at a given annual rate."""
    return 72 / (annual_rate * 100)

# Simple formula (no contributions)
def compound_formula(P, r, n, t):
    """A = P(1 + r/n)^(nt)"""
    return P * (1 + r / n) ** (n * t)

# Examples
result = compound_interest(10000, 0.07, 20, n=12, contribution=500)
print(f"Final balance:   ${result['final_balance']:,.2f}")
print(f"Total invested:  ${result['total_invested']:,.2f}")
print(f"Total interest:  ${result['total_interest']:,.2f}")
print(f"Years to double: {rule_of_72(0.07):.1f} years at 7%")

# Compounding frequency comparison
for label, n in [("Annual", 1), ("Monthly", 12), ("Daily", 365)]:
    A = compound_formula(10000, 0.12, n, 10)
    print(f"{label:8}: ${A:,.2f}  (EAR = {((1 + 0.12/n)**n - 1)*100:.4f}%)")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.