Prices are computed by generic kernel code (curves, interpolators, pricers) that is written once and run with different kinds of numbers: plain numbers for fast pricing, and numbers recorded on a tape for exact sensitivities by adjoint algorithmic differentiation (AAD). This chapter defines that number type, how AAD computes derivatives, the root finder used by curve building, the interpolation methods, least-squares fitting, the normal distribution, the Black and Bachelier implied volatilities, and the Black–Scholes–Merton price on a spot. Iterative solvers run on plain numbers, and their sensitivities come from the implicit function theorem (applied with the curves), never from recording their iterations.
5.1 Notation
| Symbol | Meaning |
|---|---|
| \(v_1, \dots, v_N\) | The numbers recorded on a tape, in the order they were computed |
| \(\varphi_k\) | The operation that computed \(v_k\) from at most two earlier numbers |
| \(v_{a(k)}\), \(v_{b(k)}\) | The arguments of \(\varphi_k\) |
| \(\partial_a \varphi_k\), \(\partial_b \varphi_k\) | The local derivatives of \(\varphi_k\) with respect to its arguments |
| \(y = v_m\) | The result whose derivatives are wanted |
| \(\bar{v}_k\) | The adjoint of \(v_k\): \(\partial y / \partial v_k\) |
| \(x_0 < \dots < x_n\), \(y_0, \dots, y_n\) | Interpolation nodes and values |
| \(w\) | Interpolation weight, \(0 \le w < 1\) |
| \(r(x)\), \(J\), \(C(x)\), \(g\) | Residuals of a fit, their Jacobian, the cost \(\tfrac12\lVert r \rVert^2\) and its gradient \(J^\top r\) |
| \(\mu\), \(D\), \(\rho\) | Levenberg–Marquardt damping, column scaling and gain ratio |
| \(\varphi\), \(\Phi\), \(Y = \Phi/\varphi\) | Standard normal density, distribution function and their ratio |
| \(\operatorname{erfcx}(z)\) | Scaled complementary error function \(e^{z^2}\operatorname{erfc}(z)\) |
| \(F\), \(K\), \(T\), \(\sigma\), \(\theta\) | Forward, strike, time to expiry in years, volatility, \(+1\) for a call and \(-1\) for a put |
| \(x\), \(s\), \(h\), \(t\) | Log-moneyness \(\ln(F/K)\), total volatility \(\sigma\sqrt T\), \(x/s\) and \(s/2\) |
| \(b(x, s)\), \(\beta\) | Normalised out-of-the-money Black price, and its target value |
| \(S\), \(r\), \(q\) | Spot price, continuously compounded rate and dividend yield |
| \(\Delta\), \(\Gamma\), \(\mathcal V\), \(\Theta\), \(\rho\) | Sensitivities of a spot option to the spot, the spot twice, the volatility, time passing and the rate |
5.2 Numbers
Kernel code computes with a number type that offers exactly: addition, subtraction, multiplication and division (between two numbers, or a number and a constant), negation, \(\exp\), \(\ln\), \(\sqrt{\cdot}\), a power with a constant exponent, and \(\max\) and \(\min\) of two numbers. It deliberately offers no comparisons: kernel code must not choose what to compute from a value, so that the same code also runs on a Monte Carlo graph where a "value" is a whole vector of paths. Where a calculation needs a choice, it uses \(\max\) or \(\min\), or a smoothed version. A choice based on data that is not a number of this type (times, schedules, counts) is allowed.
Two number types exist:
- a plain number, which computes values only, as ordinary double-precision arithmetic;
- an AAD number (Section 5.3), which computes the same values and records each operation so that derivatives can be computed afterwards.
A constant is a number that does not depend on any input being differentiated (for example a cash-flow amount or a time). Constants are never recorded.
5.3 Adjoint algorithmic differentiation
Recording. When a calculation runs with AAD numbers, every operation appends one node to a tape: the index of each argument and the operation's local derivatives at the current values. Node \(k\) stores
with a missing argument for operations of one number (and for the inputs themselves, which have none). An operation involving a constant records only its non-constant argument.
Adjoint sweep. The derivatives of a result \(y = v_m\) with respect to every recorded number are computed in one pass over the tape, backwards from \(m\):
In words: each node passes its adjoint, multiplied by its local derivatives, back to its arguments. Because every node only refers to earlier nodes, one backward pass suffices, and its cost is a small multiple of the cost of the calculation itself, whatever the number of inputs. That is why a full bucketed risk is cheap. The adjoint \(\bar{v}_i\) of an input is the derivative \(\partial y / \partial v_i\).
Local derivatives of each operation:
At a tie, \(\max\) and \(\min\) pass the whole derivative to their first argument: the derivative of a kink is a choice, and this one is documented and tested.
5.4 Tapes and threads
A tape is a recording in progress, so it belongs to one thread at a time:
- each thread or task computing sensitivities uses its own tape, typically one per batch of trades, taken from a pool and reset after use (a reset keeps the tape's memory, so repeated calculations do not create garbage);
- every AAD number carries a reference to its tape, so nothing is shared between threads behind the scenes; combining numbers from two tapes, or from before a reset, is an error;
- the inputs shared between threads (dates, calendars, schedules, and later curves with their implicit-function-theorem matrices) are immutable and are read concurrently without locks.
Plain-number calculations keep no state at all and run in parallel freely.
5.5 Root finding: Brent's method
Curve building solves equations of one unknown, \(f(x) = 0\). Brent's method finds a root of a continuous function \(f\) in an interval \([l, u]\) where it changes sign, \(f(l)\,f(u) < 0\).
The method keeps a bracket \([a, b]\) that always contains a root, with \(b\) the best estimate (\(|f(b)| \le |f(a)|\)), \(c\) the previous value of \(b\) and \(d\) the one before. Each step tries a fast estimate \(s\):
inverse quadratic interpolation through \((a, f(a))\), \((b, f(b))\), \((c, f(c))\) when the three function values differ:
\[s = \frac{a f_b f_c}{(f_a - f_b)(f_a - f_c)} + \frac{b f_a f_c}{(f_b - f_a)(f_b - f_c)} + \frac{c f_a f_b}{(f_c - f_a)(f_c - f_b)},\]otherwise the secant step \(s = b - f_b\,(b - a)/(f_b - f_a)\);
and falls back to bisection, \(s = (a + b)/2\), when \(s\) is not between \((3a + b)/4\) and \(b\), or when the step would not at least halve the previous step (measured from \(b\) to \(c\) after a bisection, from \(c\) to \(d\) otherwise), or when that previous step is already below the tolerance. Then \(f(s)\) replaces whichever end of the bracket has the same sign, and \(a\) and \(b\) are swapped if needed so that \(b\) stays the best estimate.
The search stops when \(|b - a|\) is at most the tolerance \(\varepsilon\) (default \(10^{-12}\)) or \(f\) is exactly zero, and returns \(b\). Bisection guarantees convergence; the interpolation steps make it fast near a smooth root. It is an error when \(f\) has the same sign at both ends, is not a number there, or the iteration limit (default 100) is reached.
5.6 Interpolation
Interpolators turn values \(y_0, \dots, y_n\) at strictly increasing nodes \(x_0 < \dots < x_n\) into a value \(I(x)\) at any \(x\), and its derivative \(I'(x)\) with respect to the position. For \(x_i \le x < x_{i+1}\) the interval has width \(h_i = x_{i+1} - x_i\), the weight is \(w = (x - x_i)/h_i\), and the secant slope is \(\delta_i = (y_{i+1} - y_i)/h_i\). Node positions and values must be finite, and a position \(x\) that is not a number is an error rather than a value at an end node. At a node the interpolated value is the node value exactly; the derivative at a node is that of the interval to its right, and of the interval to its left at the last node.
Extrapolation. Every interpolator carries one of three policies for \(x < x_0\) and \(x > x_n\):
- Flat: the end value is held, \(I(x) = y_0\) or \(y_n\), and \(I'(x) = 0\).
- Linear: the end slope continues, \(I(x) = y_n + I'(x_n)\,(x - x_n)\) and likewise at \(x_0\). For the log interpolators below the slope is that of the logarithm, so a discount curve keeps its end forward rate (Equation (7.3)).
- None: a position outside the nodes is an error.
With a single node every policy gives the node value and a zero derivative.
Linear:
Its derivative with respect to the node values is the weight: \(1 - w\) for \(y_i\), \(w\) for \(y_{i+1}\), and zero for the others.
Log-linear, for positive values such as discount factors \(P\): the logarithm is interpolated linearly,
For discount factors against time this gives a constant continuously compounded forward rate \(\ln(y_i / y_{i+1})/h_i\) between nodes. The derivative with respect to \(y_i\) is \(\Lambda(x)\,(1 - w)/y_i\), and with respect to \(y_{i+1}\) it is \(\Lambda(x)\, w / y_{i+1}\). Values of zero or less are not allowed (their logarithm does not exist).
Piecewise constant, for step functions such as hazard rates, spreads and fixings: on \(x_i < x < x_{i+1}\) the value is carried forward from the left node or backward from the right node,
At a node both variants give the node value. The derivative is zero everywhere, so the linear and flat policies coincide.
Cubic Hermite. On each interval the cubic through \((x_i, y_i)\) and \((x_{i+1}, y_{i+1})\) with prescribed slopes \(m_i\) and \(m_{i+1}\) at the nodes:
with \(H'(x) = \big(h_{00}'(w)\, y_i + h_{01}'(w)\, y_{i+1}\big)/h_i + h_{10}'(w)\, m_i + h_{11}'(w)\, m_{i+1}\), where the prime on \(h_{\cdot}\) is the derivative in \(w\). The curve passes through every node and its first derivative is continuous, whatever the slopes. The slopes are estimated from the node values once, by one of four schemes:
- Natural spline: the slopes that make the second derivative continuous and zero at both ends. With \(M_i\) the second derivative at node \(i\), \(M_0 = M_n = 0\) and, for \(i = 1, \dots, n - 1\),
a tridiagonal system solved by elimination; then \(m_i = \delta_i - h_i (2 M_i + M_{i+1})/6\) for \(i < n\) and \(m_n = \delta_{n-1} + h_{n-1} (M_{n-1} + 2 M_n)/6\). Smooth, but not local: a change at one node moves the whole curve.
- Parabolic (Bessel): the slope at a node of the parabola through it and its two neighbours, and at the ends of the parabola through the first (last) three nodes:
Local, and exact for quadratic data.
- Kruger: the harmonic mean of the neighbouring secants, zero where they differ in sign, with Kruger's end condition:
- Fritsch–Butland: the weighted harmonic mean, zero where the secants differ in sign, with the end secants as end slopes:
Kruger and Fritsch–Butland keep monotone data monotone by construction; with equal widths they coincide. With two nodes every scheme is the straight line.
Monotonicity filter (Hyman). Any scheme's slopes may be filtered so that monotone data give a monotone curve: at an interior node,
and at each end the slope is clamped between \(0\) and \(3\delta\) of the single neighbouring secant, with its sign. The sign tests in the Kruger, Fritsch–Butland and Hyman rules are decided once, from the node values, when the interpolator is built; the sensitivities of the result to the node values are those of the chosen branch, exactly as for \(\max\) and \(\min\). A sensitivity taken where a secant changes sign is therefore one-sided.
Log-cubic, for positive values: the cubic Hermite of the logarithms,
with any slope scheme and the filter applied to \(\ln y\). For discount factors the forward rate \(-\Lambda_3'/\Lambda_3\) is then continuous at the nodes, which log-linear interpolation does not achieve.
Monotone convex (Hagan and West). The node values are the integrals of a rate, and the interpolator draws a continuous rate \(I'(x)\) whose average over each interval is the interval's secant slope \(\delta_i\) and which is monotone where the secants are; \(I(x)\) is its integral from the node. The shapes and their integrals are defined in Section 7.8, where the method is used for discount curves with \(y = \ln P\) and \(f = -I'\). The shape of each interval is chosen from the node values when the interpolator is built. The linear policy continues the end rate.
5.7 Worked examples
| Calculation | Result |
|---|---|
| Root of \(x^2 - 2\) on \([0, 2]\) | \(1.41421356237\ldots = \sqrt{2}\) |
| Root of \(\cos x - x\) on \([0, 1]\) | \(0.73908513321\ldots\) |
| Zero rate \(r\) with \(e^{-2r} = 0.95\), on \([-0.5, 0.5]\) | \(-\ln(0.95)/2 = 0.02564664719\ldots\) |
| Linear, nodes \((0.5, 1), (1, 3), (2, 2), (5, 8)\), at \(x = 1.5\) | \(2.5\) |
| Same, at \(x = 3\) (\(w = 1/3\)) | \(4\); derivatives \((0, 0, 2/3, 1/3)\) |
| Same, at \(x = 0\) and \(x = 9\), flat policy | \(1\) and \(8\) (end values held) |
| Same, linear policy (end slopes \(4\) and \(2\)) | \(-1\) at \(x = 0\); \(16\) at \(x = 9\) |
| Log-linear, \(P(1) = 0.98\), \(P(2) = 0.95\), at \(t = 1.5\) | \(\sqrt{0.98 \times 0.95} = 0.96488341\ldots\) |
| Same, at \(t = 3\), linear policy | \(0.95^2 / 0.98 = 0.92091837\ldots\) (forward rate \(\ln(0.98/0.95)\) continues) |
| Piecewise constant, nodes \((1, 0.01), (2, 0.02), (4, 0.04)\), at \(x = 3\) | \(0.02\) forward-flat, \(0.04\) backward-flat |
| Natural spline, nodes \((0, 0), (1, 1), (2, 0)\) | \(M_1 = -3\); slopes \((1.5, 0, -1.5)\); \(H(0.5) = 0.6875\), \(H'(0.5) = 1.125\) |
| Parabolic scheme, same nodes | slopes \((2, 0, -2)\); \(H(x) = 2x - x^2\) exactly, \(H(0.5) = 0.75\) |
| Kruger, nodes \((0, 0), (1, 1), (2, 3), (3, 4)\) (secants \(1, 2, 1\)) | slopes \((5/6, 4/3, 4/3, 5/6)\) |
| Fritsch–Butland, same nodes | slopes \((1, 4/3, 4/3, 1)\) |
| Hyman filter on the natural slopes of \((0, 0), (1, 1), (2, 1.05), (3, 3)\) | interior slopes clamped to \(3 \times 0.05 = 0.15\) |
| Derivative of \(x^3\) at \(x = 3\) by AAD | \(27\) |
For the linear example at \(x = 3\): the node interval is \([2, 5]\), so \(w = (3 - 2)/(5 - 2) = 1/3\) and \(L(3) = \tfrac{2}{3} \times 2 + \tfrac{1}{3} \times 8 = 4\).
For the natural spline: the secants are \(\delta_0 = 1\) and \(\delta_1 = -1\), so Equation (5.9) at the single interior node reads \(4 M_1 = 6(-1 - 1)\), \(M_1 = -3\); then \(m_0 = 1 - (0 - 3)/6 = 1.5\), \(m_1 = -1 - (-6 + 0)/6 = 0\) and \(m_2 = -1 + (-3 + 0)/6 = -1.5\). At \(x = 0.5\), \(w = 0.5\) and Equation (5.7) gives \(0.5 \times 0 + 0.125 \times 1.5 + 0.5 \times 1 - 0.125 \times 0 = 0.6875\). The parabolic scheme gives the slopes \(2, 0, -2\) of \(2x - x^2\) and reproduces it.
5.8 Least squares: QR and Levenberg–Marquardt
A least-squares fit looks for parameters \(x = (x_1, \dots, x_n)\) that make \(m \ge 1\) residuals \(r_i(x)\) (for example model price minus market price of each calibration instrument) as small as possible together:
\(C\) is the cost, \(J = \partial r/\partial x\) the \(m \times n\) Jacobian (row \(i\) holds the derivatives of \(r_i\)) and \(g = J^\top r\) the gradient of the cost. When there are as many residuals as parameters and an exact fit exists, Newton's method (Section 5.5) is the right tool; least squares is for fits with more quotes than parameters, or no exact fit, such as smoothed curves and volatility smiles.
Linear least squares by QR. For a linear model \(r = A x - b\) the minimum solves the normal equations \(A^\top A\, x = A^\top b\), but forming \(A^\top A\) squares the condition number of \(A\) and loses up to twice as many digits. Instead, Householder reflections factor \(A = Q R\) with \(Q\) orthogonal and \(R\) upper triangular (the first \(n\) rows of an \(m \times n\) triangle). Since \(Q\) preserves lengths,
found by back substitution. Reflection \(k\) is \(H_k = I - v v^\top / v_k\) with \(v\) the \(k\)-th column below the diagonal divided by \(\pm\) its length (the sign of the diagonal entry, so that nothing cancels) and \(v_k\) increased by one; it maps that column onto \(\mp \lVert a_k \rVert e_k\). A column whose remaining length is at most \(10^{-14}\) times the largest entry of \(A\) makes \(A\) rank deficient, which is an error.
Levenberg–Marquardt. For nonlinear residuals each step linearises, \(r(x + \delta) \approx r + J \delta\), and adds a penalty on long steps (Levenberg, 1944; Marquardt, 1963):
solved as one linear least-squares problem of \(m + n\) rows by Equation (5.16), again without normal equations (Moré, 1978). The damping \(\mu > 0\) moves the step between Gauss–Newton (\(\mu \to 0\)) and a short gradient step (\(\mu\) large); the stacked matrix always has full rank, so a step always exists. The diagonal scaling \(D\) makes the method independent of the units of the parameters (Moré, 1978):
the largest length column \(j\) of the Jacobian has had, and \(1\) for a column that has always been zero.
A trial point \(x + \delta\) is judged by the gain ratio, the actual reduction of the cost over the reduction the linear model predicts:
where the denominator is \(\tfrac12 \lVert r \rVert^2 - \tfrac12 \lVert r + J\delta \rVert^2\) rewritten with the step equation, and is positive. If \(\rho > 0\) the step is accepted and the damping shrinks smoothly; otherwise the step is rejected and the damping grows ever faster (Nielsen's update, as given by Madsen et al. (2004)):
The method starts with \(\mu = 10^{-3}\) and \(\nu = 2\). A trial point where a residual or the Jacobian is not finite (a parameter outside the model's domain) counts as rejected. It stops, returning the current point, when
- the cost is zero, or every entry of the gradient is at most the gradient tolerance (zero by default, since the gradient carries the units of the residuals); or
- the step length is at most \(\varepsilon_x (\lVert x \rVert + \varepsilon_x)\) with the step tolerance \(\varepsilon_x = 10^{-12}\) by default; or
- a step that the linear model predicted well (\(\rho > \tfrac34\)) reduces the cost by at most the fraction \(\varepsilon_C = 10^{-14}\) of it (a small gain on a poorly predicted, heavily damped step says nothing about the optimum, so it only raises the damping);
and it is an error to need more trial steps than the limit (200 by default). There are no bounds on the parameters: a calibration maps constrained parameters to free ones itself (for example a correlation \(\rho = \tanh u\)).
Sensitivities. The iterations are never differentiated. At the solution \(x^*(q)\) of a fit to quotes \(q\) the gradient vanishes, \(J^\top r = 0\); differentiating that condition in \(q\) gives
For an exact fit the residuals are zero and only the first terms remain, the Gauss–Newton form \(-(J^\top J)^{-1} J^\top \partial r/\partial q\). The solution returns the residuals and the Jacobian at \(x^*\) so that a calibration can apply either form; when residuals stay large the second-order terms matter, and the calibration that needs them computes them.
Worked examples. Rosenbrock's valley as residuals \(r_1 = 10(x_2 - x_1^2)\), \(r_2 = 1 - x_1\) from \((-1.2, 1)\) reaches \((1, 1)\). Fitting \(e^a\) to the data \(1, 2, 4.5\) has the optimum \(e^a = 2.5\), the mean, so \(a = \ln 2.5 = 0.91629073\ldots\) with cost \(\tfrac12(1.5^2 + 0.5^2 + 2^2) = 3.25\). The straight line through \((0, 1), (1, 3), (2, 4), (3, 4)\) in the least-squares sense is \(y = 1.5 + t\).
5.9 Normal distribution
The standard normal density and distribution function are \(\varphi(x) = e^{-x^2/2}/\sqrt{2\pi}\) and \(\Phi(x) = \int_{-\infty}^x \varphi(u)\, du\). Option formulas need \(\Phi\) with full relative accuracy deep in the lower tail: a far out-of-the-money option is worth a tiny \(\Phi(x)\), and \(1 - \Phi(-x)\) would lose every digit. So \(\Phi\) is built on the scaled complementary error function \(\operatorname{erfcx}(z) = e^{z^2} \operatorname{erfc}(z)\), a smooth function that decays like \(1/(z\sqrt{\pi})\):
where \(E(w) = \operatorname{erf}(\sqrt w)/\sqrt w\). The factor \(e^{-x^2/2}\) is computed as \(e^{-a^2/2}\, e^{-(x - a)(x + a)/2}\) with \(a\) the multiple of \(1/16\) nearest \(x\) towards zero: \(a^2\) is exact in floating point, so the rounding of \(x^2\) (which would cost a relative \(x^2\) units in the last place) is avoided. Beyond \(|x| = 40\) the factor is zero.
Chebyshev fits. \(E\) on \(w \in [0, \tfrac14]\) and \(\operatorname{erfcx}\) on
the intervals \([\tfrac12, 1], [1, 2], [2, 4], [4, 8], [8, 16]\) are Chebyshev
series \(\sum_{j=0}^{N} c_j T_j(t)\) in \(t = (2z - a - b)/(b - a)\) on each
interval \([a, b]\), evaluated by Clenshaw's recurrence. The coefficients were
fitted for this library (2026-10-14) by interpolation at the \(N + 1\)
Chebyshev points \(\cos(\pi (k + \tfrac12)/(N + 1))\) with mpmath 1.4.1 at 50
significant digits, increasing \(N\) until the last coefficient is below
\(10^{-18}\) of the first; the rounded coefficients reproduce the function to a
relative \(9 \times 10^{-17}\) or better on 201 points per interval
(degrees 10, 15, 18, 20, 23 and 24). The script tools/fit-normal-coefficients.py
regenerates the coefficients, repeats this check in double precision
(about \(2 \times 10^{-16}\), the evaluation's own rounding included) and prints
the reference values of the tests. Beyond \(z = 16\) the asymptotic series
is used, accurate to \(10^{-17}\) there; the reflection on the right serves negative arguments and overflows below about \(-26.6\).
The ratio \(Y = \Phi/\varphi\). Option formulas below use \(Y(x) = \Phi(x)/\varphi(x) = \sqrt{\pi/2}\, \operatorname{erfcx}(-x/\sqrt2)\) and its derivative \(Y'(x) = 1 + x\,Y(x)\) (from \(\varphi' = -x \varphi\)). For large negative \(x\) that sum cancels (at \(x = -10\), \(xY = -0.99\)), so for \(x \le -2\) the derivative comes from Laplace's continued fraction for the Mills ratio \(R(z) = \Phi(-z)/\varphi(z)\), \(z = -x\):
where the last form has no subtraction. The fraction is evaluated from depth \(20 + \lfloor 800/z^2 \rfloor\) upwards (160 levels reach full precision at \(z = 2\), 20 at \(z = 10\)); beyond \(z = 10^8\), \(Y' = 1/z^2\).
Inverse. \(\Phi^{-1}(p)\) for \(0 < p \le \tfrac12\) starts from the rational approximation 26.2.23 of Abramowitz and Stegun (1964) (absolute error below \(4.5 \times 10^{-4}\)), \(t = \sqrt{-2 \ln p}\), \(x_0 = -\left(t - \frac{2.515517 + 0.802853 t + 0.010328 t^2}{1 + 1.432788 t + 0.189269 t^2 + 0.001308 t^3}\right)\), and applies Halley's method on the accurate \(\Phi\), which converges cubically:
stopping when the change is below \(10^{-16} |x|\) (two steps in practice, four at most). For \(p > \tfrac12\), \(\Phi^{-1}(p) = -\Phi^{-1}(1 - p)\), where \(1 - p\) is exact; \(p = 0\) and \(p = 1\) give \(\mp\infty\), and \(p\) outside \([0, 1]\) is an error.
Worked examples (mpmath at 50 digits agrees to the digits shown): \(\Phi(-1) = 0.158655253931457\), \(\Phi(-10) = 7.61985302416053 \times 10^{-24}\), \(\Phi(-37) = 5.72557122252458 \times 10^{-300}\), \(\operatorname{erfcx}(1) = 0.427583576155807\), \(Y'(-10) = 0.00971403528268079\), \(\Phi^{-1}(0.01) = -2.32634787404084\) and \(\Phi^{-1}(10^{-300}) = -37.0470962993612\).
5.10 Black implied volatility
Black's formula. For a forward \(F > 0\), strike \(K > 0\), time to expiry \(T \ge 0\) and lognormal volatility \(\sigma \ge 0\), the undiscounted price of a call (\(\theta = 1\)) or put (\(\theta = -1\)) is (Black, 1976)
A discounted premium is divided by the discount factor first; a shifted lognormal model is the same formula with the shift added to \(F\) and \(K\). The implied volatility is the \(\sigma\) that reproduces a given \(V\). It exists and is unique when \(V\) lies strictly between the intrinsic value \(\max(\theta(F - K), 0)\) and the upper bound (\(F\) for a call, \(K\) for a put); \(V\) equal to the intrinsic value gives \(\sigma = 0\), and any other price is an error. The method follows Jäckel's "Let's Be Rational" (Jäckel, ).
Normalisation. With \(x = \ln(F/K)\), the total volatility \(s = \sigma\sqrt T\), \(h = x/s\) and \(t = s/2\), the price divided by \(\sqrt{FK}\) depends on \(x\) and \(s\) only. Subtracting the intrinsic value leaves the price of the out-of-the-money option of the same strike (put–call parity), and that depends on \(x\) only through \(-|x|\). So every inversion reduces to the normalised out-of-the-money call with \(x \le 0\):
with \(V = \max(\theta(F - K), 0) + \sqrt{FK}\, b(-|x|, s)\) and \(b' = \partial b/\partial s\) below. The second form follows from \(e^{\pm x/2}\Phi(h \pm t) = Y(h \pm t)\, e^{-(h^2 + t^2)/2}/\sqrt{2\pi}\) (as \(x/2 = h t\)). Near the money \(x\) is computed as \(\ln(1 + r)\) with \(r = (F - K)/K\), evaluated as \(\ln(u)\, r/(u - 1)\) with \(u = 1 + r\) (Goldberg, 1991, theorem 4), because \(\ln(F/K)\) would carry an absolute rounding error of one unit, large relative to a small \(x\).
Evaluating \(b\) without cancellation. The difference \(Y(h + t) - Y(h - t)\) cancels when \(t\) is small compared with \(|h|\). Four regions avoid that, with the limits of Jäckel () (checked by the tests):
\(h + t < -10 + 0.21\) (the paper's \(|h| > 10\) and \(t < |h| - 10 + \tau_{\text{small}}\)): both arguments are far in the tail, where \(Y(z) = -\sum_{k \ge 0} (-1)^k (2k-1)!!\, z^{-(2k+1)}\). Each difference of powers is written without subtraction, with \(u = 1/(h - t)\) and \(w = 1/(h + t)\):
\[Y(h + t) - Y(h - t) = 2t\, u w \sum_{k \ge 0} (-1)^k (2k - 1)!!\; H_{2k}(u, w), \qquad H_n(u, w) = \sum_{i=0}^{n} u^i w^{n-i} ,\](5.28)whose terms are all positive; \(H_n = w H_{n-1} + u^n\). The series is summed until a term is below \(10^{-17}\) of the sum.
Otherwise, \(t < 0.21\): the odd part of the Taylor series of \(Y\) around \(h\),
\[Y(h + t) - Y(h - t) = 2 \sum_{k \text{ odd}} Y^{(k)}(h)\, \frac{t^k}{k!}, \qquad Y^{(n+1)} = h\, Y^{(n)} + n\, Y^{(n-1)} ,\](5.29)starting from \(Y\) and the accurate \(Y'\) of Equation (5.24). The recurrence follows from \(Y' = 1 + hY\); it loses a factor \(|h|\) per step, but the terms carry \(t^k/k!\), so the loss stays below a few units in the last place for \(|h| < 10.3\) and \(t < 0.21\).
Otherwise, \(h + t > 0.85\): the plain first form of Equation (5.27), where \(e^{-x}\Phi(h - t)/\Phi(h + t)\) stays below about \(0.25\).
Otherwise the difference of \(Y\) values directly,
\[Y(h + t) - Y(h - t), \qquad Y(z) = \sqrt{\pi/2}\, \operatorname{erfcx}(-z/\sqrt 2),\](5.30)which loses at most about a decimal digit in this region.
The factor \(b' = e^{-(h^2 + t^2)/2}/\sqrt{2\pi}\) has the rounding error of its exponent: in the far wings a price \(e^{-E}\) is accurate to a relative \(E\) units in the last place. This does not affect the implied volatility, whose relative error is that of the price divided by \(\partial \ln b/\partial \ln s \approx 2E\).
Derivatives in \(s\). The normalised vega and the ratios of higher derivatives are explicit:
and the Black vega is \(\partial V/\partial \sigma = \sqrt{FK}\,\sqrt T\, b'\). The vega is largest at \(s_c = \sqrt{2|x|}\), where \(b''\) vanishes.
Branches. With \(b_c = b(x, s_c)\) and \(v_c = b'(x, s_c)\), the tangent at the inflection point meets \(b = 0\) at \(s_l\) and \(b = b_{\max}\) at \(s_u\):
They divide \((0, b_{\max})\) into four branches, each with its own starting point \(s_0\) and its own objective \(g(s)\), chosen so that \(g\) is nearly linear in \(s\) on the branch and the iteration converges fast:
| Branch | Range of \(\beta\) | Starting point | Objective \(g(s)\) |
|---|---|---|---|
| Lowest | \(\beta < b_l\) | asymptotic, below | \(1/\ln b(s) - 1/\ln\beta\) |
| Lower middle | \(b_l \le \beta \le b_c\) | rational cubic, Equation (5.33) | \(b(s) - \beta\) |
| Upper middle | \(b_c < \beta \le b_u\) | rational cubic | \(b(s) - \beta\) |
| Upper | \(\beta > b_u\) | \(\max(s_u,\, -2\Phi^{-1}((b_{\max} - \beta)/(b_{\max} + 1/b_{\max})))\) | \(\ln \dfrac{b_{\max} - b(s)}{b_{\max} - \beta}\) |
Here \(\beta\) is the normalised target price. On the lowest branch \(\ln b\) is computed as \(\ln b' + \ln(b/b')\), so nothing underflows; its starting point solves the leading behaviour \(\ln\beta \approx -x^2/(2s^2) - s^2/8 + 3\ln s - 2\ln|x| - \tfrac12\ln(2\pi)\) (the first term of Equation (5.28)) by four fixed-point steps, kept below \(s_l\). On the upper branch \(b_{\max} - b = e^{x/2}\Phi(-h - t) + e^{-x/2}\Phi(h - t)\) is a sum of positive terms; its starting point is the exact inverse at \(x = 0\), where \(b_{\max} - b = 2\Phi(-s/2)\). At \(x = 0\), \(s_c = b_c = 0\) and only the upper two branches exist.
Rational cubic starting point. On each middle branch, \(s\) as a function of \(\beta\) is interpolated between the branch ends \((\beta_0, s_0)\) and \((\beta_1, s_1)\), with slopes \(d_i = 1/b'(s_i)\), by the rational cubic of Delbourgo and Gregory (1985), with \(\tau = (\beta - \beta_0)/\Delta\) and \(\Delta = \beta_1 - \beta_0\):
\(R\) matches both values and slopes for any control parameter \(r\) (\(r = 3\) is the cubic Hermite polynomial). Following Jäckel's idea of matching the curvature, \(r\) is chosen so that \(R'' = 0\) at the end \(s_c\), where the inverse function has an inflection point as \(b\) does: solving \(R''(1) = 0\) gives \(r = \Delta(d_1 - d_0)/(\Delta d_1 - (s_1 - s_0))\) on the lower middle branch, and \(R''(0) = 0\) gives \(r = \Delta(d_0 - d_1)/(\Delta d_0 - (s_1 - s_0))\) on the upper one (derived for this library with sympy). It is raised, if needed, to \((d_0 + d_1)/((s_1 - s_0)/\Delta)\), the smallest value for which Delbourgo and Gregory show \(R\) is monotone.
Householder iteration. From \(s_0\), each step uses the Newton step \(n = -g/g'\) and the ratios \(h_2 = g''/g'\), \(h_3 = g'''/g'\):
the third-order Householder method, whose error shrinks to roughly its fourth power at each step. The derivatives of \(g\) follow from Equation (5.31) by the chain rule; for the lowest branch, with \(L = \ln b\) and \(\rho_1 = b'/b\), \(g' = -\rho_1/L^2\), \(h_2 = -(2/L + 1)\rho_1 + b''/b'\) and \(h_3 = (6/L^2 + 6/L + 2)\rho_1^2 - 3(2/L + 1)\rho_1 b''/b' + b'''/b'\); for the upper branch, with \(c = b_{\max} - b\) and \(\rho = b'/c\), \(n = \ln(c/(b_{\max} - \beta))/\rho\), \(h_2 = \rho + b''/b'\) and \(h_3 = 2\rho^2 + 3\rho\, b''/b' + b'''/b'\). Every evaluation also updates a bracket around the root (from the sign of \(b(s) - \beta\), which is increasing in \(s\)); a step that leaves the bracket is replaced by its midpoint, or by doubling while the bracket has no upper end. The iteration stops when the step or the bracket is below \(10^{-15}\) of \(s\), the level of rounding noise in the price; more than 32 steps is an error. Over 100,000 random out-of-the-money cases with \(|x| \le 8\) and \(10^{-3} \le s \le 8\) (2026-10-14) it took two or three steps, counting the last one that confirms convergence, rarely four or five, and the volatility was recovered to \(1.5 \times 10^{-13}\) or better (the worst cases at large \(s\), where the price is flat in \(\sigma\)).
The structure follows Jäckel () and was checked against the paper after the first version (review of 2026-10-14): the normalisation, the four evaluation regions and their limits, the branch points from the tangent at the inflection point, the three objectives, the rational cubic with zero curvature at the inflection point and the Householder(3) derivatives match. This library's own choices, which change starting points and the stopping rule but not results, are: the starting points on the lowest and upper branches (the asymptotic forms above, where the paper interpolates rational cubics in transformed coordinates, its equations (4.31) to (4.38) and (4.23) to (4.30)); the plain objective \(b - \beta\) up to \(b_u\), where the paper keeps it up to \(\max(b_u, b_{\max}/2)\); the series of region 1 summed to convergence instead of a fixed 17 terms, and region 2 by the recurrence instead of a fixed 12th-order expansion; and the safeguarding bracket with a stopping rule, where the paper takes exactly two Householder steps.
Worked example. \(F = 100\), \(K = 120\), \(T = 0.5\), \(\sigma = 0.3\): the call is worth \(2.50377520873224\) (mpmath at 60 digits), with vega \(21.2391829685234\). In normalised terms \(x = -0.182321556793955\), \(s = 0.212132034355964\), \(\beta = 0.0228562360124142\); the branch points are \(s_c = 0.603856865149275\), \(b_c = 0.157412463900191\), \(s_l = 0.171622120695286\), \(b_l = 0.0126500923550415\), so \(\beta\) is on the lower middle branch. The rational cubic, with \(r = 6.991\) (above the monotone minimum \(2.401\)), starts at \(s_0 = 0.212271135555417\), a relative error of \(6.6 \times 10^{-4}\); two Householder steps reach \(s\) to the last digit, and \(\sigma = s/\sqrt{0.5} = 0.3\).
5.11 Bachelier implied volatility
Bachelier's formula. In the normal model the forward moves by \(\sigma \sqrt T\) times a standard normal variable, so forward and strike may have any sign; interest rate options are quoted in this normal volatility. With \(d = \theta(F - K)\) and \(s = \sigma\sqrt T\), the undiscounted price is (Bachelier, 1900)
Reduction. As for Black, subtracting the intrinsic value \(\max(d, 0)\) leaves the out-of-the-money price, which depends on \(a = |F - K|\) and \(s\) only (Jäckel, 2017):
where the last form, with \(Y'\) from Equation (5.24), avoids the cancellation of \(\varphi(u) + u\Phi(u)\) for large \(|u|\). The time value \(v = s\psi(u)\) increases from \(0\) to \(\infty\) with \(s\), so every price above the intrinsic value has exactly one volatility, and there is no upper bound. Its derivatives in \(s\) are \(v' = \varphi(u)\) (the normal vega divided by \(\sqrt T\)), \(v''/v' = u^2/s\) and \(v'''/v' = u^2(u^2 - 3)/s^2\). At the money, \(a = 0\), the inversion is exact: \(s = v\sqrt{2\pi}\).
Branches. In terms of the ratio \(q = v/a = \psi(u)/|u|\), two branches meet at \(u = -1\), where \(q = \psi(-1) = \varphi(1) - \Phi(-1) = 0.0833154705876863\):
On the lower branch \(\ln q = -\ln|u| - u^2/2 - \tfrac12\ln(2\pi) + \ln Y'(u)\) is computed from its parts, and the starting point solves the leading behaviour \(q \approx \varphi(u)/|u|^3\) by four fixed-point steps (with \(|u_0| \ge 1\), \(s_0 = a/|u_0|\)). On the upper branch the starting point is the larger root of the expansion \(v \approx s\varphi(0) - a/2 + a^2\varphi(0)/(2s)\), kept at least \(a\). The Householder iteration, bracket and stopping rule are those of Equation (5.34), with \(h_2\) and \(h_3\) from the derivatives above (for the lower branch, the same formulas as Black's lowest branch with \(\rho_1 = v'/v = 1/(s\, Y'(u))\)).
Jäckel (2017) gives a rational approximation of the inverse that needs no iteration; this library uses his reduction with its own asymptotic starting points and the same Householder refinement, which reaches full precision in a few steps.
Worked example. \(F = 0.03\), \(K = 0.035\), \(T = 2\), \(\sigma = 0.01\) (100 basis points a year): \(a = 0.005\), \(s = 0.0141421356237310\), \(u = -0.353553390593274\), \(q = 0.698177324460233\) (upper branch), and the call is worth \(0.00349088662230116\), the put \(0.00849088662230117\), with vega \(0.530007064688057\); the inversion of either returns \(\sigma = 0.01\).
5.12 Black–Scholes–Merton on a spot
Model. For an option on a share or index with spot price \(S\), a continuously compounded risk-free rate \(r\) and a continuously compounded dividend yield \(q\), both constant to expiry, the model of Black and Scholes (1973) and Merton (1973) makes the forward to expiry \(F = S e^{(r-q)T}\) and the price the discounted Black price on that forward (Equation (5.26)):
In plain words: the option is a Black option on the forward, paid at expiry, so its value today is that payoff value times the discount factor \(e^{-rT}\). The dividend yield lowers the forward. A zero time or volatility gives the discounted intrinsic value \(e^{-rT}\max(\theta(F - K), 0)\).
Sensitivities. Differentiating Equation (5.38), with \(\varphi\) and \(\Phi\) the normal density and distribution function of Section 5.9 and \(T > 0\), \(\sigma > 0\):
Delta is per unit of the spot; gamma per unit of the spot squared; vega and rho per unit of volatility and rate (1.00 = 100%, so a 1% move changes the value by \(\mathcal V/100\), a 1bp move by \(\rho/10\,000\)); theta per year of time passing with spot, rate, dividend yield and volatility fixed. Gamma and vega are the same for a call and a put. Rho differentiates \(r\) in both the forward and the discount factor, with \(q\) held fixed.
Implied volatility. The premium \(V\) is divided by \(e^{-rT}\) to give the undiscounted Black price on \(F\), which Section 5.10 inverts; no new algorithm is needed. The premium must lie between the discounted intrinsic value and the discounted upper bound: below \(S e^{-qT}\) for a call and below \(K e^{-rT}\) for a put.
Worked example (Hull, 2018). \(S = 42\), \(K = 40\), \(T = 0.5\), \(r = 10\%\), \(q = 0\), \(\sigma = 20\%\): \(F = 44.1533860477930\), \(d_1 = 0.769262628106031\), \(d_2 = 0.627841271868722\) and \(e^{-rT} = 0.951229424500714\). The call is worth \(4.75942239287153\) and the put \(0.808599372900094\); for the call \(\Delta = 0.779131290942669\), \(\Gamma = 0.0499626704059119\), \(\mathcal V = 8.81341505960285\), \(\Theta = -4.55909219459263\) a year and \(\rho = 13.9820459133603\). Inverting either price returns \(\sigma = 20\%\).
5.13 One-dimensional minimisation: golden-section search
Problem. Find a point of \([a, b]\) where a function \(f\) of one variable is smallest, when no derivative is at hand and \(f\) is unimodal on the interval (decreasing, then increasing).
Method. Keep a bracket \([a, b]\) and two interior points
If \(f(c) \le f(d)\) the minimum lies in \([a, d]\), else in \([c, b]\); the kept interior point is one of the new pair, because \(\rho^2 = 1 - \rho\), so each step costs one new value of \(f\) and shrinks the bracket by \(\rho\). The search stops when \(b - a\) is below the tolerance and returns the better interior point. In plain words: the bracket is cut in the golden ratio, always keeping the part where the smaller value was seen.
Limits. Near a smooth minimum \(f\) changes only by the square of the distance, so its values stop differing in double precision about \(\sqrt{\varepsilon} \approx 10^{-8}\) (relative) from the minimum; asking for a tighter tolerance does not make the answer more precise. For a function that is not unimodal the result is a local minimum. Used by the Hull-White mean reversion fit (Section 16.9).
Worked example. \(f(x) = x \ln x\) on \([0.01, 2]\) has its minimum at \(1/e \approx 0.367879\); the search with tolerance \(10^{-10}\) returns it to within \(10^{-7}\).
References
- Milton Abramowitz and Irene A. Stegun (1964). Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. National Bureau of Standards.
- Louis Bachelier (1900). Théorie de la spéculation. Annales scientifiques de l'École Normale Supérieure 17, 21–86.
- Fischer Black (1976). The Pricing of Commodity Contracts. Journal of Financial Economics 3(1–2), 167–179.
- Fischer Black and Myron Scholes (1973). The Pricing of Options and Corporate Liabilities. Journal of Political Economy 81(3), 637–654.
- Richard P. Brent (1973). Algorithms for Minimization without Derivatives. Prentice-Hall.
- R. Delbourgo and J. A. Gregory (1985). Shape Preserving Piecewise Rational Interpolation. SIAM Journal on Scientific and Statistical Computing 6(4), 967–976.
- David Goldberg (1991). What Every Computer Scientist Should Know About Floating-Point Arithmetic. ACM Computing Surveys 23(1), 5–48.
- John C. Hull (2018). Options, Futures, and Other Derivatives. 10 edition. Pearson.
- Peter Jäckel. Let's Be Rational. Wilmott, 40–53.
- Peter Jäckel (2017). Implied Normal Volatility. Wilmott.
- Kenneth Levenberg (1944). A Method for the Solution of Certain Non-Linear Problems in Least Squares. Quarterly of Applied Mathematics 2(2), 164–168.
- Kaj Madsen, Hans Bruun Nielsen and Ole Tingleff (2004). Methods for Non-Linear Least Squares Problems. 2 edition. Informatics and Mathematical Modelling, Technical University of Denmark.
- Donald W. Marquardt (1963). An Algorithm for Least-Squares Estimation of Nonlinear Parameters. Journal of the Society for Industrial and Applied Mathematics 11(2), 431–441.
- Robert C. Merton (1973). Theory of Rational Option Pricing. The Bell Journal of Economics and Management Science 4(1), 141–183.
- Jorge J. Moré (1978). The Levenberg-Marquardt Algorithm: Implementation and Theory. Numerical Analysis, Lecture Notes in Mathematics 630, 105–116. Edited by G. A. Watson. Springer.
- Antoine Savine (2018). Modern Computational Finance: AAD and Parallel Simulations. Wiley.
[Savine (2018); Brent (1973); Levenberg (1944); Marquardt (1963); Moré (1978); Madsen et al. (2004); Abramowitz and Stegun (1964); Black (1976); Bachelier (1900); Jäckel (); Jäckel (2017); Delbourgo and Gregory (1985); Goldberg (1991); Black and Scholes (1973); Merton (1973); Hull (2018)]