Ever heard of the Rule of 72? It’s a classic finance shortcut that tells you how many years it takes for an investment to double at a given interest rate—without reaching for a calculator! Pretty much, if you want to understand when you are going to double your money, that are growing with 7% per year, then simply divide 72 by 7 and see the approximate answer. It works like that and it is approximately ok, for values between 5 and 10%.
For all other values, the formula looks like this:
With Python the formula looks like this:
1 2 3 4 5 |
import math def exact_doubling_time(rate_percent): rate_decimal = rate_percent / 100.0 return math.log(2)/math.log(1+rate_decimal) |
If you want to see how exact the formula is, then a good comparison vs the exact value looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
def rule_of_72(rate_percent): return 72 / rate_percent def rule_of_70(rate_percent): return 70 / rate_percent def rule_of_69(rate_percent): return 69 / rate_percent rate_ex = 8 approx_72 = rule_of_72(rate_ex) approx_70 = rule_of_70(rate_ex) approx_69 = rule_of_69(rate_ex) exact_val = exact_doubling_time(rate_ex) print(f"Interest Rate: {rate_ex}%") print(f"Rule of 72: {approx_72:.2f} years") print(f"Rule of 70: {approx_70:.2f} years") print(f"Rule of 69: {approx_69:.2f} years") print(f"Exact: {exact_val:.3f} years") for r_percent in [1, 2, 5, 8, 10, 20]: exact_t = exact_doubling_time(r_percent) t72 = rule_of_72(r_percent) print(f"Rate: {r_percent}%\n" f" Exact = {exact_t:.3f} | Rule 72 = {t72:.3f} | Error = {100*(t72 - exact_t)/exact_t:.2f}%\n") |
The execution of the code from above like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Interest Rate: 8% Rule of 72: 9.00 years Rule of 70: 8.75 years Rule of 69: 8.62 years Exact: 9.006 years Rate: 1% Exact = 69.661 | Rule 72 = 72.000 | Error = 3.36% Rate: 2% Exact = 35.003 | Rule 72 = 36.000 | Error = 2.85% Rate: 5% Exact = 14.207 | Rule 72 = 14.400 | Error = 1.36% Rate: 8% Exact = 9.006 | Rule 72 = 9.000 | Error = -0.07% Rate: 10% Exact = 7.273 | Rule 72 = 7.200 | Error = -1.00% Rate: 20% Exact = 3.802 | Rule 72 = 3.600 | Error = -5.31% |
The YT video, explaining the code and is here:
The GitHub code is here: https://github.com/Vitosh/Python_personal/tree/master/YouTube/023_Python-Rule-of-72
Enjoy!