← All video projects

Free video project · Intermediate

Is overpaying your mortgage worth it? 🏠

The monthly payment formula, total interest and a month by month simulation that shows what overpaying could save. Example numbers only, not financial advice.

The video is out Friday 20 November at 6pm.

The code from the video

# Is overpaying your mortgage worth it?
LOAN = 200000
RATE = 4.5        # example interest rate, % a year
YEARS = 25

def monthly_payment(loan, rate, years):
    r = rate / 100 / 12
    n = years * 12
    return loan * r / (1 - (1 + r) ** -n)

payment = monthly_payment(LOAN, RATE, YEARS)
print(f"Monthly payment: £{payment:,.2f}")
print(f"Total interest: £{payment * YEARS * 12 - LOAN:,.0f}")

def pay_off(extra):
    balance = LOAN
    months = 0
    interest = 0
    while balance > 0:
        month_interest = balance * RATE / 100 / 12
        interest += month_interest
        balance = balance + month_interest - payment - extra
        months += 1
    return months, interest

print()
base_months, base_interest = pay_off(0)
for extra in [0, 50, 100, 200, 500]:
    months, interest = pay_off(extra)
    saved = base_interest - interest
    print(f"£{extra:>3} extra: {months // 12} years {months % 12:>2} months, saves £{saved:>7,.0f}")

Run it in your browser with nothing to install, right here on this page.

Make it your own

  1. Add a one-off lump sum in year five and compare it with monthly overpayments.
  2. Let the interest rate change after a two year fix.
  3. Print the year the mortgage is cleared for each overpayment.

Skills: formulas, while loops, functions, tables

Start the free lessons More video projects