Options
An option's payoff at expiry is a piecewise-linear function of the price, so strategies and their break-even prices are exact. A binomial tree with rational factors gives an exact price. The Black–Scholes formula involves logarithms, square roots and the normal distribution; its values come back as intervals proven to contain them.
strategy([{ type: "call", strike: 100, premium: 5 }, { type: "put", strike: 100, premium: 4 }]).breakEvens; // [91, 109]
binomialTree({ spot: 50, strike: 52, steps: 2, up: "6/5", down: "4/5", growth: "21/20", type: "put", style: "american" }).price;
const v = blackScholes({ spot: 100, strike: 100, rate: "5%", volatility: "20%", time: 1 });
show(v.call, 6); // "10.450584"
v.delta.call; // N(d1), enclosed
impliedVolatility({ price: "10.45", spot: 100, strike: 100, rate: "5%", time: 1 });
Payoffs and strategies
A call with strike K pays at expiry and a put pays . strategy(legs) combines calls, puts, the stock and a bond, each with a premium and a quantity (negative for a short position). Profit is linear between strikes, so each break-even price is found by solving a linear equation on each piece, exactly. The maximum profit and loss are read off the corners, or are unbounded when the last slope is not zero.
Put–call parity
A call bought and a put sold, both with strike K, pay at expiry, whatever happens. That is the same as holding the stock and owing K, so for European options on a stock without dividends
parity finds whichever of the four is missing. Given all four it returns the gap, which is zero when no arbitrage is possible. With continuous compounding is enclosed. With compounding: "annual" and whole years it is an exact fraction.
The binomial tree
In each step the price moves up by a factor u or down by d, and money grows by g. Holding Δ shares and some cash can copy the option's value in both outcomes, so its price is fixed. Equivalently, the price is the expected payoff discounted under the risk-neutral probability
which lies strictly between 0 and 1 exactly when . If that fails, the tree has an arbitrage and is refused. Working back from expiry gives the price as an exact fraction. For an American option, each node also compares the value of exercising now; the nodes where that wins are listed in earlyExercise. Without dividends an American call is never exercised early, and the tests check that its price equals the European one exactly.
Given a volatility instead, the Cox–Ross–Rubinstein tree takes , , . These are rounded to 8 decimal places, and the result says rounded: true. The exact tree's fractions grow with every step, so 100 steps take about a second. float: true runs the same induction in floating point for a quick preview.
Black–Scholes
As the steps shrink the tree's price converges to the Black–Scholes value
and . Here N is the normal distribution function, computed as from analytic's certified error function. Every quantity is an interval proven to contain the true value. That includes the sensitivities: delta , gamma , vega , theta and rho. A dividend yield q replaces S by .
The price rises with volatility, since vega is positive. So the implied volatility, the σ that reproduces a market price, can be found by bisection. Each step decides from certified values which half the answer is in, and the result is an interval proven to contain it.
| call | returns |
|---|---|
| strategy(legs) | { payoff(S), profit(S), cost, kinks, breakEvens, maxProfit, maxLoss } |
| parity({ call, put, spot, strike, rate, time, compounding }) | the missing one, or { gap, holds }; prices may be enclosures, such as blackScholes(…).call |
| binomialTree({ spot, strike, steps, type, style, up, down, growth } or { volatility, time, rate }) | { price, probability, delta, earlyExercise, rounded, tree } |
| blackScholes({ spot, strike, rate, volatility, time, dividendYield }) | { call, put, d1, d2, delta, gamma, vega, theta, rho }, all enclosed |
| impliedVolatility({ price, type, spot, strike, rate, time, digits }) | an interval containing σ |
| normalCdf(x), normalPdf(x) | enclosures |
@ratmath/finance and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.