CodePlexProject Hosting for Open Source Software

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 __L MI) MI = X(1__MI) – L

P3 = X – (L – P1 – P2)

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

L = (X-L

Simplify a bit as IND = (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) = (1

F(n

F(n

Also F(n

1

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

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