1---
2app_version: 0.1.0
3precision: 2
4form_title: Compound Interest Calculator
5form_description: See how compound interest grows your money. Enter initial amount, interest rate, years and monthly contributions to see final value and interest earned.
6form_inputs: Initial amount|principal{€}, Interest rate|rate{%}, Years|years, Monthly deposit|deposit{€}
7form_outputs: Final amount|final, Principal invested|invested, Interest earned|interest, Annual growth|annual_growth
8---
9# Compound Interest Calculator
10// The power of compound interest over time.
11
12# Investment parameters
13principal = 10000 € // initial investment
14rate = 5 % // annual interest rate
15years = 20 // investment period (years)
16deposit = 200 € // monthly additional deposit
17
18# Calculations
19// Monthly interest rate
20monthly_rate = rate / 12
21months = years * 12
22
23// Future value of initial principal
24fv_principal = principal * (1 + monthly_rate)^months
25
26// Future value of monthly deposits (annuity)
27annuity_factor = ((1 + monthly_rate)^months - 1) / monthly_rate
28fv_deposits = deposit * annuity_factor
29
30// Total final amount
31final = fv_principal + fv_deposits
32
33// Total invested (principal + all deposits)
34invested = principal + deposit * months
35
36// Interest earned
37interest = final - invested
38
39// Effective annual rate: 5 % p.a. compounded monthly is a little more than 5 %.
40// (A "CAGR" over the final amount would be wrong here — most of it came from
41// the monthly deposits, not from growth on the initial principal.)
42annual_growth = ((1 + monthly_rate)^12 - 1) * 100
43
44// What if no additional deposits?
45final_no_deposits = principal * (1 + monthly_rate)^months
46
47// What if deposits but no principal?
48final_deposits_only = deposit * annuity_factor
49
50// Rule of 72: years to double at this rate
51years_to_double = 72 / (rate * 100)
52
53# Results
54"Initial investment": principal
55"Monthly deposit": deposit
56"Interest rate (%)": rate * 100
57"Investment period": years
58
59"Final amount": final
60"Total invested": invested
61"Interest earned": interest
62
63"Effective annual rate (%)": annual_growth
64"Years to double at this rate": years_to_double
65
66"Without deposits": final_no_deposits
67"Deposits only": final_deposits_only
68
69// Growth visualization
70growth(year) = (principal * (1 + monthly_rate)^(year * 12)) + (deposit * (((1 + monthly_rate)^(year * 12) - 1) / monthly_rate))
71plot(growth(x), 0..years, "Investment growth", "Years", "€", "Value over time")
72