Compound Interest Calculator
Calculate future value with compound interest. Interest earned on both principal and accumulated interest. Einstein called it 'the eighth wonder of the world'. Foundation of investing and loans.
Visualization
Interactive visualization for Compound Interest Calculator
Interactive visualization with step-by-step execution
Implementation
1class CompoundInterest {
2 calculate(
3 principal: number,
4 rate: number,
5 time: number,
6 frequency: number = 1
7 ): number {
8 return principal * Math.pow(1 + rate / frequency, frequency * time);
9 }
10
11 calculateContinuous(principal: number, rate: number, time: number): number {
12 return principal * Math.exp(rate * time);
13 }
14
15 interestEarned(
16 principal: number,
17 rate: number,
18 time: number,
19 frequency: number = 1
20 ): number {
21 return this.calculate(principal, rate, time, frequency) - principal;
22 }
23
24 yearsToDouble(rate: number): number {
25 // Rule of 72 approximation
26 return 72 / (rate * 100);
27 }
28
29 effectiveAnnualRate(nominalRate: number, frequency: number): number {
30 return Math.pow(1 + nominalRate / frequency, frequency) - 1;
31 }
32
33 futureValueSeries(
34 payment: number,
35 rate: number,
36 periods: number
37 ): number {
38 // Future value of annuity
39 return payment * ((Math.pow(1 + rate, periods) - 1) / rate);
40 }
41
42 presentValue(futureValue: number, rate: number, periods: number): number {
43 return futureValue / Math.pow(1 + rate, periods);
44 }
45}Deep Dive
Theoretical Foundation
Formula: A = P(1 + r/n)^(nt) where P=principal, r=rate, n=compounds per year, t=years. Continuous: A = Pe^(rt). More frequent compounding = higher returns. Rule of 72: years to double ≈ 72/rate%.
Complexity
Time
O(1)
O(1)
O(1)
Space
O(1)
Applications
Industry Use
Retirement savings planning (401k, IRA)
Certificate of deposit (CD) calculations
Savings account growth projections
Bond investment analysis
Loan interest calculations
Education savings plans (529 plans)
Life insurance cash value growth
Investment portfolio projections
Use Cases
Related Algorithms
GCD (Euclidean Algorithm)
Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Dating back to around 300 BC and appearing in Euclid's Elements, it's one of the oldest algorithms still in common use. The algorithm is based on the principle that GCD(a,b) = GCD(b, a mod b) and is remarkably efficient with O(log min(a,b)) time complexity. The GCD is the largest positive integer that divides both numbers without remainder.
LCM (Least Common Multiple)
Calculate the Least Common Multiple (LCM) of two integers - the smallest positive integer that is divisible by both numbers. The LCM is intimately related to the GCD through the formula: LCM(a,b) = |a×b| / GCD(a,b). This relationship allows us to compute LCM efficiently using the Euclidean algorithm for GCD, achieving O(log min(a,b)) time complexity instead of naive factorization methods.
Sieve of Eratosthenes
Ancient and highly efficient algorithm to find all prime numbers up to a given limit n. Invented by Greek mathematician Eratosthenes of Cyrene (276-194 BC), this sieve method systematically eliminates multiples of primes, leaving only primes in the array. With O(n log log n) time complexity, it remains one of the most practical algorithms for generating large lists of primes, vastly superior to trial division which runs in O(n² / log n) time.
Prime Factorization
Decompose a positive integer into its unique prime factor representation. Every integer greater than 1 can be expressed as a product of prime numbers in exactly one way (Fundamental Theorem of Arithmetic). This algorithm uses trial division optimized to check only up to √n, as any composite number must have a prime factor ≤ √n. Returns a map of prime factors to their powers, e.g., 360 = 2³ × 3² × 5¹.