When evaluating the multi-year performance of an investment portfolio or a economic metric, a common error is averaging annual return percentages with a simple arithmetic mean. If an asset rises $+50\%$ in Year 1 and falls $-50\%$ in Year 2, the arithmetic mean is $0\%$, yet $1,000$ USD initial capital becomes $1,500$ USD and then drops to $750$ USD — a real loss of $-25\%$.
The Definition of CAGR
The Compound Annual Growth Rate (CAGR) is the constant geometric rate $g$ required for a starting value $V_i > 0$ to reach a final value $V_f > 0$ over $n > 0$ periods:
g = (Vf / Vi) ** (1 / n) - 1
Mathematically, $1 + g$ is the geometric mean of the annual growth factors $(1 + r_1), (1 + r_2), \dots, (1 + r_n)$. By the AM-GM inequality, the geometric mean of non-equal positive values is strictly less than their arithmetic mean. The difference between arithmetic average and CAGR is often called the volatility drag, approximately equal to $\frac{1}{2}\sigma^2$ for small return variances.
Worked Example Over 4 Years
Consider an asset growing from $10,000$ USD to $14,641$ USD over $n = 4$ years:
| Year | End Value | Annual Return |
|---|---|---|
| 0 | $10,000.00 | — |
| 1 | $13,000.00 | +30.00% |
| 2 | $11,700.00 | -10.00% |
| 3 | $14,625.00 | +25.00% |
| 4 | $14,641.00 | +0.11% |
The arithmetic average of returns is $(30 - 10 + 25 + 0.11) / 4 \approx 11.28\%$. But the true CAGR is:
(14641 / 10000) ** (1 / 4) - 1 = 10.00%
Code Edge Cases to Guard Against
- Zero Initial Value ($V_i = 0$): Division by zero. Compound growth cannot be computed relative to zero.
- Negative Final Value ($V_f < 0$): Taking a fractional power $1/n$ of a negative ratio yields
NaNor complex numbers. - Partial-Year Periods ($n$ in days or months): Normalize $n = \text{days} / 365.25$ rather than assuming integer years.
import math def calculate_cagr(v_initial: float, v_final: float, years: float) -> float: if years <= 0: raise ValueError("Years must be positive.") if v_initial <= 0 or v_final < 0: raise ValueError("Initial value must be > 0 and final value >= 0.") if v_final == 0: return -1.0 return math.expm1(math.log(v_final / v_initial) / years)
Using math.expm1(math.log(v_final / v_initial) / years) preserves floating-point precision when growth rate $g$ is close to zero.
Verification and Simulation
To test custom compounding horizons and view period-by-period growth tables, check the CAGR calculator at Miryori.
Disclosure: The author leads content at Miryori, the free online calculator suite linked above. Educational math only, not financial advice.