Skip to content

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.

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

  • salary a pay rate as pay per hour, day, week, month and year
  • grow what money will be worth after time at the rate
  • present_value what a future sum, and any regular payments up to then, are worth today at the rate
  • apr the yearly rate quoted before compounding (annual percentage rate) that gives an effective yearly rate
  • npv 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
  • irr the rate at which a list of cash flows has a net present value of zero (internal rate of return), per flow period
  • loan_rate the yearly rate of a loan from its monthly payment (the annual percentage rate, compounding monthly)
  • depreciation a schedule of how an asset loses value over its life, a row per year
  • elasticity how many percent demand changes per 1% change in price, for demand f at price
  • cagr the steady yearly growth rate that would take start to end over time (compound annual growth rate)
  • doubling how long it takes money to double at the rate
  • apy the yearly rate you really earn once compounding is included (annual percentage yield)
  • real_rate what a return is really worth once inflation is taken out
  • payment the monthly payment that pays off a loan over time, interest included
  • payoff how long a regular payment takes to pay off a balance with interest, rounded up to whole payments
  • amortize a loan’s month-by-month schedule
  • share 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
  • settle given how much each person paid, the payments that even things out so everyone has paid the same
  • change how much a value changed, as a fraction of where it started
  • margin profit as a fraction of the selling price
  • markup profit as a fraction of what it cost you
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

1
salary($25/h){hour: $25.00, day: $200.00, week: $1,000.00, month: $4,333.33, year: $52,000.00}
2
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}
Example outputCtrl+Enter to run

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”

1
grow($10000, 7%/yr, 30 yr)$76,122.55
2
grow($0, 7%/yr, 30 yr, $500/mo)$609,985.50
3
grow($1000, 5%/yr, 1 yr, "daily")$1,051.27
Example outputCtrl+Enter to run

See also cagr, payment

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”

1
present_value($10000, 7%/yr, 10 yr)$5,083.49
2
present_value($0, 5%/yr, 20 yr, $1000/yr)$12,462.21
Example outputCtrl+Enter to run

See also grow, npv

apr(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”

1
apr(12.6825%/yr, "monthly")12%/yr
Example outputCtrl+Enter to run

See 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

1
npv(10%/yr, [-$1000, $300, $400, $500])-$21.04
Example outputCtrl+Enter to run

See 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

1
irr([-$1000, $300, $400, $500])8.89634%/yr
Example outputCtrl+Enter to run

See also npv

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)

1
loan_rate($10000, $200/mo, 5 yr)7.4201%/yr
Example outputCtrl+Enter to run

See also payment

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)

1
depreciation($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}]
2
depreciation($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}]
Example outputCtrl+Enter to run

See also change

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

1
elasticity(|p| 100 - 2 * p, 20)-0.666667
Example outputCtrl+Enter to run

See also change, margin

cagr(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)

1
cagr($1000, $2500, 8 yr)12.1353%/yr
Example outputCtrl+Enter to run

See also grow, change

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”

1
doubling(7%/yr)10.2448 yr
Example outputCtrl+Enter to run

See 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”

1
apy(5%/yr, "daily")5.12675%/yr
2
apy(5%/yr, "monthly")5.11619%/yr
Example outputCtrl+Enter to run

See also grow

real_rate(rate: quantity|num, inflation: quantity|num) -> quantity

what a return is really worth once inflation is taken out

1
real_rate(7%/yr, 3%/yr)3.8835%/yr
Example outputCtrl+Enter to run

See also grow

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”

1
payment($400000, 6.5%/yr, 30 yr)$2,528.27/mo
2
payment($25000, 7%/yr, 5 yr) * 5 yr$29,701.80
Example outputCtrl+Enter to run

See also payoff, amortize

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”

1
payoff($5000, 22%/yr, $200/mo)34 mo
2
today + payoff($5000, 22%/yr, $200/mo)2029-09-04
Example outputCtrl+Enter to run

See also payment

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

1
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}]
2
amortize($400000, 6.5%/yr, 30 yr, extra: $300/mo).len * 1 mo to yr22.4167 yr
Example outputCtrl+Enter to run

See 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

1
share($100, 3)[$33.34, $33.33, $33.33]
2
share($100, [2, 1, 1])[$50.00, $25.00, $25.00]
Example outputCtrl+Enter to run

See also settle

settle(paid: map) -> list

given how much each person paid, the payments that even things out so everyone has paid the same

1
settle({ana: $120, ben: $0, cy: $30})["ben pays ana $50.00", "cy pays ana $20.00"]
Example outputCtrl+Enter to run

See also share

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

1
change($80, $100)0.25
2
change(80, 60).percent"-25%"
Example outputCtrl+Enter to run

See also margin, cagr

margin(cost: num|quantity, price: num|quantity) -> float

profit as a fraction of the selling price

1
margin($60, $100)0.4
Example outputCtrl+Enter to run

See also markup

markup(cost: num|quantity, price: num|quantity) -> float

profit as a fraction of what it cost you

1
markup($60, $100)0.666667
Example outputCtrl+Enter to run

See also margin

1
# pay by the hour, day, week, month and year
2
salary($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 mortgage
4
payment($400000, 6.5%/yr, 30 yr)$2,528.27/mo
5
# total interest paid over the loan
6
payment($400000, 6.5%/yr, 30 yr) * 30 yr - $400000$510,177.95
7
# the date $200 a month clears a $5000 card balance
8
today + payoff($5000, 22%/yr, $200/mo)2029-09-04
9
# saving $500 a month for 30 years at 7%
10
grow($0, 7%/yr, 30 yr, $500/mo)$609,985.50
11
# split a bill
12
share($100, 3)[$33.34, $33.33, $33.33]
13
# who owes whom
14
settle({ana: $120, ben: $0, cy: $30})["ben pays ana $50.00", "cy pays ana $20.00"]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.