Derive Mortgage Amortization Formula from Scratch
A Journey to Discover the Beauty of Math in Real Estates with the Visualization in Python
I. Definition
If you took a down payment on your mortgage, most likely you are taking an Amortizing Loan.
An amortization loan refers to an exact amount you pay monthly so that by the end of the loan term you paid off the debt and the interest.
The monthly amortization consists of interest payments and principal payments. The interest payment goes toward the interest while the principal payment contributes to your actual debt.

Notably, when your debt goes down, the interest of the following month reduce, and the principal increases. The less you have to pay for the interest, the more money you can put toward reducing the underlying debt.
For example, you bought a $300,000 house with a 20% down payment. The interest rate is 3.5% and you plan to pay it off in 30 years. This is what you have to pay annually.

The sum of the principal column is 80% of the mortgage (20% down payment) and the sum of the interest column is the lender’s profit. Note that every period you pay the same amount.
II. Derivation
Let’s start with denoting different variables:

Every month j we pay the same amount x,

For every month, the interest is calculated by the remaining balance. Iterating this logic we obtain:

The recursion can be converted to an exclusive formula by first expanding all the terms…

… and then observing the pattern to deduce the principal j,

The total amount over N periods is the original principal plus the total interest of all months,

Therefore,

Since the denominator looks like a geometric sum,

we can simplify further and obtain the monthly payment x ,

These formulas will help us later in developing the Python code.
III. Code
Applying the formulas (1), (2), and (3) we obtain the following code:


