module.exports = { slug: "loan-payment-amortized", title: "Amortized loan payment", deck_category: "finance", description: "Computes the fixed monthly payment for a fully amortizing loan using the standard annuity payment formula.", inputs: [ { name: "principal", type: "number", unit: "currency units", required: true, description: "Loan amount borrowed", min: 0 }, { name: "annual_rate_percent", type: "number", unit: "%", required: true, description: "Nominal annual interest rate, compounded monthly", min: 0 }, { name: "months", type: "integer", required: true, description: "Number of monthly payments (loan term in months)", min: 1 } ], outputs: [ { name: "monthly_payment", unit: "currency units", description: "Fixed payment due each month" } ], steps: [ "Convert the annual rate to a decimal: r = annual_rate_percent / 100.", "Monthly rate i = r / 12.", "If i = 0, monthly_payment = principal / months.", "Otherwise, monthly_payment = principal * i * (1 + i)^months / ((1 + i)^months - 1) (the standard annuity payment formula).", "Round monthly_payment to 2 decimals (money to cents)." ], constants: [], sources: [ { kind: "edition_page", value: "Brealey, Myers, Allen, Principles of Corporate Finance, 13th ed., Chapter 3, section 3-3 (Loan Amortization)", title: "Principles of Corporate Finance", publisher: "McGraw-Hill", retrieved_utc: "2026-09-30T19:31:29Z", note: "Standard fixed-payment annuity formula for amortizing loans" } ], disclaimer: null, questionText(inputs) { return `What is the fixed monthly payment on a $${inputs.principal} loan at ${inputs.annual_rate_percent}% annual interest amortized over ${inputs.months} months?`; }, run(inputs) { const { principal, annual_rate_percent, months } = inputs; if (typeof principal !== "number" || principal < 0) throw new Error("principal must be a non-negative number"); if (typeof annual_rate_percent !== "number" || annual_rate_percent < 0) throw new Error("annual_rate_percent must be a non-negative number"); if (!Number.isInteger(months) || months <= 0) throw new Error("months must be a positive integer"); const r = annual_rate_percent / 100; const i = r / 12; let monthly_payment; if (i === 0) { monthly_payment = principal / months; } else { const factor = Math.pow(1 + i, months); monthly_payment = (principal * i * factor) / (factor - 1); } monthly_payment = Math.round(monthly_payment * 100) / 100; return { answer: `$${monthly_payment.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`, values: { monthly_payment } }; }, examples: [ { name: "worked example", inputs: { principal: 200000, annual_rate_percent: 6, months: 360 }, expected: { answer: "$1,199.10" }, check: "hand computation: i = 0.005, factor = 1.005^360 = 6.022575..., payment = 200000*0.005*6.022575/(6.022575-1) = 1199.10" }, { name: "test vector: zero interest", inputs: { principal: 12000, annual_rate_percent: 0, months: 12 }, expected: { answer: "$1,000.00" }, check: "hand computation: zero-rate branch, payment = 12000/12 = 1000.00" } ] };