Guide 02 Three independent choices

Methods, backends and arrays

A calibration combines three choices that the package keeps independent: how a smile is priced, how derivatives are taken, and where the arrays live. Each one is an argument, and changing one does not change the others.

FinancialFFTclosed formsMonte CarloForwardDiff · Zygote · Mooncake · EnzymeCUDA

Pricing methods

The second argument of calibrate is any pricing method of FinancialMonteCarlo's pricer interface, so the kind of calibration is the choice of that argument:

MethodPackageModels
LewisMethod, CosMethod, CarrMadanLewisMethod, CarrMadanMethodFinancialFFT.jlevery model with a characteristic exponent: Black–Scholes, Merton, Kou, Variance Gamma, NIG, Heston
AnalyticMethodFinancialCalibrator.jlclosed forms: BlackScholesProcess, LogNormalMixture, ShiftedProcess of either, see Closed forms
MonteCarloConfigurationFinancialMonteCarlo.jlevery model that it simulates, with the same seed at every evaluation
Vibrato, VibratoSaltando, PureLRMVibratoMonteCarlo.jlMonte Carlo with smooth estimators of the derivatives
calibrate(model, und, CosMethod(2^10), mkt)                                   # Fourier
calibrate(model, und, LewisMethod(400.0, 40001), mkt)                         # Fourier, another quadrature
calibrate(slnm, und, AnalyticMethod(), mkt)                                 # closed form
calibrate(model, und, MonteCarloConfiguration(10^5, 1), mkt)                  # simulation

The same Heston calibration of the DAX surface with three Fourier methods (measured by docs/benchmarks.jl):

Heston, DAX, pricing engineone losscalibrationRMS error
CosMethod(512)1.35 ms312 ms68.9 bp
LewisMethod(200, 4001)4.63 ms1.07 s68.9 bp
CarrMadanLewisMethod(400, 14)35.74 ms9.85 s68.9 bp

Same model, same optimum: the engine sets the cost. CarrMadanLewisMethod(400, 14) runs an FFT of 2¹⁴ points per maturity, far more than nine smiles of twelve strikes need, and still stops near 3e-7 in volatility.

Choosing the size

A larger method costs more and stops being more accurate once its error is below the rounding of the implied volatilities. What it must be accurate for is the whole calibration, not only its starting point: on the DAX surface, at the starting point of each model of the quick start and the tests, and at the optimum its calibration reaches:

methodBlack–ScholesMertonKouVariance GammaNIGHeston
CosMethod(128)< 1e-12 / < 1e-12
0.19 ms
3e-10 / 2e-07
0.24 ms
5e-09 / fails
0.26 ms
3e-04 / fails
0.29 ms
4e-05 / fails
0.24 ms
1e-06 / 2e-03
0.44 ms
CosMethod(256)< 1e-12 / < 1e-12
0.44 ms
< 1e-12 / < 1e-12
0.46 ms
< 1e-12 / fails
0.44 ms
3e-05 / 2e-03
0.49 ms
3e-08 / 7e-04
0.39 ms
3e-12 / 8e-07
0.73 ms
CosMethod(512)< 1e-12 / < 1e-12
0.94 ms
< 1e-12 / < 1e-12
1.19 ms
< 1e-12 / 4e-03
0.89 ms
3e-06 / 7e-05
0.87 ms
< 1e-12 / 1e-06
0.81 ms
< 1e-12 / 8e-12
1.36 ms
CosMethod(1024)< 1e-12 / < 1e-12
1.62 ms
< 1e-12 / < 1e-12
1.99 ms
< 1e-12 / 6e-06
1.98 ms
3e-07 / 2e-05
1.63 ms
< 1e-12 / 3e-12
1.61 ms
< 1e-12 / < 1e-12
2.92 ms
CosMethod(2048)< 1e-12 / < 1e-12
3.05 ms
< 1e-12 / < 1e-12
2.73 ms
< 1e-12 / < 1e-12
4.18 ms
4e-09 / 2e-06
4.00 ms
< 1e-12 / < 1e-12
3.86 ms
< 1e-12 / < 1e-12
4.99 ms
LewisMethod(100, 1001)8e-05 / 7e-05
0.75 ms
1e-05 / 4e-04
0.82 ms
3e-05 / 3e-04
0.72 ms
2e-04 / 7e-03
0.78 ms
2e-05 / 8e-04
0.56 ms
1e-04 / 3e-04
1.42 ms
LewisMethod(100, 2001)1e-11 / 1e-11
1.44 ms
2e-12 / 6e-08
1.65 ms
4e-12 / 5e-07
1.89 ms
2e-04 / 7e-03
1.90 ms
3e-06 / 7e-04
1.11 ms
1e-07 / 5e-05
2.27 ms
LewisMethod(100, 4001)< 1e-12 / < 1e-12
2.79 ms
< 1e-12 / 6e-08
2.35 ms
< 1e-12 / 6e-07
3.55 ms
2e-04 / 7e-03
3.74 ms
3e-06 / 7e-04
2.77 ms
1e-07 / 5e-05
4.56 ms
LewisMethod(200, 4001)1e-11 / 1e-11
3.22 ms
2e-12 / 6e-11
2.53 ms
4e-12 / 4e-11
3.97 ms
2e-05 / 6e-04
3.83 ms
2e-10 / 1e-06
2.04 ms
2e-11 / 2e-08
4.32 ms
LewisMethod(400, 8001)1e-11 / 1e-11
6.51 ms
2e-12 / 6e-11
5.17 ms
4e-12 / 4e-11
7.69 ms
2e-06 / 8e-05
5.48 ms
3e-12 / 6e-11
5.40 ms
2e-11 / 3e-11
8.79 ms
LewisMethod(800, 16001)1e-11 / 1e-11
11.37 ms
2e-12 / 6e-11
10.14 ms
4e-12 / 4e-11
14.38 ms
2e-07 / 4e-06
15.04 ms
3e-12 / 6e-11
10.11 ms
2e-11 / 3e-11
19.73 ms
CosMethod(0.0001)1e-07 / 1e-07
2.75 ms
4e-08 / 1e-06
3.31 ms
4e-08 / 1e-06
3.54 ms
2e-08 / 9e-08
4.41 ms
3e-08 / 4e-07
3.39 ms
4e-07 / 5e-07
5.69 ms
CosMethod(1.0e-6)2e-10 / 2e-10
2.90 ms
3e-10 / 8e-09
4.04 ms
1e-09 / 1e-08
4.09 ms
3e-09 / 4e-08
6.98 ms
4e-10 / 4e-09
3.50 ms
1e-09 / 3e-09
6.52 ms
LewisMethod(0.0001)1e-07 / 2e-07
1.48 ms
9e-08 / 2e-06
2.29 ms
9e-08 / 4e-06
2.53 ms
1e-07 / 2e-06
5.07 ms
2e-07 / 1e-06
2.09 ms
1e-06 / 1e-06
5.76 ms
LewisMethod(1.0e-6)1e-08 / 1e-08
1.59 ms
1e-09 / 5e-08
2.24 ms
4e-09 / 4e-08
2.61 ms
—
N > N_max
1e-09 / 4e-08
2.25 ms
2e-08 / 2e-08
5.83 ms
CarrMadanLewisMethod(400, 14)4e-07 / 4e-07
11.20 ms
1e-07 / 1e-05
14.21 ms
1e-07 / 2e-05
17.50 ms
1e-05 / 1e-04
18.01 ms
7e-07 / 4e-06
12.73 ms
1e-06 / 5e-06
32.12 ms
CarrMadanMethod(400, 14)7e-07 / 6e-07
10.49 ms
1e-07 / 8e-06
15.30 ms
2e-07 / fails
18.65 ms
1e-05 / 9e-05
18.12 ms
8e-07 / 4e-06
14.69 ms
7e-07 / 4e-06
36.11 ms

Largest implied volatility error over the 99 DAX quotes of the loss, against LewisMethod(3200, 512001), at the starting point of each model / at the optimum of its calibration; under it, one loss at the starting point. In bold the recommended setting: Black–Scholes: CosMethod(256), Merton: CosMethod(256), Kou: LewisMethod(200, 4001), Variance Gamma: LewisMethod(800, 16001), NIG: LewisMethod(400, 8001), Heston: CosMethod(512). Measured 2026-11-27 on Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz.

  • CosMethod for Black–Scholes, Merton and Heston: CosMethod(256) is exact to the rounding for the first two, at a fraction of a millisecond per loss; Heston needs CosMethod(512) at its optimum (a volatility of variance above 1).
  • LewisMethod for Kou. The DAX optimum of Kou has almost no up jumps (p → 0) and λ₊ → 1. The truncation range of CosMethod comes from a Chernoff bound, L / λ₊ for the upper tail however rare the jumps are, and grows to [-4, 32]: CosMethod(512) is 43 bp off there, and its derivatives (range held constant, FinancialFFT.jl#64) are not those of its prices. LBFGS then takes its 1000 iterations and 50000 evaluations of the loss, 128 s, against 1 s with CosMethod(1024) or 1.5 s with LewisMethod(100, 4001). Lewis has no truncation range to grow: LewisMethod(200, 4001) is accurate to 1e-10 at both points.
  • Variance Gamma and NIG need a wide Lewis range. Their characteristic functions decay slowly at short maturities (as a power of the frequency for Variance Gamma), so LewisMethod(100, ·) stops at 1e-4 to 1e-2 in volatility whatever its number of nodes: on DAX it moved the Variance Gamma optimum by 1.5 bp of RMS error. LewisMethod(800, 16001) (VG) and LewisMethod(400, 8001) (NIG), with the spacing 2A/N of 0.1, reach 4e-6 and 1e-10. CosMethod converges for them too, but its derivatives are not those of its prices there: a derivative error of 4e-5 for Variance Gamma with CosMethod(1024), which the polish and calibrated_parameters would inherit.
  • From a tolerance, no tuning. CosMethod(ε) and LewisMethod(ε) (FinancialFFT 0.9, 0.10) choose the size of each maturity from a tolerance ε on the prices, in their units: on DAX (spot 10514) ε = 1e-6 gives at most 4e-8 in volatility at both points for every model, ε = 1e-4 at most 4e-6 (the volatility error is about ε / vega). The sizes are chosen again at every loss, which costs 2 to 7 ms on this surface, more than the whole loss of a fixed CosMethod(256): the fixed settings above stay the fast choice where they are known (FinancialCalibrator#47 would choose the sizes once per calibration). The exception is Variance Gamma, whose characteristic function decays as a power: at its optimum CosMethod(1e-4) errs by 9e-8, 40 times less than LewisMethod(800, 16001), at about the same cost (15 ms per loss there, 4 ms at the start), with derivatives within 6e-7 of those of the reference; CosMethod(1e-6) takes 90 ms there and LewisMethod(1e-6) more than its N_max nodes.
  • Carr–Madan stops near 1e-7 to 1e-5 whatever the size of its FFT, at several times the cost of a quadrature: use it only for very large smiles, where one FFT prices all the strikes.

Automatic differentiation

From outside

calibrated_parameters is a function of the quoted volatilities that every backend can differentiate, since its rules come from the implicit function theorem and not from tracing the optimizer:

using ForwardDiff, Zygote
f(v) = calibrated_parameters(model, und, method, mkt, v)
ForwardDiff.jacobian(f, mkt.Volatility)                    # ∂p*/∂v, forward mode
Zygote.gradient(v -> w' * f(v), mkt.Volatility)            # wᵀ ∂p*/∂v, reverse mode (ChainRules)

Mooncake has a rule of its own, in the package extension loaded with Mooncake (ImplicitDifferentiation's ChainRules rule needs a RuleConfig, which Mooncake.@from_rrule does not pass):

using Mooncake, ADTypes
import DifferentiationInterface as DI
DI.gradient(v -> w' * f(v), AutoMooncake(; config = nothing), mkt.Volatility)

Support

Every derivative of the calibration runs through the implicit function theorem, so the outer backend never traces the optimizer: it only meets the rule of the implicit function, and the inner backends meet the loss. The backends can be mixed freely, forward over reverse or reverse over forward. The table shows the gradient of $w^\top p^*(v)$ for Variance Gamma with LewisMethod(100.0, 4001) on 15 quotes, relative to the ForwardDiff gradient on the host. Every case ran in a fresh Julia process (bench/bench.jl vg15, 2026-12-01, FinancialCalibrator 0.4.6). The first call is timed after one calibration in that process, so it is the compilation of the derivatives only; the device is a laptop GPU (NVIDIA MX150):

OuterInner x / yHost: first callHost: next callsDevice: next callsError
ForwardDiff¹ForwardDiff / ForwardDiff0.95 s0.15 s0.32 s²0 (host), 5e-13 (device)
ZygoteForwardDiff / ForwardDiff26 s0.14 s0.20 s1e-14, 2e-12
MooncakeForwardDiff / ForwardDiff41 s0.19 s0.80 s1e-14, 2e-12
ZygoteMooncake / ForwardDiff92 s0.11 s✗³1e-14
MooncakeMooncake / ForwardDiff76 s0.21 s✗³1e-14
Enzyme, reverse⁴ForwardDiff / ForwardDiff127 s0.11 s0.22 s1e-14, 2e-12
Enzyme, forward⁴ForwardDiff / ForwardDiff120 s0.10 s✗⁵1e-15

One run per case: on this laptop the times of two runs differ by up to a third. The device column is 2026-12-01 too, but for ForwardDiff (² measured 2026-11-21; the device keeps the conditions of 0.4.5, see below).

Compilation and run time of the gradient per AD backendCompilation and run time of the gradient per AD backend

¹ With one chunk for all the quotes, ForwardDiff.gradient(f, v, ForwardDiff.GradientConfig(f, v, ForwardDiff.Chunk{length(v)}())). Or build the function once with calibrated_parameters_function, whose solver remembers its last quotes: any chunk then runs one calibration (#48; at 45 quotes the default chunk without it was 2.9x slower). ForwardDiff's default chunk (8) splits 15 quotes in two, and each chunk runs the whole calibration again. ² One direction: ForwardDiff cannot seed a CuArray, so on the device it gives one derivative at a time (ForwardDiff.derivative along a bump of one quote). ³ Mooncake differentiating the inner ForwardDiff gradient of the conditions meets a broadcast of dual numbers over a CuArray, which it does not support. ⁴ Enzyme works through rules of the extension of FinancialCalibrator for EnzymeCore: they build the implicit function outside of the differentiated code, then apply ImplicitDifferentiation's Enzyme rules to it as a constant (Enzyme cannot trace the construction, and failed on the GPU when it did, #21). Those rules need the solver to return an inferred type, which it does. On the device the first call compiles for 4 to 7 minutes here, 18 on Black–Scholes with CosMethod(1024). ⁵ Enzyme's forward mode seeds the gradient with one-hot arrays that it fills by scalar indexing, which a CuArray refuses (EnzymeAD/Enzyme.jl#4048); the reverse mode works on the device.

What the numbers say:

  • Once compiled, a gradient costs about one calibration, whatever the backend: here the solve takes about 0.1 s (NelderMead, then the Levenberg–Marquardt polish). On the host the quotes enter the optimality conditions linearly (#49): the derivatives in the quotes are one matrix-vector product with the Jacobian of the errors at the solution, which the solver computes once, so no pricing is differentiated with respect to the quotes. On these 15 quotes that precomputation costs about what it saves (Zygote outside: 0.14 s against 0.12-0.14 s with 0.4.5); from about a hundred quotes it is 2 to 30 times faster (below).
  • The first call is compilation: Zygote and Mooncake compile their rules for the whole pricing method.
  • A reverse backend for x is no longer reverse over forward on the host: the conditions are linear in the quotes, so Mooncake differentiates a matrix-vector product, not the pricer (twice as fast as 0.4.5 here, and it compiles in half the time). On the device the conditions keep the gradient at the current quotes, and Mooncake for x meets the ForwardDiff gradient through the pricer (³).

The test suite checks ForwardDiff, Zygote, Mooncake and Enzyme (reverse, and forward on Black–Scholes) against the formula $\partial p^*/\partial v = -H^{-1} \partial_v \nabla_p L$, and Zygote and Mooncake on the GPU.

Inside

Four derivatives are taken inside, each by an ADTypes.jl backend, through DifferentiationInterface.jl:

KeywordOfDefault
autodiffthe gradient of the loss, for a gradient based Optim optimizer (LBFGS(), BFGS(), ...)AutoForwardDiff()
polish_backendthe Jacobian $J$ of the volatility errors, in the Levenberg–Marquardt polishAutoForwardDiff()
conditions_backendthe gradient $g = \partial_x L$, the optimality conditionsAutoForwardDiff()
implicit_backends = (x = ..., y = ...)the derivatives of $g$ with respect to the quotes (x) and to the variables (y)AutoForwardDiff() for both

The last row differentiates the gradient of the row before it: a second order derivative, nested. ForwardDiff everywhere suits a calibration, whose parameters are few: the Jacobian $J$ has as many columns as parameters, and the Hessian $\partial_x g$ is small. The one place where reverse mode can pay is x with a reverse outer backend and many quotes: the reverse rule needs $(\partial_v g)^\top w$, which forward mode gets one quote at a time.

using ADTypes, Mooncake
calibrated_parameters(model, und, method, mkt, v; implicit_backends = (x = AutoMooncake(; config = nothing), y = AutoForwardDiff()))

The table above times these combinations. Zygote for x does not work: it cannot differentiate the inner ForwardDiff gradient of the conditions.

What each backend differentiates

The inner backends differentiate two functions: FinancialCalibrator.loss (for autodiff) and vol_errors (for polish_backend and the conditions). loss returns $\infty$ where the parameters cannot be priced, by catching the exception. Zygote and Mooncake cannot differentiate a catch, so FinancialCalibrator gives them a rule for loss (a ChainRules rrule for Zygote, a Mooncake rule in the extension) that runs the try itself around the reverse pass of the loss without it, with a zero gradient where the loss is $\infty$, as ForwardDiff and Enzyme give (FinancialCalibrator.jl#40). Gradients on the DAX surface, against ForwardDiff (shifted lognormal mixture with AnalyticMethod, Variance Gamma with LewisMethod(100.0, 2001)):

Backendvol_errorsloss
ForwardDiff✓✓
Zygote✓✓ (a rule, FinancialCalibrator.jl#40)
Mooncake✓✓ (a rule, FinancialCalibrator.jl#40)
Enzyme, reverse✓✓

Enzyme needs no runtime activity with FinancialMonteCarlo 0.9 or later, whose curves are isbits (FinancialMonteCarlo.jl#79); with 0.8, a model rebuilt from active parameters on the dividend curve that adapter returns needs AutoEnzyme(; mode = Enzyme.set_runtime_activity(Enzyme.Reverse)). When calling Enzyme.autodiff directly, pass the model, the market data and the cache of loss_cache as Const arguments: captured in a closure annotated Const, they make Enzyme ask for runtime activity on any underlying. Every backend works as the autodiff of a gradient optimizer such as LBFGS() on the mixture and on Variance Gamma, whose line search on DAX reaches parameters that cannot be priced. On Heston with CosMethod, Enzyme does not (EnzymeNoDerivativeError, FinancialCalibrator.jl#41).

Zygote is correct but slow here: a gradient of vol_errors costs 1.6 ms on the mixture (ForwardDiff 0.11 ms) and 16 ms with Lewis (ForwardDiff 2.7 ms), with FinancialMonteCarlo 0.9 (laptop, i7-8550U). With 0.8 the mixture took 7.7 ms, most of it Zygote tracing the model setup (rebuilding the model and integrating the dividend curve element by element): FinancialMonteCarlo 0.9 gives set_parameters! and the integral of a curve reverse rules (FinancialMonteCarlo.jl#80). The inner backends have few parameters to differentiate, which is what ForwardDiff is for; Zygote belongs outside, on calibrated_parameters, where it meets only the rule of the implicit function.

Every backend differentiates the pricing code itself, which is written for it: no branches, validations outside the derivatives, and for the closed forms a kernel whose Zygote gradient is inferred (see Other closed forms).

Which backend

bench/ times every combination of backends, each in a fresh Julia process, on three models with 99 quotes of the DAX surface (synthetic volatilities of a known model, so the optimum is well conditioned): the shifted lognormal mixture with AnalyticMethod, Variance Gamma with LewisMethod(100.0, 4001) and Heston with CosMethod(1024). The times are run times once compiled (laptop: i7-8550U, NVIDIA MX150; Enzyme 0.13.221, CUDA 6.5.1, 2026-11-20); the first call compiles for 1 to 3 minutes with Enzyme, Zygote and Mooncake, against 10 ms with ForwardDiff. ✗ marks a combination that fails; FinancialCalibrator.jl#41 explains each one.

Inside: ForwardDiff or Enzyme forward. The derivatives in the parameters (host, Float64):

Backendloss gradient: mixtureVGHestonvol_errors Jacobian: mixtureVGHeston
ForwardDiff97 μs6.5 ms9.0 ms90 μs6.0 ms8.5 ms
Enzyme, forward85 μs4.3 ms7.5 ms89 μs4.6 ms6.9 ms
Enzyme, reverse128 μs9.2 ms10 ms1.5 ms0.74 s0.54 s
Zygote1.5 ms20 ms26 ms72 ms1.1 s1.0 s
Mooncake0.40 ms69 ms58 ms12 ms1.8 s2.8 s

A gradient in 3 to 5 parameters is what forward mode is for. Reverse mode builds the Jacobian of vol_errors one quote at a time, 100 to 300 times slower. In calibrate (LBFGS()):

autodiff / polish_backendMixtureVGHeston
ForwardDiff / ForwardDiff (the default)4.6 ms0.34 s0.43 s
Enzyme forward / ForwardDiff4.8 ms0.21 s✗
Enzyme forward / Enzyme forward5.0 ms0.26 s✗
ForwardDiff / Enzyme forward5.1 ms0.24 s0.38 s
Enzyme reverse / ForwardDiff6.2 ms0.32 s✗
Zygote / ForwardDiff0.16 s0.53 s0.61 s
Mooncake / ForwardDiff33 ms2.7 s3.0 s
ForwardDiff / Enzyme reverse, Zygote, Mooncake19 ms to 0.81 s7.6 to 20 s4.8 to 13 s
NelderMead(), ForwardDiff polish6.9 ms0.71 s0.68 s

Enzyme forward saves up to a third on the Fourier methods, but the default stays ForwardDiff: it compiles in milliseconds and works on every model.

Outside: any reverse backend, or ForwardDiff. The gradient of $w^\top p^*(v)$ with the default inner backends, and the full Jacobian $\partial p^*/\partial v$:

Outer backendGradient: mixtureVGHestonJacobian: mixtureVGHeston
ForwardDiff8.1 ms0.42 s0.60 s8.0 ms0.43 s0.66 s
Zygote8.6 ms0.45 s0.63 s9.6 ms0.46 s0.74 s
Enzyme, reverse8.0 ms0.44 s0.63 s23 ms1.8 s2.0 s
Enzyme, forward54 ms3.1 s4.4 s82 ms⁶4.3 s⁶5.9 s⁶
Mooncake17 ms0.86 s1.2 s113 ms⁶5.4 s⁶11 s⁶
Zygote, inner x Mooncake12 ms0.46 s0.68 s

bench/bench.jl on the DAX scenarios (99 quotes in the loss), 2026-12-01, FinancialCalibrator 0.4.6. Against 0.4.5, measured case by case in alternating fresh processes, the quotes entering the conditions linearly (#49) made the gradients 2 to 3 times faster (VG with ForwardDiff outside 1.06 → 0.42 s, Heston 1.74 → 0.60 s) and the Jacobians 2.5 to 8.5 times faster (Heston with Zygote outside 6.31 → 0.74 s); Mooncake for x 1.8 → 0.46 s (VG), 2.3 → 0.68 s (Heston). ⁶ Not rerun with 0.4.6 (2026-11-20, 0.4.x before #49).

The outer backend meets only the rule of the implicit function, so the inner derivatives set the cost, and the reverse backends tie with ForwardDiff on 99 quotes. Enzyme as an inner backend of calibrated_parameters fails in this benchmark (#41). For the full Jacobian, ForwardDiff or Zygote.

Arrays: Float64 on the host for a hundred quotes, Float32 on the host from about a thousand. Heston with CosMethod(1024) on 99 DAX quotes and on a large surface (4 maturities × 500 strikes, 1929 quotes in the loss), 2026-12-02, FinancialFFT 0.10.4:

Host Float64Host Float32Device Float64Device Float32
loss gradient, ForwardDiff, 99 quotes6.1 ms6.3 ms6.6 ms6.1 ms
calibrate, NelderMead(), 99 quotes0.57 s0.45 s1.2 s1.3 s
calibrate, LBFGS(), 99 quotes0.30 s0.49 s0.37 s1.1 s
Gradient of $w^\top p^*$, Zygote, 99 quotes0.63 s0.55 s3.2 s2.5 s
loss gradient, ForwardDiff, 1929 quotes28 ms6.3 ms16 ms7.9 ms
calibrate, NelderMead(), 1929 quotes1.4 s0.61 s1.3 s0.69 s
Gradient of $w^\top p^*$, Zygote, 1929 quotes1.7 s0.71 s40 s21 s

Since FinancialFFT 0.10.4, which keeps the Float32 prices free of subnormal numbers (FinancialFFT#96), Float32 on the host is 2 to 4 times faster than Float64 on the large surface (on 2026-12-01 it was 2 to 4 times slower), and faster than the device in either type on this laptop (NVIDIA MX150). On 99 quotes the two types cost about the same. LBFGS() is the exception: in Float32 its line search takes 2.5 times the evaluations of the loss on Heston (77 against 31, the same 29 iterations), so it is slower than in Float64 (#52); NelderMead() is not affected.

The gradient of the calibrated parameters on 1929 quotes went from 57 s to 1.9 s on the host (161 → 6.6 s in Float32, 0.71 s since FinancialFFT 0.10.4): the conditions linear in the quotes (#49) apply on the host only, and the device keeps the gradient at the current quotes, differentiated through the pricer once per quote.

Mooncake differentiates the Fourier methods on the device too (Variance Gamma and Heston, the loss gradient matches ForwardDiff to 4e-15; the concatenation of the maturities through a rule of the extension, faster on the host than Mooncake's own of 0.5.74, chalk-lab/Mooncake.jl#1484), and the closed forms (Black–Scholes and the mixtures, 1e-14): their device broadcasts refuse a callable with state, so a rule of the CUDA and Mooncake extension differentiates the same prices with the numbers of the kernel passed as broadcast arguments (#41 group 3c). The Mooncake Jacobian of vol_errors on the device works since Mooncake 0.5.74, which accepts a CuArray output (#41 group 3d, chalk-lab/Mooncake.jl#1485).

Float32 loses digits: the calibrated parameters agree with the model that generated the quotes to 1e-5 to 2e-4 (1e-13 in Float64), at a final loss of about 1e-10 (3e-6 in volatility), and the derivatives of the calibrated parameters agree with Float64 to 4e-5 (shifted lognormal mixture) to 4e-3 (Variance Gamma, 15 quotes): enough for a calibration, not for derivatives that need more digits. On 1929 quotes the gradient of $w^\top p^*$ is dominated by the derivative of the conditions in the quotes (implicit_backends.x, forward mode: one direction per quote); a reverse backend for x needs one pullback per parameter instead, see #41. Its full Jacobian with Zygote takes 5.5 minutes on the host and did not end in 50 minutes in host Float32 (FinancialFFT 0.10.3, before FinancialFFT#96; not measured since).

Arrays

Floating point types

MarketData and CalibratedData are parametric in the floating point type. adapter(raw, Float32) reads a surface in Float32, and the losses are computed in it.

GPU

The strikes and the volatilities of MarketData can live on the GPU. With CUDA.jl loaded, every smile is then priced on the device (the extension moves the method to CudaMode), the implied volatilities are a broadcast on the device, and so are the derivatives: the dual numbers of ForwardDiff and the cotangents of Zygote are CuArrays too. The small linear systems (the Levenberg–Marquardt step, the implicit function theorem) come back to the CPU.

using CUDA, Adapt
gmkt = adapt(CuArray, mkt)                                            # strikes and volatilities on the device
calibrate(model, und, CosMethod(1024), gmkt)
calibrated_parameters(model, und, CosMethod(1024), gmkt)
Zygote.gradient(V -> sum(calibrated_parameters(model, und, CosMethod(1024), gmkt, V)), gmkt.Volatility)[1]   # a CuMatrix

Measured on a laptop GPU (NVIDIA MX150) with the DAX surface of 108 quotes, once compiled:

HostDeviceAgreement
calibrate, Black–Scholes, CosMethod(1024)0.06 s0.41 s4e-15
calibrate, Variance Gamma, LewisMethod(100.0, 4001)0.36 s0.71 s3e-8
one loss, Black–Scholes, CosMethod(1024)1.1 ms8.5 ms
one loss, Variance Gamma, LewisMethod(100.0, 4001)2.7 ms7.2 ms
Zygote gradient, Black–Scholes4e-14
Zygote gradient, Variance Gamma8e-8

How the cost of one loss grows with the strikes of a smile, on the same laptop (Black–Scholes, CosMethod(4096), measured by docs/benchmarks.jl):

Loss time against the number of strikes on CPU and GPULoss time against the number of strikes on CPU and GPU

A smile of 12 strikes is far too small to occupy a GPU, and these numbers time kernel launches: a loss costs 7 to 9 ms on the device whatever the model and the method. The device pays off with many strikes per smile, or many quotes. The point here is that nothing in the calibration, nor in its derivatives, needs to leave the device.

Float32

Consumer GPUs compute in Float64 at a fraction of their Float32 rate (1/32 on the MX150), and adapter(raw, Float32) gives a surface in Float32. On the DAX surface this changes nothing on the device, since the launches dominate: a loss costs 9.1 ms (Black–Scholes, Cos) and 7.6 ms (Variance Gamma, Lewis), and a calibration takes about as long (Black–Scholes 0.46 s, Variance Gamma 0.75 s, parameters within 2e-4 of the host in Float32). On a smile large enough to occupy the device, Float32 pays: 2000 strikes with CosMethod(4096):

HostDevice
Float6417.7 ms14.3 ms
Float3217.6 ms6.7 ms

Reactant (XLA)

The closed-form loss of AnalyticMethod (Black–Scholes, the lognormal mixtures, shifted or not) compiles with Reactant.jl, and so does its Enzyme gradient. The parameters are traced; the market data and the cache are constants of the compiled program. The implied volatilities go through FinancialToolbox's traced Let's Be Rational, with one traced call/put flag per quote (out of the money).

using Reactant, Enzyme
cache = FinancialCalibrator.loss_cache(model, und, AnalyticMethod(), mkt)
L(q) = FinancialCalibrator.loss(q, model, AnalyticMethod(), mkt, cache)
p = Reactant.to_rarray(FinancialMonteCarlo.get_parameters(model))
@jit L(p)
@jit Enzyme.gradient(Reverse, L, p)

The values agree with plain Julia to 1e-15 (the errors per quote), the gradient with ForwardDiff to 5e-15 (test/reactant, Linux CPU and CUDA). It is correct, not fast: on the DAX surface (108 quotes, Linux, Reactant 0.2.309, once compiled)

Compile (loss, gradient)LossGradientHost lossHost ForwardDiff
Black–Scholes, CPU200 s, 32 s548 μs678 μs48 μs64 μs
Shifted mixture, CPU32 s, 35 s634 μs951 μs62 μs99 μs
Black–Scholes, CUDA (MX150)283 s, 53 s24.5 ms24.5 ms51 μs132 μs
Shifted mixture, CUDA (MX150)75 s, 58 s24.1 ms24.9 ms64 μs110 μs

The cost is the traced implied volatility: about 0.4 ms per compiled call on the CPU whatever the size, and the branches of the solver are XLA conditionals, which the MX150 runs at about 0.3 ms per quote (FinancialToolbox's gpu.md, decision D-010 there, measures the alternatives). The calibration itself, the Fourier methods and the Monte Carlo methods are not traced. On Windows the XLA CPU compiler cannot link the implied volatility (EnzymeAD/Reactant.jl#3848).