Mortgage calculator mathematical approach
1. How do I calculate monthly payment?
Let’s say our loan is “L” and interest rate is “I” and the term of mortgage (length of mortgage) is “T”. That is all we need to calculate the famous monthly payment. Let’s figure out the formula for that and call it “X”.

First month X = P1 + L(I/(100 12)) since the interest is as a percentage and is for the whole year.
Use the MI as monthly interest:
MI = I/(100 * 12)) so the payment will be
X = P1 + L*MI where P1 is the principal payed in the first month
We can say then P1 = X – L * MI
Second month: P2 = X – (L-P1) * MI since we already pay part of the loan (P1) interest will be calculated for the remaining
P2 = X – (L – X LMI) MI = X(1MI) – LMI(1 MI)=(1MI)(X – LMI)
P3 = X – (L – P1 – P2)MI = X- (L – X L MI – (1MI)(x – LMI)) MI = X XMI X(1MI)MI – (L LMI LMI LMI2 )MI = X(1 2MI MI2) – L(1 2MI MI2)MI = (1+MI)2(X-LMI)

SO:
P1 = (1+MI)0 * (X-L*MI)
P2 = (1+MI)1 * (X-L*MI)
P3 = (1+MI)2 * (X-L*MI)
.
.
.
PN = (1+MI)n-1 * (X-L*MI)
Now, let’s sum it up as P1 P2 P3 + … PN = L because sum of all principals must be the actual loan.

L = (X-LMI)( (1MI)0 (1MI)1 (1MI)2 … (1+MI)n-1 ) then
Simplify a bit as IND = (1MI)0 (1MI)1 (1MI)2 … (1+MI)n-1
X = L/IND + L * MI
X = L * (1/IND + MI)
At this point programmatically we can calculate IND by doing a loop as
double nInd = 0;
for (int i = 0; i < T; i++)
{
nInd += Math.Pow((1 + MI), i);
}
But let’s try to help the computer to rest for a bit and see if we can calculate the recurrence.
For this we applied a very well-known trick. To calculate that recurrent indicator, we create a function as:
F(n) = (1MI)0 (1MI)1 (1MI)2 … (1+MI)n-1
F(n1) = (1MI)0 (1MI)1 (1MI)2 … (1MI)n-1 (1MI)n
F(n1) = F(n) (1+MI)n
Also F(n1) = 1 (MI1)( (1MI)0 (1MI)1 (1MI)2 … (1MI)n-1) = 1 (MI1)F(n)
1 (MI1)*F(n) = F(n) (1MI)n we can simply deduct
F(n) = ((1+MI)n – 1)/MI

With this in mind we can safely say
X = L * (1/F(n) + MI)
So for example you Need a loan for 400k with a 3.5% interest for 10 years.
MI = 3.5/1200
N=T*12=120
F(n) = (1 + 3.5/1200)120 – 1) / (3.5/1200) = 143.43251049835925626507852655046;
X = 400000 * (1/143.43… + 3.5/1200 ) = 3955.43

To calculate the amortization is simply since we did the hard work. Doing a loop for the length of the term we can calculate the principal since we know the monthly payment
PN = (1+MI)n-1 * (X-L*MI)
Than monthly interest will be Monthly Payment minus the principal.
Further we can calculate the total of the amount of interest payed and the remaining balance for each month (amortization)

Please download the application that displays both month and amortization payments

Sorry for the exponents they cannot agree with me. I have uploaded the word document if you want to understand the mortgage formula.

please check MortgageCalc.pdf

And for the courtesy of LM Software we provide also a web interface where you can check the result

Mortgage calculator

windows app C#

Last edited Nov 7, 2016 at 11:47 PM by mmilitaru, version 8