Skip to main content
Derivatives Compass

Numerical MethodsAdvancedEstimated reading timeAbout 10 min

Adjoint Algorithmic Differentiation (AAD)

Adjoint algorithmic differentiation (AAD) is a method that finds how much one computed result depends on each of many inputs (the sensitivities) in a single pass, by walking through the computation in reverse. Its cost does not depend on the number of inputs and stays within a few times that of the original computation. There are published cases of its use for Monte Carlo Greeks and for the sensitivities of CVA.

When the Monte Carlo method is used to find many sensitivities, such as the Greeks of options or those of XVA (CVA and the like), the computation time grows with the number of sensitivities. Quants and developers of valuation systems run into this problem.

Prerequisites

  • The Greeks IntroductoryTo learn what a sensitivity is and what the Greeks such as delta and vega mean.
  • Monte Carlo Simulation PractitionerTo learn how the paths are built that the pathwise method relies on.

Key points

  • Bumping needs one more rerun for each additional sensitivity.
  • The reverse mode of automatic differentiation suits many inputs and a single output.
  • The reverse mode costs less than 5 times the original computation, however many inputs there are.
  • With many outputs, the reverse mode needs more runs as well.

Why more sensitivities take longer

Bumping (finite differences) moves one input at a time by a small amount, reruns the valuation, and divides the change in price by the size of the move. It differs from the finite difference method, which solves a partial differential equation on a grid. Each sensitivity adds one more rerun, so the work grows in proportion to the number of sensitivities1. A one-sided bump that moves input θ\theta by Δθ\Delta\theta is given by the following formula2.

∂V∂θ≈V(θ+Δθ)−V(θ)Δθ\frac{\partial V}{\partial \theta} \approx \frac{V(\theta + \Delta\theta) - V(\theta)}{\Delta\theta}

Consider a hypothetical example in which a portfolio takes 1 minute to value once and you need 1,000 sensitivities, such as points on the interest rate curve and volatility points. A one-sided bump needs the original valuation plus 1,000 bumped valuations, 1,001 in all, which takes 1,001 minutes (about 16.7 hours). When the output is a single price, the reverse (adjoint) mode of automatic differentiation, which works backward from the output to the inputs, can in theory find all 1,000 sensitivities in less than 5 times the original valuation (less than 5 minutes). Memory and other costs come on top of that.

Number of sensitivities Valuations for a one-sided bump Time for bumping (minutes) Time for the reverse mode (minutes, theoretical upper bound)
10 11 11 less than 5
100 101 101 less than 5
1,000 1,001 1,001 less than 5

Besides the count, bumping has a problem with choosing the step size. The right size depends on the value of the input, and balancing accuracy against stability is not simple3. A step that is too large increases the approximation error, and for a discontinuous payoff a step that is too small makes the estimate noisy2. In the Monte Carlo method, the same random numbers are used before and after the bump to keep the noise down2. A central difference is more accurate, but it needs two reruns per sensitivity2.

For correlations the count grows even faster. With many random factors, the number of pairs grows with the square of the number of factors. Finding the correlation sensitivity of every pair by bumping is often too heavy to be practical1.

Forward mode and reverse (adjoint) mode

Automatic differentiation finds the derivatives of a computation written as a program by using the chain rule. However complex the program, it is a composition of elementary operations such as addition, multiplication, and sin⁡\sin, and the partial derivatives of those operations are known, so the derivative of the whole can be assembled4.

Suppose the computation runs from the input ZZ through AA and BB to the output YY. YY is a single number, such as a price, and ZZ is the set of inputs whose sensitivities you want. When there are several inputs, ∂A/∂Z\partial A / \partial Z and the like are matrices. The forward (tangent linear) mode works in the same direction as the computation and finds, step by step, how a move Z˙\dot Z in the inputs carries through to the output5.

Y˙=∂Y∂B ∂B∂A ∂A∂Z Z˙\dot{Y} = \frac{\partial Y}{\partial B}\,\frac{\partial B}{\partial A}\,\frac{\partial A}{\partial Z}\,\dot{Z}

Z˙\dot Z can hold the direction of only one input, so NN sensitivities need NN forward runs5.

The reverse (adjoint) mode computes backward, from the output to the inputs. It sets the adjoint of the output, Yˉ\bar{Y}, to 1 and finds the adjoint of each variable, such as Aˉ\bar{A}, by using transposed matrices as follows6.

Zˉ=(∂A∂Z)T(∂B∂A)T(∂Y∂B)TYˉ\bar{Z} = \left(\frac{\partial A}{\partial Z}\right)^{T}\left(\frac{\partial B}{\partial A}\right)^{T}\left(\frac{\partial Y}{\partial B}\right)^{T}\bar{Y}

Each component of Zˉ\bar{Z} is the sensitivity of the output YY to the corresponding input. A single backward pass starting from Yˉ=1\bar{Y} = 1 finds all NN of them6.

The reverse mode suits cases where there are few outputs whose sensitivities you want and many inputs. The forward mode suits the opposite case, with few inputs and many outputs4. When the output is a single portfolio value and the inputs are hundreds of market data points and model parameters, the reverse mode is the better fit. The technique of applying the reverse mode to a whole computer program is adjoint algorithmic differentiation (AAD)7.

Finding three sensitivities with the reverse mode

Consider a hypothetical example in which an output yy is found from the inputs x1=2x_1 = 2, x2=3x_2 = 3, and x3=1x_3 = 1 in three steps.

v1=x1x2,v2=v1+x3,y=v22v_1 = x_1 x_2, \qquad v_2 = v_1 + x_3, \qquad y = v_2^{2}

In the notation of the previous section, xx corresponds to the input ZZ, v1v_1 and v2v_2 to the intermediate AA and BB, and yy to the output YY.

In the forward calculation (the original valuation), the intermediate values and the output are as follows.

Step Calculation Value
v1v_1 x1×x2x_1 \times x_2 6
v2v_2 v1+x3v_1 + x_3 7
yy v2×v2v_2 \times v_2 49

The backward calculation starts from yˉ=1\bar{y} = 1 and goes in reverse order. The partial derivative at each step is fixed by the intermediate values found in the forward pass (v2=7v_2 = 7, x1=2x_1 = 2, x2=3x_2 = 3).

Adjoint Calculation Value
vˉ2\bar{v}_2 2v2×yˉ2 v_2 \times \bar{y} 14
vˉ1\bar{v}_1 1×vˉ21 \times \bar{v}_2 14
xˉ3\bar{x}_3 1×vˉ21 \times \bar{v}_2 14
xˉ1\bar{x}_1 x2×vˉ1x_2 \times \bar{v}_1 42
xˉ2\bar{x}_2 x1×vˉ1x_1 \times \bar{v}_1 28

One backward pass gives ∂y/∂x1=42\partial y/\partial x_1 = 42, ∂y/∂x2=28\partial y/\partial x_2 = 28, and ∂y/∂x3=14\partial y/\partial x_3 = 14 at the same time. Differentiating the formula directly, y=(x1x2+x3)2y = (x_1 x_2 + x_3)^2 gives ∂y/∂x1=2×7×3=42\partial y/\partial x_1 = 2 \times 7 \times 3 = 42 and so on, the same values. The forward mode would need 3 runs for 3 inputs. With only 3 inputs, bumping also needs just 4 valuations, counting the original. The gap in the number of runs widens with many inputs, such as the 1,000 sensitivities in the bumping example.

Compared with a one-sided bump of step size 0.001, the results are as follows. The bump values are larger than the true values because of the approximation error from the step size.

Input Reverse mode Bump (one-sided, step 0.001) Difference
x1x_1 42 42.009 0.009
x2x_2 28 28.004 0.004
x3x_3 14 14.001 0.001

The upper bound on the reverse-mode cost is presented as a theoretical result of less than 5 times4, and the bound on the number of operations is 4 times8. The simulator below uses 4 times. A one-sided bump becomes slower than the reverse mode from 4 sensitivities, and a central difference from 3.

SimulatorNumber of sensitivities and run times of bumping and AADOther simulators
Inputs
Bump difference
min
×
02004006008001,0001,20002004006008001,000Run time (minutes)Number of sensitivities
  • AAD
  • Bump (One-sided (count + 1 runs))

Derivatives of the 3-input example y = (x₁x₂ + x₃)² (x₁ = 2, x₂ = 3, x₃ = 1, y = 49); the difference is bump − adjoint

InputAdjointBumpDifference
x₁42.000042.00900.009
x₂28.000028.00400.004
x₃14.000014.00100.001

Number of runs: adjoint mode 1, forward mode 3, bump 4 (including the original valuation).

Bump run time
16.7 h
AAD run time (under 5 times one valuation in theory)
4.0 min
Bump ÷ AAD (how many times faster)
250.3
Number of bump valuations
1,001
Smallest number of sensitivities at which AAD is faster
4

Simplifications

  • Run time is a simple estimate: the time of one original valuation times the number of valuations or the multiple. Actual AAD times depend on the model, the product and the implementation.
  • The AAD multiple is under 5 times the original calculation in theory, whatever the number of inputs. The examples in the article stayed within 4 times. Memory cost is not included.
  • One-sided bumping is one original valuation plus one bumped valuation per sensitivity; central bumping is two per sensitivity. Reusing random numbers in Monte Carlo and running valuations in parallel are not considered.
  • The 3-input example is a small calculation in which the adjoint steps can be followed by hand. Adjoint mode uses the intermediate values of the forward pass and works backward, giving all 3 derivatives in one pass. The bump difference is the approximation error from the step size; because y is quadratic in each input, it is proportional to h for one-sided bumping and 0 for central bumping.

This simulator uses simplified calculations for learning. It cannot be used for valuing actual transactions or managing their risk. (Terms of Use)

About this simulator

Move the number of sensitivities, the time of one original valuation, the AAD multiple, and the bumping scheme to compare the run times. The initial values are 1,000 sensitivities and 1 minute per valuation, the same as in the bumping example. The vertical axis is scaled to the 1,001 minutes of bumping, so AAD looks like a flat line near 0. In the results, "Bump ÷ AAD" is the bumping time divided by the AAD time, and a larger value means AAD is faster. The "4 sensitivities" and "3 sensitivities" in the text cannot be reproduced with the slider, whose minimum is 10, so read them from "Smallest number of sensitivities at which AAD is faster" in the results. The table below the chart uses the three-input example above and shows the reverse-mode values and their differences from a one-sided bump of step 0.001. Switching to a central difference or shrinking the step makes these differences smaller.

Computational cost, memory, and accuracy

The run time of the reverse mode stays within about 4 times that of the original computation8. However, one reverse run returns the sensitivities of a single output. When there are several outputs, the pathwise method (which differentiates the payoff with respect to the inputs path by path and averages the results, using a forward calculation) can find them with less additional work9.

The backward calculation uses the intermediate values found in the forward pass (such as v2v_2 in the example above), so the forward pass stores them. In a Monte Carlo method that finds sensitivities path by path, only the values of the current path need to be stored, so the extra memory stays small. In some applications, such as fluid calculations, the storage can be excessive10. In large valuation libraries, techniques such as memory management and checkpointing can help11.

On accuracy, automatic differentiation returns the derivative of the computation as written in the program exactly, to machine precision, whereas bumping contains approximation error4. The bump difference of 0.009 in the example above is the error that remains even with a step size of 0.001. Whether the computation itself agrees with the true sensitivity is a separate question, and discontinuous payoffs are the typical case.

Deep diveThe adjoint along a stochastic differential equation path and the cost

Suppose a Monte Carlo path is built by the following recursion. S^n\hat{S}_n is the state at time nn, S0S_0 is the initial value, and FnF_n is the update for one step12.

S^n+1=Fn(S^n)\hat{S}_{n+1} = F_n(\hat{S}_n)

Let Dn=∂Fn/∂S^nD_n = \partial F_n / \partial \hat{S}_n be the partial derivative of the one-step update and ff the payoff at maturity. The sensitivity to the initial value is then the following product.

∂f(S^N)∂S0=∂f∂S^N DN−1DN−2⋯D0\frac{\partial f(\hat{S}_N)}{\partial S_0} = \frac{\partial f}{\partial \hat{S}_N}\, D_{N-1} D_{N-2} \cdots D_0

Multiplying from the D0D_0 side (forward) involves a run of matrix-matrix products and costs about m3m^3 per step for a state of dimension mm. Multiplying from the ∂f/∂S^N\partial f / \partial \hat{S}_N side (backward) finds the adjoint Vn=(∂f/∂S^n)TV_n = (\partial f / \partial \hat{S}_n)^T in turn by Vn=DnTVn+1V_n = D_n^{T} V_{n+1}, at about m2m^2 per step12. Including the extra work for each input parameter, the backward cost is about m2+m×m^2 + m \times (number of parameters) and the forward cost about m2×m^2 \times (number of parameters), so the gap widens as the parameters multiply13.

Where AAD is used

In a 2005 case presented by Giles and Glasserman, the Monte Carlo method of the LIBOR market model (LMM) was used. For a portfolio of 15 swaptions, delta and vega were computed. As the number of periods to expiry was increased from 1 to 80, the work of the forward mode grew in proportion to the number of periods, while the work of the reverse mode stayed roughly constant14. Adding vega to delta barely increased the work of the reverse mode. The reverse mode found the sensitivities to any number of inputs with less work than valuing the portfolio14.

In a 2010 case presented by Capriotti and Giles, a basket default option built with a Gaussian copula was tested. The sensitivities to the correlations of all pairs were found with at most 4 times the work of computing the price. With 20 reference entities, it was about 100 times faster than bumping15.

In a 2011 case presented by Capriotti, Lee, and Peacock for CVA, the portfolio held 5 commodity swaps with a 5-year horizon, and one CVA valuation took 10 seconds. The CVA had more than 600 sensitivities. Reverse-mode automatic differentiation found all of them in less than 40 seconds (less than 4 times one valuation). Bumping (finite differences) took about 1 hour and 40 minutes16.

The gradient of the objective function of calibration (the sum of squared differences between model prices and market prices) contains the amount by which each price moves with the parameters, and the adjoint procedure can find it17. In a 2009 case presented by Kaebe, Maruhn, and Sachs, a lognormal variance model was calibrated by the Monte Carlo method. A computation that took more than 3 hours with a finite difference gradient took less than 10 minutes when the adjoint was combined with a multi-layer method18.

For risk managers: Checking sensitivities

The gradients from the forward mode and the reverse mode are expected to agree to machine precision. They are compared with the bumped gradient within the approximation error from the step size19.

For systems professionals: Building it into a valuation library

In a structure presented by Baxter in 2010, each routine, such as interpolation, calibration, and pricing, comes with a function that passes sensitivities backward. These functions are called in turn from the price toward the input market data20.

Assumptions and limits

Discontinuous payoffs

The pathwise method requires the payoff and the coefficients of the equation that builds the paths to be continuous and piecewise differentiable, and it cannot handle discontinuous payoffs directly21. Remedies include approximating a digital option and smoothing the payoff with a conditional expectation. It can also be combined with the likelihood ratio method (which differentiates the probability density rather than the payoff with respect to the inputs)22. Products whose payment depends on whether a level is crossed, such as a barrier option, run into this problem.

When there are many outputs

Take the example of 1,000 sensitivities and 1 minute per valuation, but suppose the outputs are 300 values, one per trade, instead of a single portfolio value. If one valuation produces all 300 outputs, a one-sided bump still takes 1,001 minutes, as with one output. The reverse mode needs one run per output9, so at the upper bound of 5 times it is less than 300 × 5 = 1,500 minutes, and it can no longer be said to beat the 1,001 minutes of bumping.

Differences from other methods

Method How the work grows Suits Weak point
Bumping In proportion to the number of sensitivities Simple to implement2 Approximation error and noise from the step size
Forward mode In proportion to the number of inputs Few inputs and many outputs More runs when there are many inputs
Reverse mode Independent of the number of inputs, less than 5 times the original computation Many inputs and few outputs More runs when there are many outputs. Intermediate values must be stored

Implementation approaches

In implementation, one approach derives the derivative equations from the continuous equations and then discretizes them. The other differentiates the discretized computation. The latter is more systematic to build and can shorten development time with automatic differentiation tools, so it is often preferred23. The tools either generate code from the original code that also computes the sensitivities, or replace the operations with a type that pairs a value with its sensitivity24.

What this page does not cover

Notes

  1. Capriotti and Giles, "Fast Correlation Greeks by Adjoint Algorithmic Differentiation" (external site) (arXiv, 2010; the "Capriotti and Giles paper"), page 1, first two paragraphs. The cost of bumping grows in proportion to the number of sensitivities, and for all pairs of correlations with the square of the number of factors. ↩ ↩2

  2. Giles, "Advanced Monte Carlo Methods: Computing Greeks" (external site) (Oxford University, lecture slides; the "Giles slides"), pages 5–6 ("Finite difference sensitivities"). The difference formulas and cost, the error and noise from the step size, the use of the same random numbers, and simplicity of implementation. ↩ ↩2 ↩3 ↩4 ↩5

  3. Homescu, "Adjoints and automatic (algorithmic) differentiation in computational finance" (external site) (arXiv, 2011; the "Homescu paper"), page 4. The finite difference step size depends on the value of the input, and choosing a step that balances accuracy and stability is difficult. ↩

  4. The Homescu paper (external site), page 3 (section 1). The chain rule, the reverse-mode cost of less than 5 times (presented as a theoretical result), which mode suits which case, and machine precision versus truncation error. ↩ ↩2 ↩3 ↩4

  5. The Homescu paper (external site), pages 4–6 (section 2). The formula for the forward (tangent linear) mode and the need for one computation per input direction. The notation is Homescu's, with the three steps Z, A, B, Y. ↩ ↩2

  6. The Homescu paper (external site), pages 4–6 (2.1, 2.2). The formula for the reverse (adjoint) mode. It works in reverse order with transposed matrices, and one run from Yˉ=1\bar{Y} = 1 finds all the sensitivities. ↩ ↩2

  7. The Capriotti and Giles paper (external site), page 1, fifth paragraph of the introduction. The adjoint implementation is an instance of a programming technique called AAD, usable for the sensitivities of numerical algorithms in general. ↩

  8. The Capriotti and Giles paper (external site), page 2. The number of operations in the adjoint routine is at most 4 times that of the original routine, and the execution time is bounded by about 4 times. ↩ ↩2

  9. The Giles slides (external site), page 27 ("Adjoint approach"). The adjoint approach gives the sensitivity of only one output, while the forward approach gives the sensitivities of several outputs at little additional cost. ↩ ↩2

  10. Giles and Glasserman, "Smoking Adjoints: fast evaluation of Greeks in Monte Carlo calculations" (external site) (August 2005; the "Giles and Glasserman paper"), pages 8 and 15 (Appendix A). Only the current path needs to be stored, and storage can be excessive in fluid calculations. ↩

  11. The Homescu paper (external site), page 19 (section 9). Because of the complexity of pricing libraries, automatic differentiation tools, memory management, and checkpointing can help. ↩

  12. The Giles slides (external site), pages 23–24 ("Adjoint approach"). The recursion and the cost per step (forward O(m3)O(m^3), backward O(m2)O(m^2)). ↩ ↩2

  13. The Giles slides (external site), pages 26–27 ("Adjoint approach"). BnB_n differs by parameter while VnV_n is shared, so the backward cost is m2+m×m^2 + m \times (number of parameters). ↩

  14. The Giles and Glasserman paper (external site), section 7 (pages 11–12). In the test with 15 swaptions and 1 to 80 periods, the costs of the forward and reverse methods, the effect of adding vega, and the reverse cost being below that of one valuation. ↩ ↩2

  15. The Capriotti and Giles paper (external site), the abstract on page 1 and the conclusion on page 6. In the test, the sensitivities to all pairwise correlations took at most 4 times the cost of the price, and the method was 100 times faster than bumping for 20 names. ↩

  16. The Homescu paper (external site), page 17 (section 8.1). A summary of the 2011 paper by Capriotti, Lee, and Peacock: less than 40 seconds for the reverse mode and about 1 hour and 40 minutes for finite differences. ↩

  17. The Homescu paper (external site), page 16 (section 7). The gradient of F=∑(ModelPrice[j]−MarketPrice[j])2F = \sum (\text{ModelPrice}[j] - \text{MarketPrice}[j])^2 contains the price sensitivities, which the adjoint can find. ↩

  18. The Homescu paper (external site), page 19 (section 8.2). A summary of the 2009 paper by Kaebe, Maruhn, and Sachs, comparing more than 3 hours with less than 10 minutes. The adjoint is derived from the continuous equations (ContAdj). ↩

  19. The Homescu paper (external site), page 6 (section 2.3). Comparing the automatic differentiation gradient with the finite difference gradient, and the forward and reverse gradients being expected to be identical to machine precision. ↩

  20. The Homescu paper (external site), pages 19–20 (section 9.1). A summary of a 2010 presentation by Baxter, with an example of representing each routine by a calculation function and an adjoint function and calling them in reverse order. ↩

  21. The Giles slides (external site), page 11 ("Pathwise sensitivities"). The conditions are a continuous, piecewise differentiable payoff and coefficients, and discontinuous payoffs cannot be handled. ↩

  22. The Giles slides (external site), pages 20–21 ("Discontinuous payoffs"). A piecewise linear approximation for digitals, conditional expectations, and Vibrato Monte Carlo. The barrier option is an example of a conditional expectation. ↩

  23. The Homescu paper (external site), page 3 (section 1). The names of the continuous and discrete adjoints, and the discrete adjoint being preferred because it is systematic and can reduce development time. ↩

  24. The Giles slides (external site), page 19 ("Automatic Differentiation"). The approach that generates new code from source code, and the one that redefines operations on a type pairing a value with its sensitivity (operator overloading). ↩

Check your understanding of this page

Taken from the chapter quiz to check what this page explains.

  1. Question 1

    As a fictional example, one evaluation of a portfolio takes 3 minutes, and you want 200 sensitivities. The output is a single portfolio value. Which pair gives the time for one-sided bumping (moving one input at a time) and the theoretical time for AAD (adjoint algorithmic differentiation) in reverse (adjoint) mode?

    Answer and explanation

    Answer: A

    Bumping takes 603 minutes and reverse mode under 15 minutes. One-sided bumping is the original evaluation plus 200 evaluations with an input moved, 201 in total. At 3 minutes each, the 201 evaluations take 201 × 3 = 603 minutes. Theoretically, reverse mode costs under 5 times the original evaluation, whatever the number of sensitivities. At 3 minutes per evaluation, that is under 3 × 5 = 15 minutes.

    The 600 minutes for bumping comes from forgetting the original evaluation and calculating 200 × 3. Taking reverse mode as 600 minutes confuses it with forward mode automatic differentiation, whose cost grows in proportion to the number of sensitivities. Forward mode needs one calculation for each input direction. The under-15-minutes figure is a theoretical upper bound for a single output, and memory and other costs come separately.

Take the full chapter quiz (5 questions)

Summary

  • Bumping needs one more rerun for each additional sensitivity.
  • The reverse mode of automatic differentiation suits many inputs and a single output.
  • The reverse mode costs less than 5 times the original computation, however many inputs there are.
  • With many outputs, the reverse mode needs more runs as well.

Read next

Share this page

In the learning roadmaps