# Interest rate

## Finance

Albert Einstein: "Compound interest is the eighth wonder of the world. He who understands it, earns it … he who doesn't … pays it."

### Terminology

A bit of terminology first:

$\color{blue} P - Principal / Price / Present\ value \\ Px - Principal + interest\ after\ 'x'\ years \\ \color{red} r - Annual\ interest\ rate \\ \color{green} t - Years$

### Simple interest rate

Let P be the principal that is borrowed, after first year the balance that needs to be paid back is the principal P plus the interest:

$\\ P1 = P + r*P$

after two years we have the principal plus the interest for 2 years: $\\ P2 = P + r*P + r*P \\$

then after 3 years … $\\ P3 = P + r*P + r*P + r*P \\$

we can see that r*P term repeats for each year, generalize for t years: $\\ Pt = P + t*r*P \\$

and finally extract P and remember the formula for later use: $\color{blue} S = P*(1 + r*t)$

Let's see a simple example, borrow $100 at 12% annual rate for 20 years:  p, r, t = 100, 0.12, 20 s = p * (1 + t*r) print('$%.2f' % s)
$1089.26  #### Daily compounding 365 days in a year and n=365  n = 365 c = p * (1 + r/n)**(t*n) print('$%.2f' % c)
$1101.88  Again,$1101 vs. $1089 vs$964, the more often the compounding, the bigger the final balance.

#### Continuously compounding

What about hourly compounding or even per minute or per millisecond? we can increase n and get the results but I want to find a formula that fits them all starting with: $\color{blue} C = P*(1 + \frac{r}{n})^{t*n}$

Since we compound more and more often then n gets bigger and bigger and approaches infinity and we can rewrite the formula as a limit: $C = \lim_{n \to +\infty} P*(1 + \frac{r}{n})^{t*n}$

Define x variable as: $x = \frac{n}{r} \\ n = x * r$

then x is direct proportional with n, as n approaches infinity, then x approaches infinity as well, limit formula holds and we can substitute n with x: $C = \lim_{x \to +\infty} P*(1 + \frac{r}{x*r})^{t*x*r}$ extract constant P outside the limit, cancel out r and commute the exponents: $C = P * (\lim_{x \to +\infty} (1 + \frac{1}{x})^x)^{r*t}$

What does the above formula looks like? Calculus anyone? Looks like the Euler's number $e = \lim_{x \to +\infty} (1 + \frac{1}{x})^x$

that gets substituted and we end up with the magic continuous compounding formula: $\color{red} C = P * e^{r*t}$

  from math import e
c = p * e**(r*t)
print('$%.2f' % c) $1102.32


Takeaway: Before moving further it is important to understand the difference between APY (annual percentace yield) and APR (annual percentance rate), the former include compounding interest, the latter does not. In other words APR is simple interest and APY is compounding interest.

### Discounted interest-rate

What about the other way around, we are given the final (compounding value) and need to calculate the present value?

Simple, re-arranging the compounding formula above we have:

$P = \frac{C}{e^{r*t}}$ $\color{red} P = C * e^{-r*t}$

where P is called the present value or discounted value and is very useful in financial valuation.

### A few tricks

#### Double your investment aka 100% profit

OK, now, let's assume that I want to invest $1000 at 6% annual interest rate and I want to know how many years do I need to double my investment? ##### Analytical Let's do a bit of high school math using the annual compounding formula above. $\textcolor{blue} {C = P*(1 + r)^t} \\ \frac{C}{P} = (1 + r)^t \\ t = \log_{1+r} \frac{C}{P} \\ t = \frac{\ln {\frac{C}{P}}}{\ln 1+r}$ After putting in the numbers we end up with: $t = \frac{\ln {\frac{2000}{1000}}}{\ln 1+0.06} \\ \textcolor{green} {t = 11.9\ years}$ Double check in Python:  from math import log t = log(2)/ log(1.06) print('%.1f years' % t) 11.9 years  Unfortunately most of the people cannot do logarithms in their heads but rest assured there is a lot easier solution. ##### Rule of 72 As Investopedia nicely explains it: Rule of 72 is a formula to estimate the number of years required to double the invested money at a given annual interest rate. Just divide 72 by the annual interest rate 6 and there you have it: ~12 years.  t = 72 / 6 print('%.1f years' % t) 12.0 years  Why 72? Detailed explanations here but ultimately it is as simple ln 2, $\ln 2 = 0.693$ while 2 comes from doubling ($2000 / \$1000), if you need to find the tripling time just use 3 or 1.5 for halving time.

comments powered by Disqus