On Compounding

Adrian Davila ·

This is a template post. Copy this file, change the frontmatter, and write. Everything below exists to show what a post can contain: prose, math, footnotes, code, figures, and components.

The formula

Suppose you invest a principal PP at an annual rate rr, compounded nn times per year. After one period the balance is P(1+r/n)P(1 + r/n). After tt years — that is, ntnt periods — it is

A=P(1+rn)nt.A = P\left(1 + \frac{r}{n}\right)^{nt}.

As n→∞n \to \infty this approaches continuous compounding,1

lim⁡n→∞P(1+rn)nt=Pert.\lim_{n \to \infty} P\left(1 + \frac{r}{n}\right)^{nt} = Pe^{rt}.

Adding contributions

Most people don’t invest once; they contribute a fixed amount CC every period. Each contribution compounds for a different length of time, so the total is a geometric series:

A=P(1+i)N+C (1+i)N−1i,i=rn,  N=nt.A = P(1+i)^{N} + C\,\frac{(1+i)^{N} - 1}{i}, \qquad i = \frac{r}{n},\; N = nt.

Code

Code blocks are highlighted at build time:

function futureValue(P: number, C: number, r: number, n: number, t: number) {
  const i = r / n;
  const N = n * t;
  const growth = (1 + i) ** N;
  return P * growth + (i === 0 ? C * N : (C * (growth - 1)) / i);
}

Figures

Figure 1. Put images in public/ (or next to the post) and reference them here.

Quotes

Compound interest is the eighth wonder of the world.

— attributed to many people, verified for none.

Footnotes

  1. This is the limit that defines ee: lim⁡n→∞(1+1/n)n=e\lim_{n\to\infty}(1 + 1/n)^n = e. ↩