online  ·  bengaluru, india  ·  v2.4.0
← back to sai.
2026-09-30 engineering  /  finance ~5 min read

How HomeLoanCalc works

One month-by-month loop, the exact EMI, and Indian tax rules per financial year, in about 73 KB.

HomeLoanCalc answers the questions a bank's EMI calculator doesn't: what a prepayment in March does to the rest of the loan, when a 10% yearly step-up finishes it, what an RBI rate cut is worth, and how much of it all comes back as tax. Why I built it ↗ is its own story. This is how it works.

one loop, month by month

Everything comes out of a single function, simulate(). It walks the loan one month at a time and writes a row per month: opening balance, interest, principal, any extra payment, closing balance, and the rate that month. Prepayments, step-ups and rate changes are just things that can happen inside that loop, so every combination of them works without special cases.

for each month, until the balance is 0:
  step-up?      raise the EMI by n% every k months
  rate change?  keep the EMI (loan gets shorter)
                or re-compute it over the months left
  interest   = balance × rate ÷ 1200
  guard:       EMI ≤ interest? raise it, and say so
  principal  = EMI − interest
  extra      = any lump sum or recurring prepayment
  balance   −= principal + extra

Two details matter more than they look. The EMI is kept exact, not rounded to the rupee: an early version rounded it and, on a 20-year loan, the last few paise spilled into a 241st month. And when a steep rate rise pushes the EMI below the month's interest, the balance would start growing forever. The loop raises the EMI instead and the page tells you it had to.

tax, the way the income tax act counts it

The schedule is regrouped into financial years, April to March, because that's how deductions are claimed. Your first EMI in November means a short first year. For each year:

It also flags the years where your interest is above the 24(b) cap. That's usually the strongest case for a prepayment early in the loan.

no backend, no database

Every input lives in the URL. Share the link and the other person sees exactly your plan; nothing is stored anywhere. Links from the first version, in two older formats, still open correctly, because people had already shared them.

light on purpose

The first version used Material UI and a charting library. It looked like every other calculator and shipped a lot of code for a page with one job. The rebuild uses hand-written components and a small SVG chart: the whole app is about 73 KB of gzipped JavaScript, works offline as an installable PWA, and has a dark mode.

tested where it counts

23 tests cover the money: the EMI matches the standard formula, the principal column sums exactly to the loan, a lump sum is applied once and never more than what's owed, both rate-change modes behave, the balance never grows, 24(b) and 80C caps hold per borrower, financial years split at March, and old links still decode. They run on every pull request before anything can merge.

where it runs

The build is a folder of static files, served by a 46-line Python script on the phone that hosts all my apps, behind a Cloudflare tunnel. Deploys go through the same guarded path as everything else: built from a merged, tagged commit, smoke-tested on the phone and through Cloudflare, and rolled back on their own if a check fails.

— — —

Try it at loancalc-saiworks.nncs.in ↗. The code is on github ↗.

Written by Sai  ·  sai31nayak@gmail.com  ·  github ↗