XVA valuation (CVA and the like) uses the Monte Carlo method to find many sensitivities. Quants, risk managers, and developers of valuation systems run into the problem that the computation time balloons as the number of sensitivities grows.

Why more sensitivities take longer

Bumping (finite differences) moves one input by a small amount, reruns the valuation, and divides the change in price by the size of the move. Each sensitivity (the Greeks, such as delta and vega) 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 formula below2. The definition of a sensitivity is covered in The Greeks.

∂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 points on the volatility surface. 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). In theory, the reverse mode of automatic differentiation can find all 1,000 in less than 5 times the original valuation (less than 5 minutes). This holds only when the output is a single price, and memory and other costs come on top.

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 hold down the noise2. 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, so finding the correlation sensitivity of every pair by bumping is often too heavy to be practical1.

The difference approximation in bumping is not the same as the finite difference method, which solves a partial differential equation on a grid.

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 (Jacobian matrices). The forward (tangent linear) mode works in the same direction as the computation and finds, step by step, how much a movement Z˙\dot Z of 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 calculation program is AAD (adjoint algorithmic differentiation)7.

Sensitivities of three inputs by 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 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
SimulatorNumber of sensitivities and run times of bumping and AAD
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. (Disclaimer)

About this simulator

Move the number of sensitivities, the time of one original valuation, and the AAD multiple to compare the run times of bumping and AAD. The initial values are 1,000 sensitivities and 1 minute per valuation, the same as in the bumping example; one-sided bumping takes 1,001 runs, or 16.7 hours. With the AAD multiple set to 4, AAD takes 4 minutes and does not change as the number grows. The bump time is 250.3 times as long. The vertical axis is scaled to the 1,001 minutes of bumping, so the 4 minutes of AAD looks like a flat line near 0. One-sided bumping becomes slower than AAD from 4 sensitivities at a multiple of 4, and from 3 sensitivities with central differences. The table below the chart is the 3-input example of this section: one adjoint pass returns 42, 28, and 14, and the differences from one-sided bumping with a step of 0.001 are 0.009, 0.004, and 0.001. With central differences the difference is 0, because the example is quadratic in each input. Shrinking the step to 10⁻⁶ makes the one-sided difference fall in proportion to the step, to 0.000009.

Computational cost, memory, and accuracy

There is a theoretical result that the computational cost of the reverse mode is less than 5 times that of the original computation, and it does not depend on the number of inputs. The cost of the forward mode grows in proportion to the number of inputs4. In the correlation sensitivity example too, the cost stays within 4 times that of finding the price once, regardless of the number of factors or pairs8.

However, one reverse run returns the sensitivities of a single output. When you want sensitivities of many outputs, the forward mode can find them with less additional work9.

On memory, the backward calculation uses the intermediate values found in the forward pass (such as v2v_2 in the example above). In a Monte Carlo method that works path by path, only the values of the current path need to be stored, so memory is described as not a heavy burden10. In a large pricing library, memory management and techniques such as checkpointing are said to 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 matches the true sensitivity is a separate question. For example, a discontinuous payoff cannot be used as it is with the method that differentiates the payoff path by path (the pathwise method).

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 one step's update, and let ff be 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) means a series of matrix-matrix products, which 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) lets you find 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}, which takes about m2m^2 per step12. Counting 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 is about m2×m^2 \times (number of parameters), so the gap widens as the parameters increase13.

Where it is used

For Greeks, a 2006 study used the reverse mode for the delta and vega of swaptions in the LIBOR market model, and Homescu describes it as a pioneering paper. For a portfolio of 15 swaptions, forward-mode automatic differentiation was about 10 times as efficient as bumping. With 80 time periods, the reverse mode was 5 times as efficient as the forward mode for delta alone and 25 times as efficient for delta and vega14. In the same passage Homescu also writes that the reverse mode cut the cost by "several orders of magnitude" compared with the forward mode, which reads as inconsistent with the figures of 5 and 25 times. The summary does not settle which is accurate. The study combines the reverse mode with the pathwise method, which differentiates the payoff with respect to the inputs path by path and averages the results.

Correlation sensitivities are another use. AAD has been applied to the valuation of baskets built with the Gaussian copula. In numerical tests on basket default options, the correlation sensitivities of all pairs were found within 4 times the price, regardless of the number of factors8. With 20 reference entities it was about 100 times as fast as bumping, and with 40 about 500 times15.

For the sensitivities of CVA, there is an example from a 2011 paper. For a portfolio of 5 commodity swaps over 5 years, there were more than 600 CVA sensitivities. With one CVA valuation taking 10 seconds, the reverse mode of automatic differentiation found all the sensitivities in under 40 seconds (less than 4 times one valuation), while bumping (finite differences) took about 1 hour 40 minutes16.

The gradient of the objective function in calibration (the sum of squared differences between model prices and market prices) contains the sensitivity of each price to the parameters, and the adjoint procedure can find it17. In an example from a 2009 paper, for the calibration of a lognormal variance model by Monte Carlo, a computation that took more than 3 hours when the gradient was found by finite differences took under 10 minutes with the adjoint18. The procedure is covered in Model Calibration.

Difficulties in adoption and where the assumptions break down

The pathwise method differentiates the payoff with respect to the inputs path by path and averages the results. It requires the payoff and the coefficients of the equation that builds the paths to be continuous and piecewise differentiable, so a discontinuous payoff cannot be handled as it is21. There are remedies such as approximating a digital option, smoothing the payoff with conditional expectation, and combining with the likelihood ratio method (which differentiates the probability density rather than the payoff with respect to the inputs)22. A product whose payment changes depending on whether a level is crossed, such as a barrier option, runs into this problem.

Implementations take one of two approaches: derive the derivative formula from the continuous equation and then discretize, or differentiate the discretized computation. The latter is often preferred. It is built systematically, and automatic differentiation tools can shorten development time23. Tools include those that generate code computing the sensitivities from the original code, and those that replace the operations with a type that pairs a value with its sensitivity24. To check an implementation, you can compare with the gradient from bumping, and you can also confirm that the forward-mode and reverse-mode gradients agree to machine precision19. In a large pricing library, memory management is also said to help.

What AAD speeds up is the sensitivity calculation inside a model. Uncertainty about the choice of option pricing model can create model risk in the valuation of a portfolio25.

Notes

  1. Capriotti and Giles, "Fast Correlation Greeks by Adjoint Algorithmic Differentiation" (arXiv, 2010), first two paragraphs of the introduction. 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" (Oxford University, lecture slides), pages 5–6 ("Finite difference sensitivities"). The difference formulas and cost, the error and noise from the step size, and the use of the same random numbers. ↩ ↩2 ↩3 ↩4

  3. Homescu, "Adjoints and automatic (algorithmic) differentiation in computational finance" (arXiv, 2011), 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. Homescu (arXiv, 2011), page 3 (section 1). The chain rule, the reverse-mode cost of less than 5 times (presented as a result from Griewank and Walther), which mode suits which case, and machine precision versus truncation error. ↩ ↩2 ↩3 ↩4

  5. Homescu (arXiv, 2011), 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. Homescu (arXiv, 2011), pages 4–6 (2.1, 2.2). The formula for the reverse (adjoint) mode. Transposed matrices give the adjoints in reverse order, and from Yˉ=1\bar{Y} = 1 one pass finds all the sensitivities. ↩ ↩2

  7. Capriotti and Giles (arXiv, 2010), fifth paragraph of the introduction. The adjoint implementation is an example of AAD, a programming technique that can be used to compute the sensitivities of numerical algorithms in general. ↩

  8. Capriotti and Giles (arXiv, 2010), abstract. In Monte Carlo valuation of baskets and in tests on portfolio default options, the correlation sensitivities of all pairs are found within 4 times the cost of finding the price. ↩ ↩2

  9. Giles (Oxford University, lecture slides), page 27 ("Adjoint approach"). The adjoint method gives the sensitivities of only one output, while the forward method gives the sensitivities of several outputs with little additional work. ↩

  10. Giles (Oxford University, lecture slides), page 25 ("Adjoint approach"). Only the data for the current path needs to be stored, so the memory requirement is not large. ↩

  11. Homescu (arXiv, 2011), page 19 (section 9). Because of the complexity of pricing libraries, automatic differentiation tools, memory management, and techniques such as checkpointing help. ↩

  12. Giles (Oxford University, lecture slides), pages 23–24 ("Adjoint approach"). The recursion, DnD_n, Vn=DnTVn+1V_n = D_n^T V_{n+1}, and the cost per step, O(m3)O(m^3) forward and O(m2)O(m^2) backward. FnF_n and ff are Giles's symbols. ↩ ↩2

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

  14. Homescu (arXiv, 2011), page 16 (section 8.1). A summary of the 2006 paper by Giles and Glasserman, with the figures of about 10, 5, and 25 times and, in the same paragraph, "several orders of magnitude". ↩

  15. Homescu (arXiv, 2011), page 17 (section 8.1). For basket default options, about 100 times as fast as bumping for 20 names and about 500 times for 40 names. ↩

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

  17. Homescu (arXiv, 2011), 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, and the adjoint procedure finds it. ↩

  18. Homescu (arXiv, 2011), page 19 (section 8.2). A summary of the 2009 paper by Kaebe, Maruhn, and Sachs, comparing more than 3 hours with under 10 minutes. It builds the adjoint from the continuous equation (ContAdj). ↩

  19. Homescu (arXiv, 2011), page 6 (section 2.3). The automatic differentiation gradient is compared with the finite difference gradient, and the forward and reverse gradients are expected to be identical to machine precision. ↩ ↩2

  20. Homescu (arXiv, 2011), pages 19–20 (section 9.1). A summary of a 2010 presentation by Baxter: each routine has a computation function and an adjoint function, and the adjoint functions are called in reverse order. ↩

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

  22. Giles (Oxford University, lecture slides), pages 20–21 ("Discontinuous payoffs"). A piecewise linear approximation for digitals, conditional expectation, and Vibrato Monte Carlo. Barriers are an example of conditional expectation. ↩

  23. Homescu (arXiv, 2011), page 3 (section 1). The names of the continuous and discrete adjoints, and why the discrete adjoint is preferred: it is systematic and shortens development. ↩

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

  25. Cont, "Model uncertainty and its impact on the pricing of derivative instruments" (Newton Institute preprint), abstract. Uncertainty about the choice of option pricing model can lead to "model risk" in the valuation of a portfolio of options. ↩