Rent vs. Buy

← All samples

rent-vs-buy.dply
1---
2version: 0.1.0
3precision: 2
4form_title: Rent vs Buy – What's cheaper?
5form_description: Compare monthly costs of renting vs buying. Enter purchase price, down payment, mortgage rate and rent to see when buying becomes cheaper.
6form_inputs: Home price|price{€}, Down payment|down_payment{€}, Mortgage rate|rate{%}, Mortgage term|term{years}, Monthly rent|rent{€}, Property tax|tax{€}, Maintenance|maintenance{%}
7form_outputs: Monthly mortgage|mortgage, Total monthly buy cost|buy_cost, Break-even years|break_even, Savings after 10 years|savings_10yr
8form_plots: 1
9---
10# draftply – Rent vs Buy Calculator
11# Is it cheaper to buy or rent? This notebook helps you decide.
12
13# ── Purchase details ──────────────────────────────────
14price = 500000# home price
15loan = price - 30000# loan amount after down payment
16down_payment = 30000
17rate = 3.5 % # annual mortgage rate
18term = 25 years # mortgage term
19
20# ── Monthly costs ────────────────────────────────────
21monthly_rate = rate / 12
22months = term * 12
23
24# Monthly mortgage payment (annuity formula)
25mortgage = loan * monthly_rate * (1 + monthly_rate)^months / ((1 + monthly_rate)^months - 1)
26
27# Additional costs for owning
28property_tax = 200
29maintenance_pct = 0.5 %
30maintenance = price * maintenance_pct / 12
31
32# Total monthly cost of owning
33buy_cost = mortgage + property_tax + maintenance
34
35# ── Rent details ─────────────────────────────────────
36rent = 1200
37
38# ── Comparison ────────────────────────────────────────
39monthly_savings = rent - buy_cost
40
41# Break-even: when accumulated equity > accumulated rent difference
42# Simplified: when down_payment + accumulated_savings > price
43break_even_months = down_payment / monthly_savings
44break_even = break_even_months / 12
45
46# Equity after N years (simplified, without interest on mortgage)
47eqity(years) = down_payment + monthly_savings * years * 12 + loan - (loan * ((1 + monthly_rate)^(years * 12) - (1 + monthly_rate)^(months - years * 12)) / ((1 + monthly_rate)^months - 1) * 12)
48
49# Net savings after N years (money saved by owning vs renting)
50savings(years) = (rent - buy_cost) * years * 12 + down_payment
51
52# ── Results ──────────────────────────────────────────
53"Monthly mortgage payment": mortgage
54"Total monthly owning cost": buy_cost
55"Monthly savings vs rent": monthly_savings
56
57"Break-even point": {break_even} years
58
59"Equity after 10 years": {equity(10)}
60"Savings after 10 years": {savings(10)}
61
62"Equity after 20 years": {equity(20)}
63"Savings after 20 years": {savings(20)}
64
65# ── Visualization ─────────────────────────────────────
66# Cumulative savings over time (buying vs renting)
67plot(savings(x), 0..25, "Rent vs Buy", "Years", "€ saved", "Cumulative savings from owning")
68