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 by is given by the following formula2.
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 , 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 through and to the output . is a single number, such as a price, and is the set of inputs whose sensitivities you want. When there are several inputs, 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 in the inputs carries through to the output5.
can hold the direction of only one input, so sensitivities need forward runs5.
The reverse (adjoint) mode computes backward, from the output to the inputs. It sets the adjoint of the output, , to 1 and finds the adjoint of each variable, such as , by using transposed matrices as follows6.
Each component of is the sensitivity of the output to the corresponding input. A single backward pass starting from finds all 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 is found from the inputs , , and in three steps.
In the notation of the previous section, corresponds to the input , and to the intermediate and , and to the output .
In the forward calculation (the original valuation), the intermediate values and the output are as follows.
| Step | Calculation | Value |
|---|---|---|
| 6 | ||
| 7 | ||
| 49 |
The backward calculation starts from and goes in reverse order. The partial derivative at each step is fixed by the intermediate values found in the forward pass (, , ).
| Adjoint | Calculation | Value |
|---|---|---|
| 14 | ||
| 14 | ||
| 14 | ||
| 42 | ||
| 28 |
One backward pass gives , , and at the same time. Differentiating the formula directly, gives 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 |
|---|---|---|---|
| 42 | 42.009 | 0.009 | |
| 28 | 28.004 | 0.004 | |
| 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.
- 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
| Input | Adjoint | Bump | Difference |
|---|---|---|---|
| x₁ | 42.0000 | 42.0090 | 0.009 |
| x₂ | 28.0000 | 28.0040 | 0.004 |
| x₃ | 14.0000 | 14.0010 | 0.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 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. is the state at time , is the initial value, and is the update for one step12.
Let be the partial derivative of the one-step update and the payoff at maturity. The sensitivity to the initial value is then the following product.
Multiplying from the side (forward) involves a run of matrix-matrix products and costs about per step for a state of dimension . Multiplying from the side (backward) finds the adjoint in turn by , at about per step12. Including the extra work for each input parameter, the backward cost is about (number of parameters) and the forward cost about (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
- The calculation of CVA itself is not covered on this page. See CVA and DVA.
- How the payoff of a barrier option works is not covered on this page. See Barrier Options.
- How sensitivities are used in market risk management is not covered on this page. See Sensitivities: DV01, Vega, and Key Rate Sensitivities.
Notes
-
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
-
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
-
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. ↩
-
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
-
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
-
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 finds all the sensitivities. ↩ ↩2
-
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. ↩
-
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
-
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
-
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. ↩
-
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. ↩
-
The Giles slides (external site), pages 23–24 ("Adjoint approach"). The recursion and the cost per step (forward , backward ). ↩ ↩2
-
The Giles slides (external site), pages 26–27 ("Adjoint approach"). differs by parameter while is shared, so the backward cost is (number of parameters). ↩
-
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
-
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. ↩
-
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. ↩
-
The Homescu paper (external site), page 16 (section 7). The gradient of contains the price sensitivities, which the adjoint can find. ↩
-
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). ↩
-
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. ↩
-
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. ↩
-
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. ↩
-
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. ↩
-
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. ↩
-
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). ↩