Catastrophic Cancellation
Subtracting two nearly equal floating-point numbers can destroy almost all of your precision at once — a quiet failure mode that shows up in P&L differences, Greeks, and numerical derivatives.
Prerequisites: Floating-Point Arithmetic and Precision
A risk system computes an option's delta by finite differences: price it with the spot bumped up a tiny amount, price it again with spot bumped down, subtract, divide by the bump size. The two prices are both computed to roughly 15-16 significant digits — but if they're nearly equal, most of those digits cancel out, and what's left is dominated by rounding error rather than the real signal. This is catastrophic cancellation: subtracting two close floating-point numbers can throw away almost all of your working precision in a single operation.
Floating-point numbers carry a fixed number of significant digits (about 15-17 for a standard double). When you subtract two numbers that agree in their first digits, those digits cancel exactly, but they take their precision budget with them — the result has roughly reliable digits left, not 15.
Why it happens
Each floating-point number already carries a tiny rounding error from how it was computed or stored, somewhere around the 16th significant digit. Subtraction itself is exact given two floating-point inputs — the danger is what the inputs already contained. If and , both numbers might individually be accurate to full double precision, but has thrown away 13 leading digits of agreement, and the relative error in that tiny result can be enormous, because the absolute rounding error in and (roughly relative to their size, so around absolute) is now comparable to the entire answer.
Worked example
Compute the numerical derivative of at using a central difference with a naive small step : . Mathematically the true derivative is . But and is nearly identical — both values are around , computed to about 16 significant digits, so their absolute precision floor is around . The true difference we need is on the order of — comparable to that noise floor. In practice this computation returns a derivative estimate with only 1-2 correct digits instead of the 6-8 a well-scaled version would give, purely because was too small relative to 's magnitude, and the subtraction cancelled far more than it should have.
What this means in practice
Catastrophic cancellation shows up in P&L attribution (today's portfolio value minus yesterday's, both huge numbers, difference tiny), numerical Greeks via finite differences, and variance computed as on data with a large mean and small spread — that formula is a textbook cancellation trap and is why NumPy's and most statistics libraries' variance implementations use a different, cancellation-resistant algorithm internally rather than that direct formula.
The fix is never "use more decimal places" — doubles already carry about 16 digits regardless of the numbers involved. The real fixes are algebraic: rearrange the formula to avoid the subtraction (e.g. compute variance as the mean of squared deviations from the mean, not ), or restructure so the subtraction happens on small, comparable-magnitude quantities rather than two large nearly-equal ones.
Related concepts
Practice in interviews
Further reading
- Goldberg, 'What Every Computer Scientist Should Know About Floating-Point Arithmetic' (1991)
- Higham, Accuracy and Stability of Numerical Algorithms