add year 0 row and Nebenkosten mitfinanzieren toggle
This commit is contained in:
34
calc.js
34
calc.js
@@ -13,7 +13,16 @@ function run_simulation(p) {
|
||||
const months = p.years * 12;
|
||||
|
||||
// --- mortgage setup ---
|
||||
const loan = p.home_price * (1 - p.down_pct / 100);
|
||||
const down_payment = p.home_price * (p.down_pct / 100);
|
||||
const closing_costs = p.home_price * (p.closing_buy_pct / 100);
|
||||
// if financed: closing costs rolled into loan, buyer only needs down payment upfront
|
||||
const loan = p.finance_nebenkosten
|
||||
? p.home_price * (1 - p.down_pct / 100) + closing_costs
|
||||
: p.home_price * (1 - p.down_pct / 100);
|
||||
const upfront_buy = p.finance_nebenkosten
|
||||
? down_payment
|
||||
: down_payment + closing_costs;
|
||||
|
||||
const r_m = p.interest_rate / 100 / 12;
|
||||
const n = p.loan_years * 12;
|
||||
let monthly_payment;
|
||||
@@ -23,9 +32,6 @@ function run_simulation(p) {
|
||||
monthly_payment = loan * (r_m * Math.pow(1 + r_m, n)) / (Math.pow(1 + r_m, n) - 1);
|
||||
}
|
||||
|
||||
// upfront costs for buyer
|
||||
const down_payment = p.home_price * (p.down_pct / 100);
|
||||
const upfront_buy = down_payment + p.home_price * (p.closing_buy_pct / 100);
|
||||
const start_capital = p.start_capital || 0;
|
||||
|
||||
// --- state ---
|
||||
@@ -53,6 +59,26 @@ function run_simulation(p) {
|
||||
|
||||
let breakeven_month = null;
|
||||
|
||||
// --- year 0 snapshot (day of purchase) ---
|
||||
const selling_costs_0 = home_value * (p.closing_sell_pct / 100);
|
||||
labels.push('Jahr 0');
|
||||
buyer_nw_arr.push(Math.round(home_value - selling_costs_0 - balance + buyer_portfolio));
|
||||
renter_nw_arr.push(Math.round(start_capital));
|
||||
cum_buy_arr.push(Math.round(upfront_buy));
|
||||
cum_rent_arr.push(0);
|
||||
detail_arr.push({
|
||||
house_value: Math.round(home_value),
|
||||
mortgage_balance: Math.round(balance),
|
||||
buyer_portfolio: Math.round(buyer_portfolio),
|
||||
yr_interest: 0,
|
||||
yr_principal: 0,
|
||||
yr_upkeep: 0,
|
||||
yr_rent: 0,
|
||||
yr_renters_ins: 0,
|
||||
kaufnebenkosten: Math.round(closing_costs),
|
||||
finance_nebenkosten: p.finance_nebenkosten,
|
||||
});
|
||||
|
||||
const invest_r_m = p.invest_return / 100 / 12;
|
||||
const app_r_m = p.appreciation / 100 / 12;
|
||||
const rent_inc_m = p.rent_increase / 100 / 12;
|
||||
|
||||
Reference in New Issue
Block a user