Take three balances of $600, $1,500, and $2,400 and a monthly payment budget of $300. In the worked schedule below, snowball clears the first balance in month 4. Avalanche clears its first balance in month 9 and costs $64.86 less in interest. Both schedules finish in month 17. The first payoff date and the full payoff date measure different outcomes from the same budget.
Fix the month-end rules before comparing strategies
Each month starts with the same interest and minimum-payment rules in both scenarios. Apply interest to the opening balance, pay each account's minimum up to the amount owed, and spend the remaining budget in priority order. Snowball prioritizes the smallest opening balance. Avalanche prioritizes the highest annual percentage rate (APR). When an extra payment clears a debt, send the unused dollars to the next debt that month. CFPB reducing debt worksheet
Use bigint cents for balances and basis points for APR. For a monthly accrual at a fixed APR, divide openingCents * aprBps by 120_000 and round each account's interest half up. The sample uses fixed monthly minimums, fixed rates, and one payment date per month. For a lender reconciliation, use the lender's accrual basis, payment posting dates, fees, and minimum calculation. A daily-balance card can produce a different result.
Save this as debt.mts and run node debt.mts with Node.js 24. It writes one amortization CSV per strategy and prints payoff month, first clearance, interest, and total paid. Node.js TypeScript support
import assert from "node:assert/strict"; import { writeFile } from "node:fs/promises"; type Debt = { id: string; balance: bigint; aprBps: bigint; minimum: bigint }; type Strategy = "snowball" | "avalanche"; type MonthRow = { month: number; id: string; opening: bigint; interest: bigint; minimumPaid: bigint; extraPaid: bigint; closing: bigint; }; const min = (a: bigint, b: bigint) => a < b ? a : b; const compare = (a: bigint, b: bigint) => a < b ? -1 : a > b ? 1 : 0; const APR_PER_MONTH_DENOMINATOR = 12n * 10_000n; function amortize(debts: Debt[], budget: bigint, strategy: Strategy, maxMonths = 600): MonthRow[] { assert(budget > 0n && Number.isSafeInteger(maxMonths) && maxMonths > 0); assert(debts.every(({ id, balance, aprBps, minimum }) => /^[A-Z][A-Z0-9-]*$/.test(id) && balance >= 0n && aprBps >= 0n && minimum >= 0n)); assert.equal(new Set(debts.map(({ id }) => id)).size, debts.length, "Duplicate account ID"); const active = debts.map((debt) => ({ ...debt })); const schedule: MonthRow[] = []; for (let month = 1; active.some((debt) => debt.balance > 0n); month++) { assert(month <= maxMonths, `Unpaid balances after ${maxMonths} months`); let extraBudget = budget; const cycle = active.filter((debt) => debt.balance > 0n).map((debt) => { const opening = debt.balance; const interest = (opening * debt.aprBps + APR_PER_MONTH_DENOMINATOR / 2n) / APR_PER_MONTH_DENOMINATOR; const minimumPaid = min(debt.minimum, opening + interest); extraBudget -= minimumPaid; const row: MonthRow = { month, id: debt.id, opening, interest, minimumPaid, extraPaid: 0n, closing: opening + interest - minimumPaid, }; return { debt, row }; }); assert(extraBudget >= 0n, `Budget below minimums in month ${month}`); cycle.sort((a, b) => { if (strategy === "avalanche") { const higherAprFirst = compare(b.debt.aprBps, a.debt.aprBps); if (higherAprFirst) return higherAprFirst; } return compare(a.row.opening, b.row.opening) || (a.row.id < b.row.id ? -1 : 1); }); for (const { debt, row } of cycle) { row.extraPaid = min(extraBudget, row.closing); extraBudget -= row.extraPaid; row.closing -= row.extraPaid; debt.balance = row.closing; schedule.push(row); } } return schedule; } function summarize(rows: MonthRow[]) { return { months: rows.at(-1)?.month ?? 0, firstClearance: rows.find((row) => row.closing === 0n)?.month ?? 0, interest: rows.reduce((sum, row) => sum + row.interest, 0n), paid: rows.reduce((sum, row) => sum + row.minimumPaid + row.extraPaid, 0n), }; } const debts: Debt[] = [ { id: "A", balance: 60_000n, aprBps: 690n, minimum: 3500n }, { id: "B", balance: 150_000n, aprBps: 2499n, minimum: 5500n }, { id: "C", balance: 240_000n, aprBps: 1450n, minimum: 8000n }, ]; const budget = 30_000n; const snowball = amortize(debts, budget, "snowball"); const avalanche = amortize(debts, budget, "avalanche"); assert.deepEqual(summarize(snowball), { months: 17, firstClearance: 4, interest: 59_750n, paid: 509_750n }); assert.deepEqual(summarize(avalanche), { months: 17, firstClearance: 9, interest: 53_264n, paid: 503_264n }); assert.equal(snowball[0].id, "A"); assert.equal(avalanche[0].id, "B"); assert.throws(() => amortize(debts, 16_999n, "snowball"), /Budget below minimums/); assert.throws(() => amortize(debts, budget, "avalanche", 1), /Unpaid balances/); const spill = amortize([ { id: "A", balance: 3n, aprBps: 0n, minimum: 5n }, { id: "B", balance: 8n, aprBps: 0n, minimum: 1n }, { id: "C", balance: 14n, aprBps: 0n, minimum: 1n }, ], 13n, "snowball"); assert.deepEqual(spill.map((row) => [row.month, row.id, row.minimumPaid, row.extraPaid, row.closing]), [ [1, "A", 3n, 0n, 0n], [1, "B", 1n, 7n, 0n], [1, "C", 1n, 1n, 12n], [2, "C", 1n, 11n, 0n], ]); const principal = debts.reduce((sum, debt) => sum + debt.balance, 0n); for (const [name, rows] of [["snowball", snowball], ["avalanche", avalanche]] as const) { const result = summarize(rows); assert.equal(result.paid, principal + result.interest); const header = "month,account,opening_cents,interest_cents,minimum_paid_cents,extra_paid_cents,closing_cents"; const lines = rows.map((r) => [r.month, r.id, r.opening, r.interest, r.minimumPaid, r.extraPaid, r.closing].join(",")); await writeFile(`${name}.csv`, [header, ...lines, ""].join("\n")); console.log(name, result); } Inspect the first month in both CSVs to verify where the extra $130 went. Then compare the final month, where a capped payment leaves part of the budget unspent. Keeping each account's opening balance, interest, minimum, extra payment, and closing balance alongside the summary makes that comparison traceable. For a workbook and side-by-side PDF built around the two schedules, see DebtScenarioPack.
