avatarHuy Bui

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1838

Abstract

medium.com/v2/resize:fit:800/1*tf-7aT08l_VMUJ5mgzJ_GQ.png"><figcaption></figcaption></figure><p id="1b8d">Every month <code>j</code> we pay the same amount <code>x</code>,</p><figure id="8f71"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*wF7qaWV1Q3BoMyakArPhaA.png"><figcaption></figcaption></figure><p id="1ef1">For every month, the interest is calculated by the remaining balance. Iterating this logic we obtain:</p><figure id="1a9a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*rTyhfHFBUligZOx6cDCekw.png"><figcaption></figcaption></figure><p id="39f2">The recursion can be converted to an exclusive formula by first expanding all the terms…</p><figure id="8f43"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*yzEWbTWZEiY9weKjGogy_A.png"><figcaption></figcaption></figure><p id="6e0f">… and then observing the pattern to deduce the <b>principal </b><code>j</code>,</p><figure id="ed06"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2VtOeay6c8E4argPr5lSDw.png"><figcaption></figcaption></figure><p id="656c">The total amount over <code>N</code> periods is the original principal plus the total interest of all months,</p><figure id="81cb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*0bseI_4POzUCXqcSOEMXFg.png"><figcaption></figcaption></figure><p id="8d7b">Therefore,</p><figure id="bf25"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*BXvkWM7pDsomQX3yUUP5Jg.png"><figcaption></figcaption></figure><p id="56e9">Since the denominator looks like a geometric sum,</p><figure id="31f2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*H3z1ctFBUVT8B9j82VPjhA.png"><figcaption></figcaption></figure><p id="0553">we can simplify further and obtain the <b>monthly payment</b> <code>x</code> ,</p><figure i

Options

d="3577"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ofOFpDxIHtELxqMrlFBL8Q.png"><figcaption></figcaption></figure><p id="521f">These formulas will help us later in developing the Python code.</p><h1 id="f31e">III. Code</h1><p id="f934">Applying the formulas (1), (2), and (3) we obtain the following code:</p> <figure id="d252"> <div> <div>

            <iframe class="gist-iframe" src="/gist/williamhuybui/512ef586042bfa032a2e35740ee6040c.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="ace6">Let say we borrow 240,000, with an annual interest of 3.5% in 30 years. The result is:</p><figure id="9a6d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Ao-4QBC8nkM2Z9t5cVCgOg.png"><figcaption></figcaption></figure><p id="2ba3">Finally, we add some visualization with Plotly</p>
    <figure id="1d7b">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/williamhuybui/7c9aa58e2fc344c3461af3340a0b28d4.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><figure id="bc96"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*iF6TgzCjbwaWq6CsZbvmJw.png"><figcaption>You can access the interactive version <a href="https://chart-studio.plotly.com/~williamhuybui/1/#/">here</a>.</figcaption></figure><p id="4a4f">We just derived the amortized formula from scratch and visualized our result with Plotly.</p><p id="b5ad">You can find me on LinkedIn @<a href="https://www.linkedin.com/in/huy-bui-data-scientist/">huybui</a></p></article></body>

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.

Source Huy Bui

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.

Source: Karl’s Mortgage Calculator

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:

Let say we borrow 240,000, with an annual interest of 3.5% in 30 years. The result is:

Finally, we add some visualization with Plotly

You can access the interactive version here.

We just derived the amortized formula from scratch and visualized our result with Plotly.

You can find me on LinkedIn @huybui

Data Science
Mathematics
Python
Real Estate
Amortization
Recommended from ReadMedium