stop mortgage payments once balance reaches zero
This commit is contained in:
9
calc.js
9
calc.js
@@ -87,16 +87,17 @@ function run_simulation(p) {
|
|||||||
|
|
||||||
for (let m = 1; m <= months; m++) {
|
for (let m = 1; m <= months; m++) {
|
||||||
// --- buy side ---
|
// --- buy side ---
|
||||||
const interest_m = balance * r_m;
|
const has_debt = balance > 0;
|
||||||
const principal_m = monthly_payment - interest_m;
|
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);
|
balance = Math.max(0, balance - principal_m);
|
||||||
home_value *= (1 + app_r_m);
|
home_value *= (1 + app_r_m);
|
||||||
|
|
||||||
const prop_tax_m = home_value * (p.prop_tax_rate / 100) / 12;
|
const prop_tax_m = home_value * (p.prop_tax_rate / 100) / 12;
|
||||||
const maint_m = home_value * (p.maint_rate / 100) / 12;
|
const maint_m = home_value * (p.maint_rate / 100) / 12;
|
||||||
const insurance_m = p.insurance / 12;
|
const insurance_m = p.insurance / 12;
|
||||||
// German context: no mortgage interest tax deduction for private buyers
|
const mortgage_m = has_debt ? monthly_payment : 0;
|
||||||
const total_buy_m = monthly_payment + prop_tax_m + maint_m + insurance_m;
|
const total_buy_m = mortgage_m + prop_tax_m + maint_m + insurance_m;
|
||||||
|
|
||||||
yr_interest += interest_m;
|
yr_interest += interest_m;
|
||||||
yr_principal += principal_m;
|
yr_principal += principal_m;
|
||||||
|
|||||||
Reference in New Issue
Block a user