From 1acc85fa26796591c714b9dc817551d64807c0d4 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 20 Mar 2026 02:58:50 +0100 Subject: [PATCH] stop mortgage payments once balance reaches zero --- calc.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/calc.js b/calc.js index b887e13..759cdec 100644 --- a/calc.js +++ b/calc.js @@ -87,16 +87,17 @@ function run_simulation(p) { for (let m = 1; m <= months; m++) { // --- buy side --- - const interest_m = balance * r_m; - const principal_m = monthly_payment - interest_m; + const has_debt = balance > 0; + const interest_m = has_debt ? balance * r_m : 0; + const principal_m = has_debt ? Math.min(balance, monthly_payment - interest_m) : 0; balance = Math.max(0, balance - principal_m); home_value *= (1 + app_r_m); const prop_tax_m = home_value * (p.prop_tax_rate / 100) / 12; const maint_m = home_value * (p.maint_rate / 100) / 12; const insurance_m = p.insurance / 12; - // German context: no mortgage interest tax deduction for private buyers - const total_buy_m = monthly_payment + prop_tax_m + maint_m + insurance_m; + const mortgage_m = has_debt ? monthly_payment : 0; + const total_buy_m = mortgage_m + prop_tax_m + maint_m + insurance_m; yr_interest += interest_m; yr_principal += principal_m;