Adjoint Greeks, and the payoff where they lie.
A finite difference needs one revaluation per input. A reverse sweep produces every partial derivative at a constant multiple of the forward cost. This repo measures that claim, then measures the case where the derivative it returns is exactly zero and exactly wrong.
Flat against linear.
One arithmetic basket, 40,000 paths. As the asset count grows 50×, AAD's cost relative to one pricing stays between 1.7× and 2.4×. Bumping grows close to the 2n+1 its construction implies.
make bench.Two ulps from the closed form.
The oracle is the textbook Black-Scholes formulas typed out by hand. It shares no code with the AD engine, which is the only reason agreement means anything. Finite differences have a sweet spot you can't know in advance. AAD has no bump to tune.
analytic 0.5987063256829237
AAD 0.5987063256829240
rel err 5.6e-16
| bump h | relative error |
|---|---|
| 1e+01 | 1.16e-02 |
| 1e-01 | 1.21e-06 |
| 1e-03 | 1.13e-10 ← best |
| 1e-06 | 4.64e-10 |
| 1e-08 | 1.48e-06 |
| 1e-10 | 1.14e-04 |
On a digital option, pathwise AAD returns delta 0.000000. No NaN, no warning, no clue.
The payoff is a step function, so its derivative is zero almost everywhere and the reverse sweep faithfully propagates zero. The crude method this repo argues against gets it right to 0.1%. Smoothing into a call spread fixes it, and brings back a bias you now have to choose.
What this doesn't do.
- No second-order GreeksGamma needs forward-over-reverse or a bump of the adjoint. The flat cost claim stops at first derivatives.
- Full tape in memory96 bytes per path, 48 MB at 500k paths. Production engines checkpoint instead.
- Flattered by numpyThe ~1.8× constant factor benefits from vectorized C. A scalar C++ tape would show more overhead.
- European payoffs onlyNo early exercise or path dependence. American options need regression-based continuation values.
- Common random numbersReusing normals across bumps is the favourable case for finite differences, so the baseline is the strongest one on purpose.
git clone https://github.com/asp53826/aad-greeks cd aad-greeks && make test && make bench