Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

finance

pay, interest and growth, loans, splitting bills, margins

Example results generated on 2026-10-08. Ones using now, today or randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.

arguments

# functions tell arguments apart by unit: $1000 a sum, $500/mo a payment,
# 7%/yr a rate, 10 yr a time, "monthly" how often interest compounds

Functions

functiondescription
salary(rate: quantity, opts?: map)pay per hour, day, week, month and year; opts {hours: 40 a week, weeks: 52 paid}
grow(sum: num|quantity, rate: quantity, time: quantity, payment?: quantity|str, compounding?: str)future value: a sum and/or payments growing at a rate
cagr(start: num|quantity, end: num|quantity, time: quantity)compound annual growth rate
doubling(rate: quantity, compounding?: str)time for money to double
apy(rate: quantity, compounding: str)effective yearly rate after compounding
real_rate(rate: quantity|num, inflation: quantity|num)return after inflation
payment(loan: num|quantity, rate: quantity, time: quantity, compounding?: str)monthly payment that pays off a loan
payoff(balance: num|quantity, rate: quantity, payment: quantity, compounding?: str)how long a payment takes to clear a balance, in whole payments
amortize(loan: num|quantity, rate: quantity, time: quantity, opts?: map)payment schedule: {n, payment, interest, principal, balance} per month; opts {extra: $200/mo}
share(sum: num|quantity, parts: int|list)split into parts that add up exactly, to the cent
settle(paid: map)who pays whom so everyone paid the same
change(from: num|quantity, to: num|quantity)fractional change from one value to another
margin(cost: num|quantity, price: num|quantity)profit as a fraction of the price
markup(cost: num|quantity, price: num|quantity)profit as a fraction of the cost

salary

salary(rate: quantity, opts?: map): pay per hour, day, week, month and year; opts {hours: 40 a week, weeks: 52 paid}

salary($25/h)
# → {hour: $25.00, day: $200.00, week: $1,000.00, month: $4,333.33, year: $52,000.00}
salary(85000 USD/yr, {hours: 37.5})
# → {hour: $43.59, day: $326.92, week: $1,634.62, month: $7,083.33, year: $85,000.00}

See also: grow

grow

grow(sum: num|quantity, rate: quantity, time: quantity, payment?: quantity|str, compounding?: str): future value: a sum and/or payments growing at a rate

grow($10000, 7%/yr, 30 yr)
# → $76,122.55
grow($0, 7%/yr, 30 yr, $500/mo)
# → $609,985.50
grow($1000, 5%/yr, 1 yr, "daily")
# → $1,051.27

See also: cagr, payment

cagr

cagr(start: num|quantity, end: num|quantity, time: quantity): compound annual growth rate

cagr($1000, $2500, 8 yr)
# → 12.1353%/yr

See also: grow, change

doubling

doubling(rate: quantity, compounding?: str): time for money to double

doubling(7%/yr)
# → 10.2448 yr

See also: grow

apy

apy(rate: quantity, compounding: str): effective yearly rate after compounding

apy(5%/yr, "daily")
# → 5.12675%/yr
apy(5%/yr, "monthly")
# → 5.11619%/yr

See also: grow

real_rate

real_rate(rate: quantity|num, inflation: quantity|num): return after inflation

real_rate(7%/yr, 3%/yr)
# → 3.8835%/yr

See also: grow

payment

payment(loan: num|quantity, rate: quantity, time: quantity, compounding?: str): monthly payment that pays off a loan

payment($400000, 6.5%/yr, 30 yr)
# → $2,528.27/mo
payment($25000, 7%/yr, 5 yr) * 5 yr
# → $29,701.80

See also: payoff, amortize

payoff

payoff(balance: num|quantity, rate: quantity, payment: quantity, compounding?: str): how long a payment takes to clear a balance, in whole payments

payoff($5000, 22%/yr, $200/mo)
# → 34 mo
today + payoff($5000, 22%/yr, $200/mo)
# → 2029-08-08

See also: payment

amortize

amortize(loan: num|quantity, rate: quantity, time: quantity, opts?: map): payment schedule: {n, payment, interest, principal, balance} per month; opts {extra: $200/mo}

amortize($1000, 12%/yr, 3 mo)
# → [{n: 1, payment: $340.02, interest: $10.00, principal: $330.02, balance: $669.98}, {n: 2, payment: $340.02, interest: $6.70, principal: $333.32, balance: $336.66}, {n: 3, payment: $340.02, interest: $3.37, principal: $336.66, balance: $0.00}]
amortize($400000, 6.5%/yr, 30 yr, {extra: $300/mo}).len * 1 mo to yr
# → 22.4167 yr

See also: payment

share

share(sum: num|quantity, parts: int|list): split into parts that add up exactly, to the cent

share($100, 3)
# → [$33.34, $33.33, $33.33]
share($100, [2, 1, 1])
# → [$50.00, $25.00, $25.00]

See also: settle

settle

settle(paid: map): who pays whom so everyone paid the same

settle({ana: $120, ben: $0, cy: $30})
# → ["ben pays ana $50.00", "cy pays ana $20.00"]

See also: share

change

change(from: num|quantity, to: num|quantity): fractional change from one value to another

change($80, $100)
# → 0.25
change(80, 60).percent
# → "-25%"

See also: margin, cagr

margin

margin(cost: num|quantity, price: num|quantity): profit as a fraction of the price

margin($60, $100)
# → 0.4

See also: markup

markup

markup(cost: num|quantity, price: num|quantity): profit as a fraction of the cost

markup($60, $100)
# → 0.666667

See also: margin

More examples

finance

# pay by the hour, day, week, month and year
salary($25/h)
# → {hour: $25.00, day: $200.00, week: $1,000.00, month: $4,333.33, year: $52,000.00}
# mortgage payment
payment($400000, 6.5%/yr, 30 yr)
# → $2,528.27/mo
# interest over the loan
payment($400000, 6.5%/yr, 30 yr) * 30 yr - $400000
# → $510,177.95
# debt-free date
today + payoff($5000, 22%/yr, $200/mo)
# → 2029-08-08
# saving $500 a month
grow($0, 7%/yr, 30 yr, $500/mo)
# → $609,985.50
# split a bill
share($100, 3)
# → [$33.34, $33.33, $33.33]
# who owes whom
settle({ana: $120, ben: $0, cy: $30})
# → ["ben pays ana $50.00", "cy pays ana $20.00"]