Reference

Everything in the library

Every export of @ratmath/finance, with what it takes and what it returns. Amounts and rates go in as whole numbers, Core Rationals or strings ("1234.56", "7/8", "4.5%"); a JavaScript number that is not whole is refused. Results are Rationals when exact and RationalIntervals, proven to contain the value, when a root or an exponential is involved; functions that return intervals take digits.

Money, rounding, dates

ExportWhat it does
amount(x), rate(x)Read an exact amount or rate.
round(x, { places = 2, mode = "half-even" })Round by a rule: half-even (the default, MONEY_ROUNDING), half-up, half-down, up, down, floor, ceil, any Core mode name, a Core rounder or your own function; moneyRounder(mode) gives the Core rounder. See Money and rounding.
format(x, { places, mode, currency, separator, percent })An amount as text, rounded for display.
show(x, places)A Rational or an interval as a decimal; an interval prints as one number when its rounding is certain.
allocate(total, weights, { places })Shares that add up to the total exactly.
power(base, exponent, digits), exp(x, digits), ln(x, digits)Exact when possible, otherwise enclosed.
date(x), CalendarDateA calendar date: addDays, addMonths, compareTo, equals. See Dates and day counts.
daysBetween(a, b), dayCount(from, to, convention), DAY_COUNTS, isLeap(y)Days, and { days, yearFraction } under a convention.
FinanceErrorWhat the library throws, with a code: inexact, bad-number, bad-rounding, bad-date, no-solution, negative-amortisation, never-repaid, bad-flows, bad-bond, bad-curve, bad-scenario and others.

Time value

ExportWhat it does
simpleInterest(P, rate, time){ interest, total }.
compound(P, rate, years, { periodsPerYear })Growth at a nominal rate; periodsPerYear may be "continuous".
effectiveRate(nominal, m), nominalRate(effective, m), equivalentRate(nominal, from, to)Rates with the same annual growth.
realRate(nominal, inflation)Fisher's relation, exactly.
presentValue(fv, rate, n), futureValue(pv, rate, n), discountFactor(rate, n)One amount moved through n periods.
annuity({ payment, rate, periods, due, growth, deferred }){ presentValue, futureValue, total, payments }.
perpetuity({ payment, rate, growth, due, deferred })Present value.
tvm({ pv, fv, pmt, rate, n, due })Solves for the one left out. See Time value of money.
rateRoots(coefficients, { digits })Every rate r > −1 with Σ ck(1 + r)k = 0, proven: the solver behind tvm, irr and yields.

Loans and cash flows

ExportWhat it does
loan({ principal, rate, periods, periodsPerYear, payment, rounding, extra, interestOnly, balloon, rateChanges })A schedule: { payment, exactPayment, schedule, periods, finalPayment, balloon, totals }. See Loans.
levelPayment(balance, periodicRate, periods, balloon)The unrounded level payment.
compareLoans(a, b), refinance(current, proposed, { costs, rollIn })Side by side; break-even and savings.
loanAPR({ principal, fees, payment, periods, periodsPerYear }){ periodic, nominal, effective }.
revolving({ balance, rate, payment, purchases, rounding })A card balance run out.
npv(rate, flows), xnpv(rate, datedFlows, { dayCount })Net present value.
irr(flows), xirr(datedFlows, { dayCount, range })Every internal rate of return. See Cash flows.
mirr(flows, financeRate, reinvestRate), payback(flows, { rate })The modified rate; payback period.
realValue(nominal, inflation, n), nominalValue(real, inflation, n)Across inflation.
depreciation({ cost, salvage, life, method, factor, switchToStraightLine, units, rounding }), DEPRECIATIONA schedule by one of four methods.
taxSchedule(brackets, { rounding }){ on(income), brackets } from brackets you supply.

Bonds and curves

ExportWhat it does
bond({ face, coupon, frequency, redemption, periods | settlement, maturity, dayCount }), Bondprice(yield), yield(cleanPrice), duration(yield), cashflows, accrued. See Bonds.
bootstrap(bonds, { frequency })Exact discount factors from bond prices.
yieldCurve({ spots | discountFactors, frequency }), YieldCurvediscount(k), spot(k), forward(a, b), parYield(k), price(bond). See Yield curves.
immunise({ liability, yield, bonds })The split of two bonds that matches a liability's value and duration.

Scenarios

ExportWhat it does
scenario({ periods, periodsPerYear, start, accounts, flows, rounding }), Scenario.project() gives the table of balances. See Scenarios.
compare(scenarios, { measure })Outcomes side by side, differences and crossovers.
sensitivity(build, inputs, { measure })The exact derivative of the outcome in each input, ranked.
DualA value with its derivative, as passed to build: add, subtract, multiply, divide, pow.
planThe phases still to come, each { phase, contents, estimate }.

Uncertain inputs

ExportWhat it does
processes.fixed, independent, choice, sequence, resample, gbm, walk, meanReverting; ProcessPaths of growth factors from a seeded stream. See Uncertain inputs.
simulate(spec, { returns, inflation, indexed, events, runs, seed, … }), SimulationMany seeded runs: outcomes, mean, standardError, percentiles, quantile, ruin (exact interval), bands, real.
sequenceRisk(spec, { account, returns, shuffles })The same returns in different orders; orderMatters and spread.

Portfolios, options, life contingencies

ExportWhat it does
portfolio({ means, covariance } or { returns }), PortfolioexpectedReturn, variance, risk, minimumVariance, frontier, frontierLongOnly, tangency. See Portfolios.
capm, returnsFrom, solveExactBeta, alpha and required return; returns from prices; an exact linear solve.
strategy(legs), parity(…)Payoffs and exact break-even prices; put–call parity. See Options.
binomialTree(…)Exact European and American prices on a binomial tree; float: true for a preview.
blackScholes(…), impliedVolatility(…), normalCdf, normalPdfCertified values and sensitivities; σ by certified bisection.
lifeTable, deMoivre, LifeTableLife tables from l or q. See Life contingencies.
lifeAnnuity, lifeInsurance, pureEndowment, endowment, netPremium, reserveExact present values, premiums and reserves.
Try itEdit the code and run it with @ratmath/finance and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs