Differential Machine Learning: Learning Prices and Sensitivities Jointly
Abstract
Standard supervised learning of a pricing function uses only values as labels. In a Monte Carlo setting, however, the pathwise derivative of each simulated payoff with respect to the initial state is available at a small multiple of the cost of the payoff itself, using automatic differentiation (AD). Differential machine learning (DML) uses these derivatives as additional labels and trains the network so that its own gradient matches them. This article presents the mathematical basis of the method, the construction of the loss, its data-efficiency properties, its extension to Longstaff-Schwartz regression, and its main limitation: discontinuous payoffs, for which pathwise derivatives are biased. It concludes with implementation details, a validation protocol and a documentation checklist.
1. Motivation
A surrogate trained on prices alone has two structural weaknesses.
- Sample inefficiency. Each Monte Carlo label is a single noisy payoff realization. Estimating a smooth function of d variables from noisy values alone requires a large number of samples, and the requirement grows quickly with d.
- Uncontrolled Greeks. Greeks obtained by differentiating a network trained on values are by-products of the fit. A function can be uniformly close to a target while its gradient is not. In practice, hedging and P&L explain depend on the Greeks at least as much as on the price.
DML addresses both by making the derivative a training target, so the network is penalized directly for an incorrect gradient.
2. Mathematical Foundation
Let X₀ ∈ ℝᵈ be the initial state (spot levels, rates, possibly model or contract parameters), let ω denote the simulated randomness, and let Z = Z(X₀, ω) be the discounted payoff of the path. The pricing function is
Two properties are used.
Values. Writing Z = y(X₀) + ε with E[ε | X₀] = 0, regression of Z on X₀ recovers y even with a single path per initial state. This is the basis of any learning approach based on simulated payoffs.
Derivatives. If Z is almost surely differentiable in x with an integrable Lipschitz constant, dominated convergence allows differentiation under the expectation:
The pathwise derivative ∂Z/∂x is therefore an unbiased, noisy label for the gradient of the price. It is computed by the chain rule through the simulation, and reverse-mode AD (adjoint differentiation) delivers all d components at a cost that is a small constant multiple of one payoff evaluation, independent of d (Baur-Strassen bound; Griewank and Walther, 2008).
Get Simone Menaldo’s stories in your inbox
Join Medium for free to get updates from this writer.
The training set is thus the collection of triples (x⁽ⁱ⁾, z⁽ⁱ⁾, ∂z⁽ⁱ⁾/∂x) for i = 1, …, n, with the x⁽ⁱ⁾ drawn from a sampling distribution μ and one path simulated per x⁽ⁱ⁾.
3. Training Objective
With a network f_w whose gradient is obtained by backpropagation, the differential loss is
Points that matter in practice:
- Consistency by construction. Price and Greeks come from one function, so Δ = ∂P/∂S holds exactly. Training separate networks for price and Greeks does not guarantee this.
- Weights λⱼ. Value and derivative errors have different scales. One reasonable normalization sets λⱼ proportional to E[z²] / E[(∂z/∂xⱼ)²], scaled so that the derivative term has weight comparable to the value term. This is a hyperparameter and its sensitivity should be reported.
- Smooth activations. The loss involves the gradient of the network with respect to its inputs, and its own gradient with respect to the weights, which requires second-order differentiation. Softplus, SiLU, ELU or tanh should be used. With ReLU the network gradient is piecewise constant and the fit of the derivative is structurally poor.
- Twin-network implementation. The forward pass computes the value, and the backward (adjoint) pass is treated as a second network that outputs the derivatives. Frameworks with double backpropagation (PyTorch, JAX, TensorFlow) handle this automatically.
4. Why Data Efficiency Improves
Each sample provides d + 1 scalar labels rather than one. The derivative labels are not independent of the value label, since they are noisy functionals of the same path, so the gain is not a factor d + 1. The mechanism is nonetheless significant:
- The derivative labels act as a data-dependent regularizer that pins down the slope of the fitted function. Unlike a Tikhonov penalty, the extra information comes from unbiased labels and does not introduce a smoothing bias, provided the interchange of derivative and expectation is valid (Section 6).
- The idea is related to Sobolev training (Czarnecki et al., 2017) and is supported by approximation results in Sobolev norms for feed-forward networks (Hornik, Stinchcombe and White, 1990).
- The benefit grows with dimension and with the smoothness of the target. It is largest where value-only regression is most data-starved, for example baskets or high-dimensional state vectors.
The efficiency claim should be verified by learning curves (Section 8) and not assumed.
5. Application to Longstaff-Schwartz-Type Regression
In Longstaff-Schwartz (2001), the continuation value at an exercise date t(k) is estimated by regressing realized discounted cash flows on basis functions of the state X(t(k)). DML replaces the polynomial basis by a differentiable regressor (a neural network or a polynomial, in which case one speaks of differential regression) and adds derivative labels:
- the label for the value is the realized discounted cash flow along the path, as in the standard algorithm;
- the label for the derivative is the pathwise derivative of that cash flow with respect to the state at the exercise date, obtained by AD from that date to the realized exercise time, with the exercise decisions held fixed.
Methodological issues specific to this setting:
- Fixed-policy derivative. The derivative ignores the dependence of the exercise decision on the state. For the optimal policy this contribution is of first order zero (smooth pasting), but for the estimated policy it is only approximately so, which leaves a residual bias in the derivative labels.
- Where the benefit lies. Errors in the exercise policy cause only a second-order loss of value, so the gain in the price of a Bermudan product is typically modest. The more significant gains are in the stability of the regression with few paths, in Greeks at inception and in exposure profiles, where the conditional expectation is needed as a function of the state at future dates.
- In-the-money selection. Regression is restricted to in-the-money paths, so the derivative fit is also local to that set, and extrapolation beyond it is uncontrolled.
- Bias control. Separating the paths used to train the policy from those used for valuation (the usual remedy for the upward bias of the in-sample estimator) applies unchanged.
See also Fries (2019) for backward differentiation of American Monte Carlo and Glasserman and Yu (2004) on the relation between the number of paths and the number of basis functions.
6. Discontinuous Payoffs: The Principal Limitation
The unbiasedness of the derivative labels requires that the payoff be, almost surely, a Lipschitz function of the state. When the payoff contains an indicator (digital coupons, autocall triggers, barrier knock-outs), the interchange fails.
- The pathwise derivative of a digital payoff (the indicator that the underlying ends above the strike) is zero almost everywhere. The true derivative of the expectation is a positive density-weighted quantity, concentrated at the discontinuity. The labels are therefore biased (to zero), not merely noisy, and the network learns a systematically wrong delta.
- The same issue arises for second-order sensitivities of vanilla options: the pathwise delta of a call is an indicator, so gamma labels from the pathwise method are zero almost everywhere. Gamma from a DML surrogate is only as reliable as the smoothness of the fitted function allows. It is not supervised.
Remedies, each with a cost:
- Payoff smoothing. Replace the indicator by a sigmoid of bandwidth ε, or by a call spread. The bias vanishes with ε, but the variance of the derivative labels grows as ε → 0.
- Conditional expectation or Brownian bridge. Integrate the discontinuity analytically over the last step, for example through the barrier-crossing probability between nodes. This requires a tractable local law and is model-specific.
- Likelihood-ratio or vibrato estimators (Giles, 2009). Move the derivative to the density. The cost is higher variance and the need for transition densities.
- Mixed labels. Use pathwise derivatives on the smooth part and another estimator on the discontinuous part. The cost is implementation complexity.
- Reduced derivative weight. Lower λⱼ in affected regions. This gives up part of the benefit.
For products such as autocallables, smoothing choices change the price as well as the Greeks, so the smoothing bandwidth is a model parameter that must be documented and validated against a reference. This is treated in a separate article.
7. Implementation
The example below trains a DML surrogate for a European basket call under correlated geometric Brownian motion, a case with a reference solution for validation. The initial state is sampled on a normalized scale, one path per sample.
import math
import torch
import torch.nn as nn
torch.manual_seed(0)
d, T, r, K = 5, 1.0, 0.02, 1.0
sigma = torch.full((d,), 0.25)
w_b = torch.full((d,), 1.0 / d) # basket weights
corr = 0.5 * torch.eye(d) + 0.5 * torch.ones(d, d) # correlation matrix
L = torch.linalg.cholesky(corr)
def make_labels(n):
"""One path per initial state: value label and pathwise-derivative label."""
x0 = (0.5 + torch.rand(n, d)).requires_grad_(True) # states in [0.5, 1.5]
w = torch.randn(n, d) @ L.T # correlated normals
sT = x0 * torch.exp((r - 0.5 * sigma**2) * T + sigma * math.sqrt(T) * w)
z = math.exp(-r * T) * torch.clamp((sT * w_b).sum(1) - K, min=0.0)
dz, = torch.autograd.grad(z.sum(), x0) # reverse-mode AD
return x0.detach(), z.detach(), dz.detach()
class Net(nn.Module):
def __init__(self, d_in, width=128, depth=4):
super().__init__()
layers, k = [], d_in
for _ in range(depth):
layers += [nn.Linear(k, width), nn.SiLU()] # smooth activation
k = width
self.body = nn.Sequential(*layers)
self.head = nn.Linear(k, 1)
def forward(self, x):
return self.head(self.body(x)).squeeze(-1)
def dml_loss(model, x, z, dz, lam):
x = x.clone().requires_grad_(True)
pred = model(x)
dpred, = torch.autograd.grad(pred.sum(), x, create_graph=True) # double backprop
value_term = ((pred - z) ** 2).mean()
deriv_term = (lam * ((dpred - dz) ** 2).mean(0)).sum()
return value_term + deriv_term
x, z, dz = make_labels(8192)
lam = (z**2).mean() / (dz**2).mean(0) / d # one possible normalization (hyperparameter)
model = Net(d)
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
for epoch in range(300):
perm = torch.randperm(len(x))
for idx in perm.split(256):
opt.zero_grad()
dml_loss(model, x[idx], z[idx], dz[idx], lam).backward()
opt.step()Implementation issues:
- Input scaling and chain rule. If inputs are standardized, x̃ = (x − m)/s, the derivative labels must be rescaled as ∂z/∂x̃ = s · ∂z/∂x. Omitting this is a frequent source of silent errors: the loss still decreases but the Greeks are wrong by a constant factor.
- Label generation with AD. Memory for the reverse sweep grows with the number of time steps and paths. Use checkpointing or chunked path generation for long simulations. Gradients must flow only through the state and parameters of interest. Detach everything else.
- Differentiability of the simulator. Schemes with branches (for example the quadratic-exponential scheme for Heston) or truncation are differentiable almost everywhere, but the branch points should be checked, and random numbers must be held fixed during differentiation (reparametrization).
- Which derivatives are labelled. Derivatives with respect to the initial state are the natural choice. With AAD, derivatives with respect to model and contract parameters (vol, correlation, strike, maturity) are available at the same cost, and these can be added as inputs and labelled.
- Sampling distribution μ. The surrogate is valid on the support of μ. Domain definition, guard logic and fallback follow the principles discussed for pricing surrogates in general (see the first article of this series).
- Float precision. The loss contains second-order derivatives. Verify float32 against float64 on a validation batch before choosing the training precision.
- Optimization. Standard first-order optimizers work, but the derivative term can dominate early training. Warm-up of the weights λⱼ or a learning-rate schedule is advisable.
8. Validation
- Learning curves. Plot value and delta error against the number of training paths for (a) a value-only network, (b) DML, and © a polynomial or classical regression benchmark, with the same architecture, optimizer and tuning budget. This is the only credible evidence for the data-efficiency claim.
- Value and Greek error distributions. Report mean, quantiles (95th, 99th, 99.9th) and maximum, in absolute and relative terms, against a reference (closed form, PDE, or high-precision Monte Carlo with reported standard error).
- Derivative-consistency test. Compare the AD gradient of the network with a finite-difference gradient of the network itself (this should agree to numerical precision), and separately with the reference Greeks (this measures the approximation error).
- Second-order Greeks. Gamma and cross-gamma are not supervised. Test them explicitly against reference values and report them separately.
- Label-bias diagnostics. Compare the average derivative label with finite-difference estimates of the reference pricer on a grid of states. A systematic gap indicates a failure of the interchange (Section 6) and not noise.
- Error maps. Plot errors against moneyness, maturity, and distance to any barrier or trigger. Structure in the maps shows under-sampled or smoothed regions.
- Portfolio impact. Translate errors into P&L explain and sensitivity differences on a representative portfolio.
- Sensitivity to λⱼ and architecture. Report the range of outcomes over the weight choice and several seeds.
9. Methodological and Implementation Pitfalls
Methodological
- Treating derivative labels as unbiased without checking the regularity conditions: discontinuous payoffs, barriers, triggers, and exercise decisions.
- Assuming that supervised first derivatives imply accurate second derivatives.
- Reading improved accuracy against a reference that shares the same bias (for example identical discretization or smoothing).
- Reporting data efficiency without matching the tuning effort of the baseline.
- In Longstaff-Schwartz applications, ignoring that the fixed-policy derivative is approximate.
Implementation
- Missing chain-rule rescaling when inputs are normalized.
- Non-smooth activations.
- Memory exhaustion in the AD sweep for long simulations.
- Non-reproducible runs: random number streams, seeds, non-deterministic GPU reductions.
- An unguarded domain: the surrogate extrapolates silently outside the support of μ.
- Staleness: model, calendar or smoothing-parameter changes invalidate the surrogate without visible failure, and require versioning and revalidation.
10. Documentation Checklist
- Reference solver: convergence study; bias and standard error; independent benchmark.
- Labels: simulator and AD configuration; verification of pathwise derivatives against finite differences; regularity analysis of the payoff.
- Discontinuities: treatment (smoothing, bridge, likelihood ratio); bandwidth and its pricing impact.
- Sampling: distribution μ, size, seeds, domain bounds and justification.
- Loss: weights λⱼ, normalization, sensitivity analysis.
- Architecture: activation justification, input scaling and label rescaling check.
- Accuracy: value, Delta, Vega and Gamma errors (mean, quantiles, maximum); error maps.
- Baselines: value-only network and classical regression, with learning curves.
- Operations: versioning, domain guard, fallback to the reference solver, monitoring and retraining triggers.
11. Conclusions
DML exploits a feature of Monte Carlo that is otherwise wasted: pathwise derivatives are cheap through adjoint differentiation and carry information about the shape of the pricing function. Used as training labels, they improve sample efficiency and give Greeks that are consistent with prices by construction. The method is conditional on the regularity of the payoff. For smooth payoffs the derivative labels are unbiased and the benefits are substantial. For discontinuous payoffs they are biased unless the payoff is smoothed or the estimator is changed, and the choice then becomes a modelling decision with pricing consequences. Second-order Greeks remain unsupervised. Validation should therefore compare against reference Greeks, test explicitly for label bias, and use properly tuned baselines to establish the data-efficiency claim.
References
Differential machine learning and Sobolev training
- Huge, B., and Savine, A. (2020). Differential machine learning. Risk (arXiv:2005.02347).
- Czarnecki, W. M., Osindero, S., Jaderberg, M., Swirszcz, G., and Pascanu, R. (2017). Sobolev training for neural networks. Advances in Neural Information Processing Systems 30.
- Hornik, K., Stinchcombe, M., and White, H. (1990). Universal approximation of an unknown mapping and its derivatives using multilayer feedforward networks. Neural Networks, 3(5), 551–560.
Pathwise derivatives, adjoints and automatic differentiation
- Broadie, M., and Glasserman, P. (1996). Estimating security price derivatives using simulation. Management Science, 42(2), 269–285.
- Giles, M., and Glasserman, P. (2006). Smoking adjoints: fast Monte Carlo Greeks. Risk, 19(1), 92–96.
- Savine, A. (2019). Modern Computational Finance: AAD and Parallel Simulations. Wiley.
- Griewank, A., and Walther, A. (2008). Evaluating Derivatives: Principles and Techniques of Algorithmic Differentiation (2nd ed.). SIAM.
- Baydin, A. G., Pearlmutter, B. A., Radul, A. A., and Siskind, J. M. (2018). Automatic differentiation in machine learning: a survey. Journal of Machine Learning Research, 18, 1–43.
- Giles, M. B. (2009). Vibrato Monte Carlo sensitivities. In Monte Carlo and Quasi-Monte Carlo Methods 2008, Springer, 369–382.
- Glasserman, P. (2004). Monte Carlo Methods in Financial Engineering. Springer.
American Monte Carlo
- Longstaff, F. A., and Schwartz, E. S. (2001). Valuing American options by simulation: a simple least-squares approach. The Review of Financial Studies, 14(1), 113–147.
- Glasserman, P., and Yu, B. (2004). Number of paths versus number of basis functions in American option pricing. The Annals of Applied Probability, 14(4), 2090–2119.
- Fries, C. P. (2019). Automatic backward differentiation for American Monte-Carlo algorithms (conditional expectation). SSRN working paper.










