How Long Until It Doubles?

growth rate · compound annual growth rate · rule of 70 · logarithms

values holds an island's real GDP x_0, x_1, \dots, x_n at the end of years 0, 1, ..., n (in millions of crowns). Compute four things, with rates as fractions (0.05 means 5 %):

  1. Year-on-year growth for each year t = 1, \dots, n: g_t = x_t / x_{t-1} - 1.
  2. The compound annual growth rate (CAGR) g: the one constant rate that would take x_0 to x_n in n years (formula below).
  3. The rule of 70, a mental shortcut for the doubling time in years: 70 divided by the growth rate in percent, that is 70 / (100\,g).
  4. The exact doubling time T at the constant rate g, which solves (1 + g)^T = 2 (formula below).
g = \left(\frac{x_n}{x_0}\right)^{1/n} - 1 \qquad\qquad T = \frac{\ln 2}{\ln(1 + g)}

An economy that is not growing never doubles: if g \le 0, both doubling times are None.

Write growth_report(values) that returns the tuple (yearly, cagr, rule70, exact), where yearly is the list of the n year-on-year rates.

Examples

Input:  values = [400, 420, 441, 463.05]
Output: ([0.05, 0.05, 0.05], 0.05, 14.0, 14.206699082890461)
Explanation: 5 % a year; the shortcut says 70 / 5 = 14 years, the exact answer is 14.2.

Input:  values = [100, 150, 120]
Output: ([0.5, -0.2], 0.09544511501033215, 7.334057902536169, 7.603568033847866)
Explanation: +50 % then -20 % average 15 % a year, but the economy only grew by a
factor of 1.2 in two years, and 1.0954 ** 2 is about 1.2, so the CAGR is about 9.5 %.

Input:  values = [80, 80]
Output: ([0.0], 0.0, None, None)

Constraints

  • floats are compared with a tolerance of 1e-6

Goals

  • Compute year-on-year growth rates from a series
  • Compute the compound annual growth rate over the whole period
  • Compare the rule-of-70 shortcut with the exact doubling time
Starting Python…