Loan Comparison

← All samples

loan-comparison.dply
1---
2version: 0.1.0
3precision: 2
4form_title: Loan Comparison
5form_description: Compare two loans side by side. Enter loan amount, interest rates and terms to see monthly payments and total interest paid.
6form_inputs: Loan amount|amount{€}, Rate A|rate_a{%}, Term A (years)|term_a{years}, Rate B|rate_b{%}, Term B (years)|term_b{years}
7form_outputs: Monthly A|monthly_a, Total interest A|interest_a, Monthly B|monthly_b, Total interest B|interest_b, Savings with B|savings
8---
9# draftply – Loan Comparison
10# Which loan is really cheaper? Compare monthly payments and total costs.
11
12# ── Loan parameters ────────────────────────────────────
13amount = 20000# loan amount
14rate_a = 4.5 % # annual interest rate A
15term_a = 5 years # term in years A
16rate_b = 3.8 % # annual interest rate B
17term_b = 7 years # term in years B
18
19# ── Monthly payment calculation (annuity formula) ─────────
20# P = L * r * (1+r)^n / ((1+r)^n - 1)
21# where P = monthly payment, L = loan amount, r = monthly rate, n = number of months
22
23# Loan A
24months_a = term_a * 12
25rate_a_monthly = rate_a / 12
26monthly_a = amount * rate_a_monthly * (1 + rate_a_monthly)^months_a / ((1 + rate_a_monthly)^months_a - 1)
27total_a = monthly_a * months_a
28interest_a = total_a - amount
29
30# Loan B
31months_b = term_b * 12
32rate_b_monthly = rate_b / 12
33monthly_b = amount * rate_b_monthly * (1 + rate_b_monthly)^months_b / ((1 + rate_b_monthly)^months_b - 1)
34total_b = monthly_b * months_b
35interest_b = total_b - amount
36
37# ── Comparison ──────────────────────────────────────────
38savings = total_a - total_b
39savings_percent = (savings / total_a) * 100
40
41# ── Results ─────────────────────────────────────────────
42"Loan amount": amount
43
44"--- Option A ---"
45"Monthly payment A": monthly_a
46"Total repayment A": total_a
47"Total interest A": interest_a
48
49"--- Option B ---"
50"Monthly payment B": monthly_b
51"Total repayment B": total_b
52"Total interest B": interest_b
53
54"--- Comparison ---"
55"Savings with B": savings
56"Savings percentage": savings_percent
57
58"Break-even in months": (total_a - total_b) / (monthly_a - monthly_b) # months until B becomes cheaper
59