# Understanding mortgage

I am considering to buy an investment home recently and so am trying to really understand mortgage. As an engineer, I thought it should be very simple. Indeed, it is quite simple but it eventually spent me couple hours figuring it out on my own. It is a simple high school math problem but I guess my old brain was slowing me down.

Anyway, let start with a simple question. How much do I need to pay monthly if I want to borrow $30,000 for 5 years with monthly interest rate of 0.5%? Let $L$ be the size of the loan, i.e.,$30,000, $C$ be the monthly payment, $N$ be the number of period (5 $\times$ 12 = 60), and $r$ be the monthly interest rate, 0.005.

The question is very simple if one understands present value. The amount of money does not worth the same at different times because of interest. If I have one dollar now, my one dollar will become 1.005 dollar a month later because of interest. In reverse, the $C$ dollar that I’m paying to the bank next month will be worth only $C/(1+r)$ now. Therefore, the total payment in the future is worth only

$\frac{C}{1+r} + \frac{C}{(1+r)^2} + \frac{C}{(1+r)^3} + \cdots + \frac{C}{(1+r)^N}$

$=\frac{C}{1+r} \frac{(1+r)^N-1}{r}$,

which should be equivalent to the entire loan $L$. Therefore, the monthly payment is given by

$C = L \frac{r (1+r)}{(1+r)^N-1}$. This gives us \$432.13.

Now, the more interesting question (that I was stuck) is what fraction of money is paid to the principal and the interest each month. I think it probably easier to explain it starting from the farthest future and going backward.

Let’s consider the time that we just pay for the second last payment, how much do we own the bank? You may say, $C$ dollars, right? Because in a month later, we will pay the last payment of $C$ dollars and will not owe the bank anymore. But we need to be careful that money a month later is not the same as money now, it is discounted by the factor $(1+r)$. Another way to think about it is that we have to pay interest for the last month also. So it won’t be possible that we only need to pay $C$ dollars next month if we only owe $C$ dollar now. Instead, we actually owe $\frac{C}{1+r}$ dollars. So how much interest do we pay for the last payment? It will be

$C - \frac{C}{(1+r)} = \frac{C}{1+r} r$. Note that again $\frac{C}{1+r}$ is how much we owe just after we pay the second last payment. So of course the interest should be just that multiplied by $r$. So everything adds up. Good!

Now, how about a period before that? That is, the time when we just pay for the third last payment. By similar token, we should owe

$\frac{1}{1+r} (C+ \frac{C}{1+r})$

to the bank. Now, forward one month again, the amount becomes

$C + \frac{C}{1+r}$

and we have only $\frac{C}{1+r}$ after paying $C$ dollars for  the second last payment. Great! Everything adds up again. And what is the interest in the second last payment?  It is

$\frac{r}{1+r}(C+ \frac{C}{1+r})$.

So in general, the interest pay in the $n$th last payment is

$C \frac{r}{1+r} (1 + \frac{1}{1+r} + \cdots + \frac{1}{(1+r)^{(n-1)}})$ $= C \frac{r}{1+r} \frac{1/(1+r)^n - 1}{1/(1+r) -1}$

$= C (1 - \frac{1}{(1+r)^n})$.

And what is the total interest? It will be

$C (1- \frac{1}{1+r}) +C(1-\frac{1}{(1+r)^2})+\cdots+C(1-\frac{1}{(1+r)^N})$ $=NC-C(\frac{1}{1+r}+\frac{1}{(1+r)^2}+\cdots+\frac{1}{(1+r)^N})$

$=NC-L$. Exactly what we will expect. Nice!

For our loan example, the below plot shows the fraction of principal paid over the periods. We can see that more interest is paid in the earlier periods than the later ones.

And the remaining amount over periods is shown below.

Finally, simple matlab code for generating the figures is shown below:

L=30000; % size of loan
N=60; % period
r=0.005; % interest rate per period
%L*(1+r) = P + P/(1+r) + P/(1+r)^2 + P/(1+r)^3
% = P (1-(1/1+r)^N)/(1-(1/(1+r))
P= L*(1+r)/((1-(1/(1+r))^N)/(1-1/(1+r)));
Ls(1)=L;
In(1)=0;
Ps(1)=0;
for i=2:N+1;
In(i)=Ls(i-1)*r;
Ps(i)=P-In(i);
Ls(i)=Ls(i-1)-Ps(i);
end
close all
figure;
plot(1:length(Ps)-1,Ps(2:end)/P);
title('Fraction of principal paid at each period');
xlabel('period');
ylabel('Fraction');
figure;
plot(1:length(Ls)-1, Ls(2:end));
title('Remaining loan');
xlabel('period');
ylabel('remaining loan');