Your SlideShare is downloading.
×

- 1. Danske Bank Practical Implementation of AAD for Derivatives Risk Management, xVA and RWA Hans-Jørgen Flyger, Brian Huge, Antoine Savine
- 2. www.danskemarkets.comAAD Danske Bank • AAD − A game changer for the computation of risk sensitivities − Applies to risks of derivatives books, xVA, capital charges, etc. − Useful beyond risk calculations: calibration, static hedge optimization, transaction costs, VAR, ... • AAD is easy in theory − Mathematically: an application of the chain rule − Implementation in C++ with operator overloading now well known See for instance, Savine, Global Derivatives 2014 (We also quickly recap the main principles) − Quick and easy implementation with toy code, with ”magical” results • AAD is hard in practice − With real-life production systems, however, implementation of AAD is challenging − Quants in Danske Bank spent a couple of years implementing AAD across production systems (and were granted the Risk 2015 In-House System of the Year award for their efforts) − We expose the main problems and share some solutions 2 Introduction AAD in Finance 1/3 , x x gx f x g x f g f
- 3. www.danskemarkets.comAAD Danske Bank • Traditionally, with finite difference or ”bumping” − Bump inputs one by one and recalculate − Sensitivity to n inputs costs n evaluations − Even with smart caching, computation time remains proportional to n • With AAD − All sensitivities are computed in one single sweep − Sensitivity to n inputs takes constant time! − In a given context, 5 sensitivities or 5,000 sensitivities are computed in the same time − The time is approx 4-8x a single evaluation • Example: pricing takes 2sec, we produce 1,600 risks − Bumping: ~1 hour − AAD: 5sec − Multithreaded over 4 cores: bumping = 15min, AAD = 1.25sec 3 Introduction The power of AAD 2/3
- 4. www.danskemarkets.comAAD Danske Bank 1) Recap AAD 101: mathematics and implementation 2) Efficient differentiation of main financial algorithms − Multi-dimensional PDEs with check-pointing − Monte-Carlo simulations with multi-threading − Calibrations with the Implicit Function Theorem (IFT) 3) Application to CVA and RWA 4 Introduction Overview 3/3
- 5. www.danskemarkets.comAAD Danske Bank Reverse Adjoint Propagation • Consider a scalar function with value where we are interested in calculating derivatives for the n independent variables • Any such function evaluated on a computer is – for a given control flow – decomposed into a sequence of elementary mathematical operations: +, -, *, /, exp, log, pow, … • The elementary operations are unary or binary and the sequence can be written as and the result • The order of the operations is given by the compiler 5 Decompose into a sequence of elementary mathematical operations 1/4
- 6. www.danskemarkets.comAAD Danske Bank Reverse Adjoint Propagation • For each intermediate operation/variable we define the associated adjoint • We have and from the chain rule • I.e. for each elementary operation fj (j>i) having argument(s) xi − we calculate the analytically known − And add to the adjoint Ai for argument xi ! − … adjoints are propagated from result to the argument(s) • All adjoints are calculated by going through the same sequence of operations as for the (usual fwd) value calculation once − But calculating adjoint contributions instead of results at each node − … in reverse order starting from AN with initial condition 6 Reverse adjoint propagation 2/4
- 7. www.danskemarkets.comAAD Danske Bank Operation Val Adjoint contrib Aggregated adjoint x1=2 2 x2=3 3 x3=4 4 x4=x1*x2 6 A1+=A7*x2 A1=2+3/10 A2+=A4*x1 A2=2/10 x5=x4+x3 10 A4+=A5*1 A4=1/10 A3+=A5*1 A3=1/10 x6=log(x5) log(10) A5+=A6/x5 A5=1/10 x7=2*x1 4 A1+=A7*2 A1=2 x8=x7+x6 4+log(10) A7+=A8*1 A7=1 A6+=A8*1 A6=1 A1=…=A7=0, A8=1 Reverse Adjoint Propagation Calculate value and derivatives for 7 Simple example 3/4 Adjoint contrib Aggregated adjoint A1+=A4*x2 A1=2+3/10 A2+=A4*x1 A2=2/10 A4+=A5*1 A4=1/10 A3+=A5*1 A3=1/10 A5+=A6/x5 A5=1/10 A1+=A7*2 A1=2 A7+=A8*1 A7=1 A6+=A8*1 A6=1 A1=…=A7=0, A8=1 A1=2+3/10 A2=2/10 A3=1/10
- 8. www.danskemarkets.comAAD Danske Bank Reverse Adjoint Propagation • I.e. to calculate the derivatives of a function , we: 1. Do the usual forward calculation to get y … keeping track of the entire sequence of operations fj and argument(s) xi 2. Calculate adjoints by running the sequence backwards, starting at • This may be implemented by 1. Source transformation (e.g. tapenade) 2. Templates and operator overloading in a modern language • We use templates and operator overloading in C++ … but in all cases is the computational time independent of the number of sensitivities 8 Implementation 4/4
- 9. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ • To implement AAD using templates and operator overloading, we need 4 basic ingredients 1. A customized number type 2. Operator nodes 3. A ”tape” for storing operator nodes 4. An AD evaluator that calculate adjoints by running the tape backwards • Since extra work is introduced for each single mathematical operation, optimizing this part of the code is essential! 9 The 4 ingredients 1/6
- 10. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ 1. Customized number type − A class for representing numbers (we call it kDoubleAd) − Overload all elementary mathematical operations for kDoubleAd : +, -, *, /, exp, log, pow, … − As a side effect in the overload, the performed operation is stored as a node on “the tape” − The kDoubleAd only needs to contain a pointer to the operator node − … e.g. in our earlier example, y contains a pointer to operator node 8 (”+” operator) 10 First ingredient: kDoubleAd 2/6 • Perform the calculation (e.g. ) using kDoubleAds instead of native doubles to store the operations − … by templatizing calculation code
- 11. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ 2. Operator node − The operator nodes are stored on the “tape” and contains what is needed to calculate the adjoint contributions: − The type of the operation (+, -, *, /, exp, log, pow, …) − The result of the operation − Pointer to the argument node(s) − Placeholder for the adjoint 11 Second ingredient: operator nodes 3/6
- 12. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ 3. The tape − The tape is the memory for the operator nodes and contains the entire sequence of operator nodes − The tape is static (thread_local) to make it accessible for all calculation code − Memory is allocated as a list of (big) blocks of contiguous memory − … to limit expensive memory allocations − … to help the computer’s memory prefetcher (more about that later) Third ingredient: The tape 4/6 Return constructed kDoubleAd using RVO Construct new operator node using placement new Node type Node result LHS argument node RHS argument node 12
- 13. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ 4. The AD RAP evaluator − Set the initial condition for the adjoints and run backwards through the operator nodes on the tape to calculate all adjoints − At each operator node, adjoints are propagated from result to argument node(s) 13 Fourth ingredient: The AD RAP evaluator 5/6 − When done, the derivative can be picked from the operator node i (e.g. through the pointer to the operator node sitting on the relevant kDoubleAd variable)
- 14. www.danskemarkets.comAAD Danske Bank AAD with Operator Overloading in C++ AAD complexity • Fwd calculation: ~ 1 * (non-AD) fwd calculation − Operator overload side effect − Memory allocation • Bwd calculation: ~ 1 * (non-AD) fwd calculation − ~2 times the (AD) fwd calculation − Operator node traversal − More calculations at each node − E.g. 2 multiplications and 2 additions for the multiplication node • Expect 4–8 * (non-AD) fwd calculation • … but constant in number of sensitivities! 14 Complexity 6/6
- 15. www.danskemarkets.comAAD Danske Bank Memory Usage • Using kDoubleAds quickly fills the tape with operator nodes − Each core typically produces around 108 operator nodes per sec … corresponding to 4 GB/sec • … using 64 bit code is a necessity for production scale calculations • Keep tapes small … − When the tape is traversed backwards to calculate adjoints, each node is read from the CPUs memory cache. − Due to the contiguous memory structure of the tape, the memory pre-fetcher can (and will) load subsequent nodes into the memory cache before the CPU needs them − BUT it can not predict and pre-fetch the argument nodes − … resulting in a high number of cache misses for long tapes (where the CPU has to wait for data to be loaded from the slow main memory) • Keeping tapes small – and ideally small enough to fit into the cache – is important for performance! − … a large number of small tapes is much better than a small number of large tapes! 15 Memory usage and memory cache 1/1
- 16. www.danskemarkets.comAAD Danske Bank Checkpointing • Checkpointing is a general technique for splitting the AAD calculation into a number of smaller slices/tapes − Split the algorithm into M slices − and calculate (non-AD) values for the first M-1 slices − A tape is generated for the final slice M − and adjoints are calculated using the usual initial conditions − The tape for slice M is wiped and a tape is generated for slice M-1 − This time adjoints are calculated using the calculated derivatives from slice M as initial condition − i.e. we “glue” tapes together via the adjoints • This is a general method and works well with finite difference grids 16 Reduce tape size by checkpointing 1/2
- 17. www.danskemarkets.comAAD Danske Bank Checkpointing Calculate derivatives for Split in 2 slices: 17 The simple example extended to use checkpointing 2/2 Slice 1 Calc value of slice 1 (use double – no AD) Generate tape for slice 2 (use kDoubleAd) Slice 2 Slice 1 Slice 2 Generate tape for slice 1 (use kDoubleAd) Set initial conditions Run slice 2 bwds to calculate adjoints Slice 2 Store derivatives and wipe tape Set initial conditions Run slice 1 bwds to calculate adjoints Pick derivatives from the xi nodes and wipe tape 1 2 3 4 5 6 7 y 17
- 18. www.danskemarkets.comAAD Danske Bank • Consider the matrix multiplication where • If we need for different then we do the multiplication first and apply the result to each of the • Instead, if we need for different then we do the multiplication first and apply the result to each of the • Remember, the adjoint of a matrix is the transpose 18 1 2 T Z X B B Y 1 2, , , ,M M M B B X Y Z 1 2 T Z X B B Y 1, , LZ Z 1, , LY Y 1 2 T X B B 'Y s 1, , LZ Z 1, , LX X 2 1 T T T Y B B 'X s 1/7Linear Algebra of AAD Is AAD magic?
- 19. www.danskemarkets.comAAD Danske Bank 19 1 1 2 32 logy x x x x 4 1 2 4 1 2 1 2 5 3 4 5 3 4 6 5 5 6 5 7 1 7 1 8 6 7 8 6 7 1 2 log 3 2 4 2 5 x x x n x x x x x x x x n x x x x x x n x x x x n x x x x x n x x x 2/7Linear Algebra of AAD Toy example again
- 20. www.danskemarkets.comAAD Danske Bank • Define and let the matrix be the calculation for step • Since differentiation is a linear operation each calculation can be it written in matrix form as or starting from the boundary condition we have 20 1 8 x n X n x n A n 1, ,n N 1X n A n X n 0X 1 1 0 0 N i X N A N A X A i X 3/7Linear Algebra of AAD Calculations on vector form
- 21. www.danskemarkets.comAAD Danske Bank • First calculation step is • Hence where 21 1n 4 1 2 1 2 4 2 1 1 0 0 0 0 1 0 0 0 0 0 x x x x x x x x X 1 1 0X A X 2 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 x x A 4/7Linear Algebra of AAD Calculation step 1
- 22. www.danskemarkets.comAAD Danske Bank 22 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 2 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 A 5 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 3 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 A x 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 4 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 A 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 5 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 A 5/7Linear Algebra of AAD Calculation steps 2, 3, 4 and 5
- 23. www.danskemarkets.comAAD Danske Bank • From this we get where is the ’th unit vector • We need to calculate the system with 3 different boundary conditions • The easiest way is to calculate it forward as and then apply the 3 different boundary conditions • This is equivalent to pick the first 3 elements 23 8 8 1 0 N T T i y e X N e A i X 8 1 11 8 2 12 8 3 13 N T i N T i N T i y e A i e x y e A i e x y e A i e x ie i 1 2 3 , ,e e e 8 15 71 2 3 4 6 8 N T i y y y y y y y y e A i x x x x x x x x 1 2 3 y y y x x x 6/7Linear Algebra of AAD Going forward
- 24. www.danskemarkets.comAAD Danske Bank • Checkpointing is just a sub sequence • Also notice that any sub sequence of calculations is a Jacobian • I.e. for any we have • This can be a useful reference when we discuss risk propagation later 24 1 10 T T T N K n n y y yA n A n X N X KX Slice 1 1 T N n K y A n X N Slice 2 1 T K n y A n X K 1 T T T K n k X Ky y yA n X K X KX k X k K k 7/7Linear Algebra of AAD Sub sequences
- 25. www.danskemarkets.comAAD Danske Bank • Arbitrage free volatility surface − Andreasen and Huge: Volatility interpolation (Risk March 2011) • Stochastic volatility model − Andreasen and Huge: Random Grids (Risk July 2011) 25 , 1 , 0 1 0 ds t s zdW dz z dt z dZ z dWdZ Checkpointed AAD for PDE finite difference grids Example: SLV – 2D PDE 1/4
- 26. www.danskemarkets.comAAD Danske Bank • Discrete time and state space (FD) • where is the cashflow at some future time • is the present value • is a matrix with the finite differences 26 nd 0v iA 1 1 1 , 0,1, , n i j n i i j i v A d A v i n Checkpointed AAD for PDE finite difference grids Grid setup 2/4
- 27. www.danskemarkets.comAAD Danske Bank • is a function of parameters to which we want risks • To find we run the following checkpointed procedure 1. Run the whole FD without AD and record all the vectors 2. Run the step with AD, record a tape 3. Run RAP over the tape to get 4. Record to be used as boundary for the next RAP over then wipe the tape 5. Repeat from step 2 27 iA ia 0 j v a 0 0 1 1 , v v a v Checkpointed AAD for PDE finite difference grids Algorithm 3/4 iv 0 1 1v Av 0 1 v v 1 2 2v A v 1 1i i iv A v
- 28. www.danskemarkets.comAAD Danske Bank AD tape step 1 AD tape step 2 0 1 2 3 n-1 n AD tape step 3 AD tape step n Checkpointed AAD for PDE finite difference grids Algorithm 4/4 Running value backward Running AD forward step by step 1 0 i v v 0 i v a 28
- 29. www.danskemarkets.comAAD Danske Bank • AAD for Monte Carlo may consume a lot of memory − 10sec MC run around 40GB for the tape • Monte Carlo simulation suggests multi threading − Each path can be handled independently and run in parallel • Running each path separately would also reduce the need for memory − Similar to check pointing in the sense it creates more manageable calculations • AAD creates dependency between paths − Variables/cashflows are averages across paths • How do we combine AAD and multi threading? 29 1/4AAD for Monte-Carlo simulations The problem
- 30. www.danskemarkets.comAAD Danske Bank • Giles and Glasserman: ”Smoking Adjoints: fast Monte Carlo Greeks” introduced adjoint differentiation in Finance. They used pathwise derivatives • Essential idea is that under suitable conditions • Derivatives can be calculated as Monte Carlo estimates on a different payoff • New ”payoff” can easily be calculated with AAD • We are again in a situation where Monte Carlo paths can be treated independently 30 =E E Cashflow Cashflow a a 2/4AAD for Monte-Carlo simulations Pathwise derivatives to the rescue
- 31. www.danskemarkets.comAAD Danske Bank • The derivatives are calculated as • Each is calculated with AAD over path i − One tape per simulation, maximum time 1/100sec up to 40MB, almost fits in CPU cache − Record and wipe the tape between simulations • Result = average of • Remember that the output from the tapes is ALL the derivatives so we only need to run this procedure only once 31 1 1 1 1n n i i i i E Cashflow Cashflow X a n a n iX 3/4 iX iX AAD for Monte-Carlo simulations Pathwise derivatives with AAD
- 32. www.danskemarkets.comAAD Danske Bank • Multithreading − Run Monte-Carlo paths in parallel − Compute pathwise derivatives with AAD in parallel • Problem: − Templated code writes to a global/static tape − Writing to the tape from parallel threads leads to race conditions • Solution: give each thread its own tape − thread_local objects are like global/static except each thread has its own copy − Support for thread local in C++11 standard, Boost, Windows API, ... • Hence what it takes for AD to work with multi-threaded Monte-Carlo: − Create a tape for each thread, access it through thread local variables − Obviously, work with per thread/task copies of variables written into − In addition, copy inputs into custom number types per thread/task so they land on the right tape! 32 4/4AAD for Monte-Carlo simulations Multi-threading
- 33. www.danskemarkets.comAAD Danske Bank Risk propagation 33 • Methods explained so far produce derivatives of result to model params like local volatilities in Dupire • We want derivatives to market variables, like implied volatilities in Dupire • Model parameters are derived from market variables in one or more steps that may involve calibrations • To Naively run AAD over this process may be unstable and memory consuming • FAQ: how to run AAD through calibration? • Solution: first run model with AAD to get sensitivities to model parameters Then propagate sensitivities backwards to market variables 1/9
- 34. www.danskemarkets.comAAD Danske Bank Backward Risk Propagation and RAP 34 • RAP: Backward propagation of sensitivities at micro (math operation) level • Risk propagation: Backward propagation of sensitivities at macro (param) level 0 2 2 4log 2y x x x x Market data -> Interpolated IV -> Calculated LV -> Price 2/9
- 35. www.danskemarkets.comAAD Danske Bank , 02 2 , , , , T K T KK C K T K T g a S K C K T Risk Propagation by example: Dupire’s model 35 observed market implied BS volatilities ˆ ˆ ˆ ˆ , 1 i i i iK T i n IV surface = all vanilla option prices 0,, ,a SC K T f K T Local Volatility ,tS t computation of LV Result V Monte-Carlo, PDE AADk V calibration of a Result V step 1 1 ja a j m n , 1 k k k kS t k p Tape Pastingj V a step 2 Implicit Function Theorem step 3 ˆi V step 1 step 2 step 3 Explicit function (Dupire) Implicit function 0 2 0 , 0 , 0 ˆ, ˆ: min , , , ˆ, ,i i i i i a i i K T K T a h S h e e e a S e w C a S BS S spot S0 spot S0 spot S0 0 V S 0 0 k k V V S S 0 0 j j aV V S a S Pricing Risk 3/9
- 36. www.danskemarkets.comAAD Danske Bank • Step 2 in our example: computation of local volatilities − We know sensitivities to LVs from step 1 − We want to propagate them to sensitivities to interpolation parameters − We could compute the Jacobian of g and apply the chain rule − We can do this orders of magnitude faster with tape pasting (but only for explicit functions) Propagation through explicit functions: Tape Pasting 36 run explicit function in AAD mode a1 record tape RAP V aV 02 2 02 2 0 2 , 2 , , , , , , , , , T k k T k k k k k k KK k k KK k k C K T f a S K T K T g a S K C K T K f a S K T a2 … am 1 2 … p Vinject adjoints pick adjoints aV 0,g a S a aV Va S0 0SV 0SV pick final inject initial 4/9
- 37. www.danskemarkets.comAAD Danske Bank • Step 3 in our example , where h is implicitly defined by a calibration − We know the sensitivities to interpolation parameters from step 2 − We want to propagate them to sensitivities to IVs and spot − We need the Jacobians and of h so we can apply the chain rule − h is implicitly defined by calibration to n instruments: − Where the error functions are explicit and we easily compute their Jacobians − We need the Jacobians and of the implicit function out of these and we’re home safe Propagation through implicit functions 37 aV ˆV 0 0 0 ˆ ˆ ˆ a a S S a S V V h V V V h 0 ˆ,a h S 0 ˆ SV ie 0ˆ, ,a Se e e ˆh 0Sh 2 0 , 0 , 0 ˆ ˆ: min , , , , ,i i i ii i i K T K T i a h e e e a S w C a S BS S ˆh 0Sh 5/9
- 38. www.danskemarkets.comAAD Danske Bank • Theorem: • Where is the ”pseudo-inverse” of the Jacobian of calibration errors to the results of h = interpolation parameters • Note that I is the projection operator propagation = risk projection • In a perfect calibration context, is square of full rank, and in this case propagation = Jacobian inversion • Finally, the general formula for propagation through calibrations: Implicit Function Theorem 38 1 ' 'a a aI e e e ae 0 0 ˆ ˆ S S h Ie h Ie ae 1 aI e 0 0 1 ˆ ˆ 1 ' ' ' ' a a a a a S a a a a S V V e e e e V V e e e e 6/9
- 39. www.danskemarkets.comAAD Danske Bank is the solution of At the optimum, we have and we have the 1st order condition Deriving the 1st order condition with respect to and : At the optimum, errors are negligible compared to derivatives, hence: So, in other terms Proof 39 2 0 ˆmin , , ,i i a e e e a S * 0 ˆ,a h S ' 0 'a m ae e e 0 00 ˆ ˆˆ ' 0 ' ' ' 0 ' ' a mn a a a m aS a SS e e e e e e ˆ 0S * 0 0 0 0 ˆ ˆ ˆ ˆ, , , , , ,i i i ie a S e h S S S 0 0 0 ˆ ˆ ˆ' 0 ' ' 0 ' a mn a a a S m a a S S e e e h e e e e h e 0 0 ˆ ˆ' ' ' ' a a a a a S a S e e h e e e e h e e 0 0 1 ˆ ˆ 1 ' ' ' ' a a a S a a a S h e e e e h e e e e 7/9
- 40. www.danskemarkets.comAAD Danske Bank Backward Risk Propagation: general algorithm • Successive vectors of parameters are derived or calibrated from one another − From initial market observed or trader input sets to which we want sensitivities − Through successive transformations from some previously computed sets − Eventually leading to the set of final model parameters • Use AAD to compute derivatives of the result to model parameters • Propagate risks in the reverse order to the construction of the parameters − For each , from output to inputs: − When is explicit, we use tape pasting − When is implicit, we use the Implicit Function Theorem for each input set where are the (explicit) errors functions implicit to the calibration that defines − When a is an input to multiple s, then the final is the sum of the propogations from all s • We can compute ”custom risks” with this algorithm − Use different parameter sets for tape pasting and IFT, than the ones used for calibration 40 iP 0 1... nP P i i j j i P f P 1NP 1NP V i j propagation i i j P Pj i P f P V V if jP if jP V if if 1 ' 'j i i i i jP P P P P PV V e e e e if ,i j i j i e P P if 1NP 8/9
- 41. www.danskemarkets.comAAD Danske Bank Big Picture: real life Forex Dupire Domestic rates OIS depo Libor futures Libor swaps Libor/OIS basis loc V Result V calib Domestic Discounts and Libors Foreign rates Fx swaps Basis swaps Libor futures Libor swaps calib Forex forward curve Spot IVs ATM 25D C/P (10D C/P) Liquid expiries calib Interpolated IV surface LV matrix AAD AAD AAD FFxV DFV TP IFT TP aV 0SV ˆV FRV DRV PDE, MC Dupire’s formula LibV IFT IFT IFT IFT IFT IFT 9/9 41
- 42. www.danskemarkets.comAAD Danske Bank Demo: CVA • As presented by Andreasen at Global Derivatives 2014, we calculate CVA by 42 CVA without collateral 1/3 • I.e. instead of simulating the netting set value directly • … we simulate cashflows and calculate CVA by accumulating future cashflows if 1. the counterparty has defaulted and 2. the netting set value is positive to us at default • where − is the default time of the counterparty − c(t) is the cashflow of the netting set at time t − is a LSM regression proxy of the value of the netting set at time t 42
- 43. www.danskemarkets.comAAD Danske Bank Demo: CVA • The two methods are economically equivalent, but with this approach we − Avoid nested MC simulations − Use LSM regression proxies as an approximation, … but only to check positivity! − Get a very efficient and accurate CVA implementation • Live CVA demo … 43 CVA without collateral 2/3 43
- 44. www.danskemarkets.comAAD Danske Bank Demo: CVA CVA Risk • Calculating CVA as just described, we have • If the proxy is good, around zero, the above is approximately zero − If the proxy is perfect, around zero, the above is exactly zero • If the proxy is bad, the above is numerical noise that we want to ignore • Hence, we want to keep the proxy frozen during risk calculations • This is done, by not “AD’ing” LSM − i.e. to use native doubles – and not kDoubleAds – in the LSM regression implementation • Live CVA risk demo … 44 Risk for CVA without collateral 3/3
- 45. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk • The minimum requirements for regulatory capital is given as a fixed proportion of the Risk-Weighted exposure Amount (RWA aka REA) • For Counterparty Credit Risk (CRR), RWA is calculated for a netting set, by − where N is the cumulative normal distribution function − PD is the default probability − LGD is Loss Given Default − is a regulatory-given correlation function of PD: − M is the effective maturity − EAD is the Exposure At Default − k is a regulatory-given maturity adjustment factor function of PD and M: 45 Regulatory-given formula for RWA CCR 1/6
- 46. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk • RWA CCR is (when using IMM) a function of the expected exposure profile − where V(t) is the (stochastic) value of the netting set at time t − and K(t) is the (stochastic) value of the collateral (in case of a CSA agreement) at time t • The expected exposure profile enters via EAD and M • Calculating the expected exposure is the challenge in the RWA CCR calculation! RWA CCR as a function of the expected exposure profile 2/6 46
- 47. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk • Our approach for RWA CCR can be considered a corollary to our CVA approach − We are using the same models as for CVA in the calculation of the EE: beast, MFC, SLV, … − We are using/extending a lot of the functionality (trade compression, trade decoration, netting set setup, realtime dynamic model building etc) − … and we are using LSM proxies to check for positivity • When a new trading opportunity occur, we can do a full RWA CCR calculation for the netting set − … at the trading desk – based on realtime models − For a typical netting set, the calculation takes 5-10 sec and full risk takes about a minute (1.5 – 2x longer with CSA) • The calculation is done in 2 steps − First the expected exposure profile is generated for the netting set − Then RWA is calculated with the expected exposure profile (and PD, LGD etc) as input − The RWA formula is scripted in the same way as we script trades and netting sets RWA CCR as 2-script setup 3/6 47
- 48. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk • For a netting set without CSA, the expected exposure is • Live RWA CCR demo … RWA CCR without collateral 4/6 LSM regression proxy 48
- 49. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk • RWA CCR can be written as − where a is a vector of parameters and EE is the expected exposure profile • Then • This can be calculated using AD with checkpointing in a single AD calculation with one checkpoint! • Live RWA CCR risk demo … RWA CCR risk as 2-script risk with macro-level checkpointing 5/6 Risk directly from the RWA formula script Risk from netting set script enters only via EE 49
- 50. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for Counterparty Credit Risk Calculate risk for RWA CCR Split in 2 scripts/slices: RWA CCR risk as 2-script risk with macro-level checkpointing 6/6 Slice 1 Calc EE from the EE script (use double – no AD) Generate tape for RWA script (use kDoubleAd) Slice 2 Slice 1 Slice 2 Generate tape for EE script (use kDoubleAd) Set initial conditions Run RWA script bwds to calculate adjoints Slice 2 Store derivatives and wipe tape Set initial conditions Run EE script bwds to calculate adjoints Pick derivatives from the ai nodes and wipe tape 1 2 3 4 5 6 7 50
- 51. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for CCR with collateral • For a 2-way CSA agreement with thresholds Hc and Hp and independent amounts Ic and Ip, collateral is modeled as • For simplicity we will ignore thresholds and independent amounts and let • The Margin Period of Risk, , is, in case of RWA, given by regulators − For a netting set with OTC derivatives having daily margin calls, it is typically 10b • The Margin Period of Risk makes it non-trivial to extend our approach to XVA and RWA with collateral … 51 RWA CCR with collateral 1/3
- 52. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for CCR with collateral • However, Andreasen (2014) showed that K can be taken into account in the expected exposure by − The expected exposure is still calculated by summing notional adjusted cashflows c(u) − And LSM proxies are still only used to check positivity − But 2 proxies are now in play − is calculated on the main simulationpath − is calculated on a separatepath branched out at • Live RWA CCR with collateral demo … 52 RWA CCR with collateral using branching 2/3
- 53. www.danskemarkets.comAAD Danske Bank Demo: Capital Requirement for CCR with collateral 53 RWA CCR with collateral using branching 3/3 • The extra paths from branching will increase the calculation time by a factor 1.5-2 − But still fast enough to be used realtime on the front • By e.g. approximating the effective maturity with time to maturity in the riskweight for RWA for CCR, we can similarly calculate KVA for CCR (and associated risk) in realtime • In addition, AD can also be used to calculate derivatives with respect to notionals … and allocate capital to individual desks, books, trades etc (“Euler decomposition”)