finance
money math: pay rates, savings growth, loan payments, investment returns, splitting bills, and profit margins
Money math for everyday questions about pay, savings, loans and splitting costs.
Every function here tells its arguments apart by unit, so they read like the question you’re asking. An amount of money like $1000 is a sum, money per time like $500/mo is a regular payment, a percentage per time like 7%/yr is an interest rate, and a time like 10 yr is how long. A word like “monthly” or “daily” says how often interest is added to the balance, where it starts earning interest itself.
good to know
Section titled “good to know”Without a word for it, interest is added with each payment when there are payments, as loans do, and otherwise once per period of the rate, so 7%/yr on its own compounds yearly.
Tags: money
salarya pay rate as pay per hour, day, week, month and yeargrowwhat money will be worth after time at the ratepresent_valuewhat a future sum, and any regular payments up to then, are worth today at the rateaprthe yearly rate quoted before compounding (annual percentage rate) that gives an effective yearly ratenpvthe net present value of a list of cash flows: each is discounted by the rate for every period since the first, which is nowirrthe rate at which a list of cash flows has a net present value of zero (internal rate of return), per flow periodloan_ratethe yearly rate of a loan from its monthly payment (the annual percentage rate, compounding monthly)depreciationa schedule of how an asset loses value over its life, a row per yearelasticityhow many percent demand changes per 1% change in price, for demand f at pricecagrthe steady yearly growth rate that would take start to end over time (compound annual growth rate)doublinghow long it takes money to double at the rateapythe yearly rate you really earn once compounding is included (annual percentage yield)real_ratewhat a return is really worth once inflation is taken outpaymentthe monthly payment that pays off a loan over time, interest includedpayoffhow long a regular payment takes to pay off a balance with interest, rounded up to whole paymentsamortizea loan’s month-by-month schedulesharesplit a sum into parts, in equal shares or by the weights in a list, rounded to the cent so they still add up exactlysettlegiven how much each person paid, the payments that even things out so everyone has paid the samechangehow much a value changed, as a fraction of where it startedmarginprofit as a fraction of the selling pricemarkupprofit as a fraction of what it cost you
Functions
Section titled “Functions”salary
Section titled “salary”salary(rate: quantity, hours: num = 40.0, weeks: num = 52.0) -> map
a pay rate as pay per hour, day, week, month and year
Assumes 40 hours a week and 52 paid weeks a year. Change them with hours and weeks
1salary($25/h){hour: $25.00, day: $200.00, week: $1,000.00, month: $4,333.33, year: $52,000.00}2salary(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(sum: num|quantity, rate: quantity, time: quantity, payment?: quantity|str, compounding?: str) -> float|quantity
what money will be worth after time at the rate
A starting sum, plus a regular payment if given, with interest compounding compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1grow($10000, 7%/yr, 30 yr)$76,122.552grow($0, 7%/yr, 30 yr, $500/mo)$609,985.503grow($1000, 5%/yr, 1 yr, "daily")$1,051.27present_value
Section titled “present_value”present_value(sum: num|quantity, rate: quantity, time: quantity, payment?: quantity|str, compounding?: str) -> float|quantity
what a future sum, and any regular payments up to then, are worth today at the rate
The reverse of grow: discounts the sum back over time, and adds what the payments are worth. compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1present_value($10000, 7%/yr, 10 yr)$5,083.492present_value($0, 5%/yr, 20 yr, $1000/yr)$12,462.21apr(apy: quantity, compounding: str) -> quantity
the yearly rate quoted before compounding (annual percentage rate) that gives an effective yearly rate
compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1apr(12.6825%/yr, "monthly")12%/yrSee also apy
npv(rate: quantity|num, flows: list) -> float|quantity
the net present value of a list of cash flows: each is discounted by the rate for every period since the first, which is now
The rate is per flow period, so use a yearly rate for yearly flows
1npv(10%/yr, [-$1000, $300, $400, $500])-$21.04See also irr, present_value
irr(flows: list) -> quantity
the rate at which a list of cash flows has a net present value of zero (internal rate of return), per flow period
1irr([-$1000, $300, $400, $500])8.89634%/yrSee also npv
loan_rate
Section titled “loan_rate”loan_rate(loan: num|quantity, payment: quantity, time: quantity) -> quantity
the yearly rate of a loan from its monthly payment (the annual percentage rate, compounding monthly)
1loan_rate($10000, $200/mo, 5 yr)7.4201%/yrSee also payment
depreciation
Section titled “depreciation”depreciation(cost: num|quantity, salvage: num|quantity, life: int, method?: str) -> list
a schedule of how an asset loses value over its life, a row per year
The method is “straight” (the same each year, the default), “sum_of_years” (more early on) or “declining” (double declining balance, never below the salvage value)
1depreciation($10000, $1000, 5)[{year: 1, depreciation: $1,800.00, value: $8,200.00}, {year: 2, depreciation: $1,800.00, value: $6,400.00}, {year: 3, depreciation: $1,800.00, value: $4,600.00}, {year: 4, depreciation: $1,800.00, value: $2,800.00}, {year: 5, depreciation: $1,800.00, value: $1,000.00}]2depreciation($10000, $1000, 5, "declining")[{year: 1, depreciation: $4,000.00, value: $6,000.00}, {year: 2, depreciation: $2,400.00, value: $3,600.00}, {year: 3, depreciation: $1,440.00, value: $2,160.00}, {year: 4, depreciation: $864.00, value: $1,296.00}, {year: 5, depreciation: $296.00, value: $1,000.00}]See also change
elasticity
Section titled “elasticity”elasticity(f: fn, price: num) -> float
how many percent demand changes per 1% change in price, for demand f at price
f takes a price and returns the quantity sold. Below -1 demand is elastic, so a price cut raises revenue
1elasticity(|p| 100 - 2 * p, 20)-0.666667cagr(start: num|quantity, end: num|quantity, time: quantity) -> quantity
the steady yearly growth rate that would take start to end over time (compound annual growth rate)
1cagr($1000, $2500, 8 yr)12.1353%/yrdoubling
Section titled “doubling”doubling(rate: quantity, compounding?: str) -> quantity
how long it takes money to double at the rate
compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1doubling(7%/yr)10.2448 yrSee also grow
apy(rate: quantity, compounding: str) -> quantity
the yearly rate you really earn once compounding is included (annual percentage yield)
compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1apy(5%/yr, "daily")5.12675%/yr2apy(5%/yr, "monthly")5.11619%/yrSee also grow
real_rate
Section titled “real_rate”real_rate(rate: quantity|num, inflation: quantity|num) -> quantity
what a return is really worth once inflation is taken out
1real_rate(7%/yr, 3%/yr)3.8835%/yrSee also grow
payment
Section titled “payment”payment(loan: num|quantity, rate: quantity, time: quantity, compounding?: str) -> quantity
the monthly payment that pays off a loan over time, interest included
compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1payment($400000, 6.5%/yr, 30 yr)$2,528.27/mo2payment($25000, 7%/yr, 5 yr) * 5 yr$29,701.80payoff
Section titled “payoff”payoff(balance: num|quantity, rate: quantity, payment: quantity, compounding?: str) -> quantity
how long a regular payment takes to pay off a balance with interest, rounded up to whole payments
compounding is “yearly”, “quarterly”, “monthly”, “weekly”, “daily” or “continuous”
1payoff($5000, 22%/yr, $200/mo)34 mo2today + payoff($5000, 22%/yr, $200/mo)2029-09-04See also payment
amortize
Section titled “amortize”amortize(loan: num|quantity, rate: quantity, time: quantity, extra?: num|quantity) -> list
a loan’s month-by-month schedule
For each payment, its number n, the payment, how much is interest and how much pays down the loan (principal), and the balance left. Pass extra, like $200/mo, to see the effect of paying extra
1amortize($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}]2amortize($400000, 6.5%/yr, 30 yr, extra: $300/mo).len * 1 mo to yr22.4167 yrSee also payment
share(sum: num|quantity, parts: int|list) -> list
split a sum into parts, in equal shares or by the weights in a list, rounded to the cent so they still add up exactly
1share($100, 3)[$33.34, $33.33, $33.33]2share($100, [2, 1, 1])[$50.00, $25.00, $25.00]See also settle
settle
Section titled “settle”settle(paid: map) -> list
given how much each person paid, the payments that even things out so everyone has paid the same
1settle({ana: $120, ben: $0, cy: $30})["ben pays ana $50.00", "cy pays ana $20.00"]See also share
change
Section titled “change”change(from: num|quantity, to: num|quantity) -> float
how much a value changed, as a fraction of where it started
From 80 to 100 is 0.25, a 25% rise
1change($80, $100)0.252change(80, 60).percent"-25%"margin
Section titled “margin”margin(cost: num|quantity, price: num|quantity) -> float
profit as a fraction of the selling price
1margin($60, $100)0.4See also markup
markup
Section titled “markup”markup(cost: num|quantity, price: num|quantity) -> float
profit as a fraction of what it cost you
1markup($60, $100)0.666667See also margin
More examples
Section titled “More examples”finance
Section titled “finance”1# pay by the hour, day, week, month and year2salary($25/h){hour: $25.00, day: $200.00, week: $1,000.00, month: $4,333.33, year: $52,000.00}3# the monthly payment on a 30-year mortgage4payment($400000, 6.5%/yr, 30 yr)$2,528.27/mo5# total interest paid over the loan6payment($400000, 6.5%/yr, 30 yr) * 30 yr - $400000$510,177.957# the date $200 a month clears a $5000 card balance8today + payoff($5000, 22%/yr, $200/mo)2029-09-049# saving $500 a month for 30 years at 7%10grow($0, 7%/yr, 30 yr, $500/mo)$609,985.5011# split a bill12share($100, 3)[$33.34, $33.33, $33.33]13# who owes whom14settle({ana: $120, ben: $0, cy: $30})["ben pays ana $50.00", "cy pays ana $20.00"]Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.