This repository contains some of the code I developed as part of my master's thesis which studied the use of Adjoint Automatic differentiation (AAD) for calculating the Greeks on options priced using Monte Carlo under the Black Scholes model. It explores the benefits of vectorised computations for this task and shows the speedup that can be gained.
My implementation of AAD uses a Tape structure to hold Nodes representing mathematical operations carried out in the program. This is a simple way of representing a computation graph DAG and is all abstracted behind the Number interface. Calculating adjoints is as easy as performing the backpropagation algorithm to accumulate them using the chain rule.
I thought the Mojo programming language might be well suited to this task as it provides easy access to SIMD primitives which compile to CPU-native instructions.
As an extension to these initial results, I implemented a simply SVI volatility model and calculated the sensitivities of its parameters using AAD.
I priced a vanilla European call using the Black Scholes model and 200,000 Monte Carlo paths across weekly time steps for the sake of complexity. The test was ran on a Ryzen 9 5900x which supports AVX2, so theoretically has space for eight 32-bit floats in its registers. The actual speed up achieved is 6.7x.
Optimisations such as pathwise adjoints [2] are implemented to reduced memory consumption and improve performance. Similar overall performance improvemetns can be seen when pricing the European option and calculating the first-order Greeks (Delta, Rho, Theta, Vega). A maximum 8.1x speed up is achieved here. This is the theoretical maximum that can be achieved on this processor and is due to the fact that the computational overhead of AAD slows the program down enough to escape potential I/O bottlenecks.
This simulation with adjoint calculations exhibits a 3-4x slow down which matches the upper bound given in [4].
The first local volatility model is a simple one - SVI. In apple.ipynb the current Apple stock call options data from yfinance are used to fit the SVI parameters
Param | Analytical Value | MC+AAD Value |
---|---|---|
Price | 29.5669 | 29.5048 |
0.6487 | 0.6489 | |
-19.1122 | -19.0517 | |
86.1373 | 86.2198 |
SVI param | Sensitivity |
---|---|
a | 169.44705 |
b | 1087.1393 |
-0.3214 | |
m | 0.2495 |
0.0039 |
Dupire local vol WIP
- [1] Gatheral, J. and Jacquier, A. (2013) ‘Arbitrage-free SVI volatility surfaces’, Quantitative Finance, 14(1), pp. 59–71.
- [2] Giles, M.B., & Glasserman, P. (2005). Smoking Adjoints: fast evaluation of Greeks in Monte Carlo calculations.
- [3] Savine, Antoine. (2019). Modern Computational Finance : AAD and Parallel Simulations. 1st edition. Hoboken, New Jersey: Wiley.
- [4] Griewank, A., & Walther, A. (2000). Evaluating derivatives - principles and techniques of algorithmic differentiation, Second Edition. Frontiers in applied mathematics.