When you hold a book of options across dozens of underlyings, two questions matter more than any Greek: how much buying power is this costing me, and how much more can I sell before it costs more. Broker platforms answer the first as an opaque number and the second not at all.
The conventional way to compute the answer is to simulate: pick a grid of prices, value the book at each one, take the worst. That's approximate by construction (the true worst case can fall between your grid points), and it's slow enough that nobody runs it across a whole portfolio interactively.
For one underlying, one expiration, one right, the terminal book value is
V(P) = Σ qtyᵢ · max(0, P − Kᵢ). Every term is a hinge, and every
hinge bends at a strike. A sum of hinges is piecewise-linear whose only
breakpoints are those same strikes, so its minimum is attained
at a strike, at zero, or in the limit. Nowhere else.
That makes margin = max(0, −min V) a closed-form answer from an
O(n log n) sort and a single linear walk. No grid. No simulation.
No pricing model at all: margin at expiration doesn't need one.
Read the same walk from the other side and it stops being a risk number and
becomes a capacity number. If the payoff floor above spot sits F
points above water, a short vertical up to F wide adds
exactly zero margin. It is already paid for by structure you own.
Free width and distance-to-margin turn out to be the same quantity,
measured in opposite directions.
A risk tool that is confidently wrong is worse than no tool. Most of the design effort went into refusing to produce numbers that look trustworthy and aren't.
A naked short call has no worst case: V → −∞. That is
categorically different from "we couldn't compute it," and both are
different from a large finite number. Each is its own value in the type
system, so unbounded risk can never be rendered as a reassuring figure.
Composite scores divide by the weight of the signals that actually scored, not the total weight. A missing input drops out instead of silently counting as zero, and coverage is reported alongside the score. There's a named regression test for the case where this flips a ranking.
The global minimum is provably blind to anything on one side of spot: a
pure call book has V(0)=0, so closing the very vertical that
creates 90 points of width moves it by nothing. Every result therefore
carries both the global floor and the floor around spot, and never
collapses them into one.
Implied vol solves by bisection because Newton's method diverges where vega collapses toward zero: deep in or out of the money, exactly where a book accumulates. On a monotone function bisection cannot. Outside no-arbitrage bounds it returns nothing, which is a finding rather than a failure.
The algorithm document carries its own corrections in the open: three places where the original reasoning was wrong, what the symptom was, and what replaced it. The deep-ITM short vertical was first described as an interest-free loan against your own width; measuring it showed the interest term is real, so the spec now reports the signed number and explains it instead of clamping it to zero.
The worked example in the specification is asserted to exact equality (not within a tolerance) three independent ways: against a hand-built ladder, through the CSV parser, and through the rendered explanation text. If the three ever disagree, one of them is lying, and the test says which.
The engine deliberately refuses to merge positions across underlyings: legs
aggregate on (expiration, right, strike) with no symbol, and
multi-symbol input raises rather than netting. A real book holds the same
contract long in one name and short in another, and a silent merge would
produce a confident number for a portfolio nobody owns.
Two codebases, on purpose. A Rust workspace (shared options-core
library, an egui desktop front-end drawing payoff curves, and a thin CLI)
carries the classifier that decomposes a raw position list into the structures a
trader actually thinks in: calendars, diagonals, butterflies, condors, verticals,
straddles. It explodes positions into unit lots, converts strikes to integer
micro-dollars to sidestep float comparison, and greedily allocates them in priority
order, asserting as an invariant that every contract is fully accounted for.
Alongside it, a pure-standard-library Python prototype implements the newer margin and capacity algorithms as an executable specification: readable, exhaustively tested, and explicitly written to be translated rather than shipped. The arithmetic is meant to be ported; the printing is meant to be thrown away. Calling it a finished product would be a nicer story and a less accurate one.
This project stays closed-source: it is coupled to real brokerage exports, and the interesting parts of a risk engine are inseparable from the book they were built against. Every position, ladder, and figure on this page is invented for illustration. The mathematics is the part worth sharing, and it needs no holdings to demonstrate.