Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

quant Lab

Numerical Methods in Mathematical Finance.


Project:
Monte-Carlo Simulation of
Local and Stochastic Volatility Models:
Implementation, Forward Smile, Calibration, Hedge
Performance

Christian P. Fries
email@christian-fries.de

June 12, 2019

Version 0.1 (5.0.6)

Abstract

The following are the exercises of the project home-work of the lecture Numerical
Methods in Mathematical Finance, which is part of the final exam.
The project is conducted in the LMU quantLab, but may be prepared at home.
Support is provided by

Christian Fries, email@christian-fries.de

Lorenzo Torricelli, torricel@math.lmu.de

Panagiotis Christodoulou, panagiotis.christodoulou@math.lmu.de

Resources and further details can be found at


http://www.christian-fries.de/finmath/lecture18.1/project/

1
Numerical Methods in Mathematical Finance Project 2019

Contents

1 Introduction 3
1.1 Aim of the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Evaluation of the Project Results . . . . . . . . . . . . . . . . . . . . 3
1.3 Submission of the Solution . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Working with the Git Repository . . . . . . . . . . . . . . . . . . . . 4

2 Theoretical Background 5
2.1 Heston Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Local Volatility Models and Dupire Formula . . . . . . . . . . . . . . 5
2.2.1 Local Volatility and Implied Volatility . . . . . . . . . . . . . 6
2.2.2 Dupire’s Formula . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Local Volatility Models . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 CEV Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 (S)SVI Model . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Difference of Local Volatility . . . . . . . . . . . . . . . . . . . . . 7

3 Software Tools and Libraries 8


3.1 finmath lib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Apache commons-math . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Visualization of Results . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.4 Task: Generic Local Volatility Model Framework . . . . . . . . . . . 9

4 Implied Volatility Smile 12


4.1 Task: Check the implied volatility smile . . . . . . . . . . . . . . . . 12

5 Calibration of the Model 13


5.1 Task: Calibration of the model using brute force Monte-Carlo(Optional) 13

6 Delta Hedging Heston and Local Volatility 15


6.1 Task: Delta Hedge Portfolio under a Heston Model . . . . . . . . . . 15
6.2 Task: Delta Hedge Portfolio under a Local Volatility Model . . . . . . 17

References 19

2019
c Christian Fries 2 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

1 Introduction

The project consists of the implementation of a Monte-Carlo simulation of an Euler-


scheme discretization of a risk neutral single-asset model. We investigate the relation
of different modelling approaches (e.g. local volatility and stochastic volatility model).
The models are analysed by performing hedge simulations under different model
assumptions. The calibration of the models is investigated too.

1.1 Aim of the Project

The aim of the project is to perform a collaborative development of a simulation,


valuation and calibration algorithm, including testing.
Your project solution should consider

• writing clean, concise, elegant and easy to understand code, avoid code duplica-
tion (DRY)

• write unit test (e.g. using JUnit)

• document the code (e.g. using JavaDoc).

It is not the primary aim to get an accurate solution.


Designing the code you may consider:

• Your solution should try to follow the open-closed-principle: open for extentions,
closed for modification. Example: consider extending the model from one asset
to many assets.

• The type hirarchie of your models, products and test should follow the Liskov
substitution principle: Examples: products can be valued with different models;
tests can be run with different models and products.

1.2 Evaluation of the Project Results

To successfully pass the review of the project we may ask for a short presentation of a
part of the solution and ask you for answering a set of project related questions.
Note: The implementation part of the project can be solved very elegantly using object
oriented implementation techniques requiring only few lines of new code. We encourage
you to discuss your ideas during the solution in order to improve you solution.

1.3 Submission of the Solution

Each working group will receive its own password protected Git repository.

2019
c Christian Fries 3 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

The solution has to be submitted to the repository by end of July 17th, 2019.
(Note: This is a tentative deadline. It might that we extend it.)

We will ask each group to present some parts of their solution and perform a short
evaluation. The presentation/evaluation will be on July 17h, 2019.

1.4 Working with the Git Repository

For an introduction to Git we recommend https://try.github.io/

Remark

DON’T PANIC. WE WILL TRY TO ASSIST YOU!

THIS IS A FIRST DRAFT. CHECK FOR UPDATES!

2019
c Christian Fries 4 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

2 Theoretical Background

2.1 Heston Model

The Heston model is an extension of the Black-Scholes model where the volatility
parameter is stochastic. In the Heston model the stock S follows the SDE
p
dS(t) = rS(t)dt + V (t)S(t)dW1 S(0) = S0
p
dV (t) = κ(θ − V (t))dt + ξ V (t)dW2 V (0) = σ 2
dW1 dW2 = ρdt,

with

dN (t) = rN (t)dt N (0) = N0

under the corresponding martingale measure QN . The Heston model has the parameters

• S0 : initial value of the stock,

• r: interest rate (constant),

• σ: initial value of the volatility,

• ξ: volatility of volatility,

• κ: mean reversion speed of the volatility,

• θ: mean reversion level of the volatility,

• ρ: correlation of volatility (squared) and stock.

Obviously, for ξ = κ = 0 the model is identical to the Black-Scholes model with


constant volatility σ and for ξ = 0 the model is identical to the Black-Scholes model
with time-dependent (but non-stochastic) volatility.
There is an implementation of the Heston model in the class HestonModel in the
package net.finmath.montecarlo.assetderivativevaluation

2.2 Local Volatility Models and Dupire Formula

A local volatility model is a model where the volatility is a function of time t and the
current value of the underlying S(t). Since S(t) is a random variable, the volatility can
be random (stochastic), but in contrast to a Heston model, the volatility does not have
an independent Brownian driver dW2 .
The local volatility model is

dS(t) = rS(t)dt + σloc (t, S(t))dW (t), S(0) = S0 .

2019
c Christian Fries 5 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

2.2.1 Local Volatility and Implied Volatility

It is important to distinguish local volatility and implied volatility: The local volatility
σloc is a model parameter - it may be a function.
The implied volatility comes as "implied Black-Scholes volatility" or "implied Bachelier
volatility" and is an alternative description of the value of a call option C(T, K), where
T is the maturity and K is the strike. The implied volatility is a function of (T, K).
For a given call option value C(T, K), the implied Black-Scholes volatility σ L (T, K)
is the value which has to be used as constant volatility in the Black-Scholes model (for-
mula) to optain the value C(T, K) (invert the Black-Scholes formula). The superscript
L is for lognormal.
For a given call option valkue C(T, K), the implied Bachelier volatility σ N (T, K)) is
the value which has to be used as constant volatility in the Bachelier model (formula)
to optain the value C(T, K) (invert the Bachelier formula). The superscript N is for
normal.
You can find conversion from volatility to value and back in the class

net.finmath.functions.AnalyticFormulas .

2.2.2 Dupire’s Formula

If C(T, K) denotes the time 0 value of a call option with maturity T and strike K, then
the local volatility can be derived from function (T, K) 7→ C(T, K).
Assuming a lognormal model
L
dS(t) = rS(t)dt + σloc (t, S(t))S(t)dW (t) S(0) = S0 .

one finds that the choice


!1/2
∂C ∂C
L 1 ∂T + rK ∂K
σloc (t, S(t)) := 2 ∂2C

K
∂K 2
T =t,K=S(t)

will reproduce all option prices C(T, K) (if that local volatility model is used to
calculate the time 0 value of a call option with given strike and maturity).
If we use the normal notation

dS(t) = rS(t)dt + σloc (t, S(t))dW (t) S(0) = S0 .

we find from
L
σloc (t, S(t)) = σloc (t, S(t))S(t)
that !1/2
∂C ∂C
L ∂T + rK ∂K
σloc (T, K) = σloc (T, K)K = 2 ∂2C
.
∂K 2

2019
c Christian Fries 6 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

2.3 Local Volatility Models

2.3.1 CEV Model

The CEV model assumes the local volatility to be

σloc (t, S) = S β , for 0 ≤ β ≤ 1.

2.3.2 (S)SVI Model

Other approaches assume a parametric form of the implied volatility. An example is


the SVI model (SVI stands for stochastic volatility inspired), which gives the implied
Black-Scholes volatility as parametric form. To obtain the local volatility from such
a parametrization one has to apply Dupire formula (e.g., numerically) to the Black-
Scholes formula applied to the parametric form.
The SVI model is local volatility model where the local volatility asymptotically
matches a local volatility derived from the Heston model.
We consider a variant, the SSVI model (surface SVI), which parametrizes the Black-
Scholes implied volatility (not the local volatility) as
p
σ L (T, K) = w(ln(K/F (T )), θ(T ))/T

with F (T ) = S(0) exp(rT ) and w as

θ p 
w(k, θ) = 1 + ρφ(θ)k + (φ(θ)k + ρ)2 + (1 − ρ2 )
2
where t 7→ θ(t) and θ 7→ φ(θ) are given functions.
It can be shown that θ describes the implied Black-Scholes volatility for ATM-options,
that is, for K = F (T ), of options values under this model. It is
2
θ(T ) = σ L (F (T ), T ) · T.

The function φ describes the skew, that is the derivative of the implied Black-Scholes
volatility with respect to K.

2.4 Difference of Local Volatility

Note that, if you calculate a local volatility function from option values C(T, K) which
are generated from a (Heston) stochastic volatility model, then the local volatility model
and the stochastic volatility model produce the same European option values, but they
are still different (in other aspects).

2019
c Christian Fries 7 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

3 Software Tools and Libraries

3.1 finmath lib

• You should implement your solution using the interfaces provided in finmath lib.
This is just to make your solutions interoperable. Please checkout the version at
https://github.com/finmath/finmath-lib

• You may use anything else from finmath lib and if your solution is very short due
to heavy re-use of existing code, then this is good.

• You may also re-write classes, if you see a good reason.

3.2 Apache commons-math

• The Apache commons-math library contains a SobolSequenceGenerator. Since


commons-math is a dependency in fimath-lib, including finmath-lib will make
commons-math available to you.

3.3 Visualization of Results

• We provide a small project which allows easily create plot in Java at https://
github.com/finmath/finmath-lib-plot-extensions. The project
provides wrapper code for JFreeChart, JFreeSVG JZY3D and iText).

2019
c Christian Fries 8 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

3.4 Task: Generic Local Volatility Model Framework

Exercise 1 (Local Volatility Models):


Implement a generic framework for the Monte-Carlo simulation of an Euler-scheme
discretization of a local volatility model.
The specification of the local volatility model should be easily interchangeable.
Implement the following local volatility functions:

L (t, S(t)) ≡
• Black-Scholes: σloc (t, S(t)) = σBS S(t) with a constant σBS , i.e., σloc
σBS .

• Full Truncation CEV model: σloc (t, S(t)) = σ0 max(S β (t), 0) for 0 ≤ β ≤ 1.

Perform valuations for call options using your model. For each value calculate the
implied volatility. Plot the implied volatility and investigate the role of the parameter β.
Hints:

• Note: your local volatility function should be a general function of (t, S) (or of
ti , S(ti )) since this is needed in a later exercise.

• Code for converting an option value into an implied volatility can be found in
AnalyticFormulas.java.

• You may re-use many classes from finmath lib and focus on the implementation of
the local volatility function. For example, use EulerSchemeFromProcessModel,
BrownianMotionLazyInit and you implementation may be a small gener-
alization of BlackScholesModelWithCurves or BachelierModel.

2019
c Christian Fries 9 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

Exercise 2 (SSVI Local Volatility Model):


Implement a local volatility model for the SSVI model using parametrizations for θ and
φ:

• Consider the SSVI model for the special case


2
θ(T ) = σ L · T,

and  
1 1 − exp(−λθ)
φ(θ) = 1− ,
λθ λθ
with given constant parameters σ L , λ, ρ (note: the parameter ρ appears in the
implied volatility function).

• (Optional) Generalize the SSVI model above to the case


Z T
θ(T ) = σ(T )2 dT
0

with a piecewise constant function σ(T ).

Note: Details of the model can be found in https://mfe.baruch.cuny.edu/


wp-content/uploads/2013/04/BloombergSVI2013.pdf and references
therein.
Hints:

• To obtain a local volatility function for the SSVI model you need to implement
several transformation steps:
BS formula Dupire
SSVI implied volatility 7−→ option value C(T, K) 7−→ local volatility

• Some steps may be done analytically, which may be a bit faster compare to a
numerical approximation.

2019
c Christian Fries 10 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

Exercise 3 (Local Volatility Model consistent with the Heston Model usinng Dupire
Formula):
THIS EXERCISE IS MORE DEMANDING. IT IS OPTIONAL
For your framework of local volatiltiy models, implement a local volatility function,
which is derived from the Heston model using Dupire formula.
Implement the following local volatility functions:

• A local volatility model that recovers the Heston model’s implied volatility smile
(see Exercise 4) using the Dupire’s formula.

Hints:

• The Heston local volatility function may be obtained numerically. Details will
follow.

• For this exercise you only need the Heston local volatility function. This function
can be obtained by Dupire formula. It requires the calculation of the Heston theta
(dC/dT ), the Heston delta (dC/dS) and the Heston gamma (d2 C/dS 2 ).

• Calculating the derivative by finite difference, where each valuation is performed


numerically by a Monte-Carlo simulation may be possible as an initial test,
but will likely be require too much computation time for a big Monte-Carlo
simulation.

– Hint: As a first start you could implement the local volatility function where
Theta, Delta, Gamma are calculated via finite difference to a secondary
Monte-Carlo simulation using only few path (≈ 1000). This might be fast
enough to allow for a first test. Then, if everything works, you may consider
replacing the local volatility calculation with a faster method. First make it
work, then make it fast.

2019
c Christian Fries 11 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

4 Implied Volatility Smile

4.1 Task: Check the implied volatility smile

Exercise 4 (Implied Volatility in the Different Models): Write a small test for the
Heston model and the local volatility models with the following model parameters

S0 = 100, r = 5%, σ = 30%

and

• if the model is a CEV model: β = 0.5,

• if the model is a Heston model: κ = 0.2, θ = σ, ξ = 20%, ρ = 0.

• if the model is a SSVI model with reasonable parameters (Note: Its part of the
exercise to find out what "reasonable parameters" are).

Perform a Monte-Carlo valuation of a set of European call options with maturity T = 2


corresponding to the following set of strike prices

K = {30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140}.

You may use the implementation of the product in the class

EuropeanOption

from the package

net.finmath.montecarlo.assetderivativevaluation.products

For each model you have implemented, retrieve the implied Black-Scholes volatilities
from your prices and plot your results. What do you observe?
Hint: You may use the function

double blackScholesOptionImpliedVolatility(double
forward, double optionMaturity, double optionStrike,
double payoffUnit, double optionValue)

from

net.finmath.functions.AnalyticFormulas.

Here forward = S0 exp(rT ) and payoffUnit = exp(−rT ).

2019
c Christian Fries 12 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

5 Calibration of the Model

5.1 Task: Calibration of the model using brute force Monte-Carlo(Optional)

Exercise 5 (Calibration):
Implement a Monte-Carlo calibration to the market prices given in the table below
for the model parameters σ, β (only for the CEV model) or κ, θ, ξ, ρ (for the Heston
model), or the parameters of the parametric SSVI model. The parameters S0 = 100
and r = 5% are fixed.
The market “prices” used to calibrate the model are

maturity strike implied BS volatility


1.0 60 56.51 %
1.0 80 52.47 %
1.0 100 50.90 %
1.0 105 50.75 %
1.0 110 50.85 %
1.0 120 51.17 %
1.0 140 52.55 %
1.0 160 54.40 %
1.0 180 56.05 %

Note: The prices are expressed as Black-Scholes volatility with parameters S0 = 100
and r = 5%.
Proceed as follows (however, you may create your own solution):

• Create a class CalibratedModel which provides a method

AssetModelMonteCarloSimulationInterface
getModel(
AssetModelMonteCarloSimulationInterface model,
AbstractAssetMonteCarloProduct[] product,
double[] targetValues)

Implement this method such that it returns a model for which the parameter
vector θ := (σ, ξ, κ, θ, ρ) is calibrated, i.e. such that the valuation of the M
given products with a model with these parameters matches the respective target
values.

• You may use the implementation of the

LevenbergMarquardt

optimizer from the package

net.finmath.optimizer

2019
c Christian Fries 13 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

in order to solve the multidimensional optimization problem with the objective


functions

θ 7→ (Vi (θ) − targetValues[i])2i=1,...,M

where

Vi (θ) = product[i].getValue(newModel), i = 1, . . . , M

with

newModel = model.getCloneWithModifiedData(newData)

and newData is HashMap with

newData.put("sigma", new Double(sigma)).

Create a plot of the market prices and the model values obtained by using the calibrated
parameters.
Notes:

• Using the class LevenbergMarquardt for the optimization, you have to


override the method

setValues(double[] parameters, double[] values)

of the class in order to define the objective function. In our case, this will be the
evaluation of (Vi (θ) − targetValues[i])2 , i = 1, . . . , M - which involves
the Monte-Carlo valuation of the products Vi , i = 1, . . . , M using a clone of the
model with the new parameter vector θ.
Hint: It is important that you choose the starting values of the solver appropriately.
We will provide further hints on this topic during the project.

• Note that the implementation of the Levenberg-Marquardt optimizer allows for


multi-threaded valuation. In this case, the implementation of setValues must
be thread-safe and the JVM needs enough memory.

• You can reuse the calibration code if each model provides its own objective
functions (because the model knows its parameters best). The model should
provide the initial value and reasonable step sizes to be used with the optimizer.

2019
c Christian Fries 14 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

6 Delta Hedging Heston and Local Volatility

6.1 Task: Delta Hedge Portfolio under a Heston Model

Exercise 6 (Delta Hedge Portfolio under a Heston Model):


Implement a delta-hedge portfolio assuming a Heston model for the calculation of the
delta.
Analyse the hedge error for different combinations of hedge assumption on the simula-
tion model:

• Perform the Monte-Carlo simulation of the underlying S with a Black-Scholes


model.

• Perform the Monte-Carlo simulation of the underlying S with a Heston model.


Try to vary the parameters. Also: you may try to use different parameters for the
simulation and for the calculation of the delta hedge (e.g.: what happens if the
trader hedges with a different “volatility of volatiltiy”.

• Create a plot of the hedge error, similar to the following

Replication Portfolio Values

Underlying Value

replication derivative payoff

and plot a histogram of the hedge error.

2019
c Christian Fries 15 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

Hints:

• Hedging will be covered a Lecture at the end of the term.

• You may adapt the implementation of the delta hedge for the Black-Scholes
model.

• You may re-use existing code performing the Monte-Carlo simulations of the
Black-Scholes Model and/or the Heston Model.

• You will need a function providing the Heston model’s delta. There are options
on how to obtain this:

– Use a Monte-Carlo valuation of a Heston model, then use finite differences


on the result (this works, but is very slow or inaccurate).
– Use the Fourier transform valuation, then use finite differences on the result
(this is a bit more accurate and/or faster). The valuation using Fourier
transforms was not covered in the lecture, but the code may be used as a
black box, see HestonModelTest in package
net.finmath.montecarlo.assetderivativevaluation
in src/test/java.
– Even more advanced, you may use the path-wise method for Monte-Carlo
simulation to directly calculate the delta from a single Monte-Carlo run...
– ...or you may try to differentiate the characteritic function in the fourier
transorm?

(any solution will be OK).

Remarks:

• The exercise can be solved by two modifications of existing code: in your


main-program the model used for the simulation of S has to be replaced by a
Monte-Carlo Heston model (this model exists). In the product calculating the
Hedge portfolio, the Black-Scholes delta has to be replaces by the Heston delta.
This last step is the main issue here. (We will prove more hints if required).

2019
c Christian Fries 16 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

6.2 Task: Delta Hedge Portfolio under a Local Volatility Model

Exercise 7 (Delta Hedge Portfolio under a Local Volatility Model):


Same as Exercise 6 with the local volatility model for the simulation of the underlying
S.
Compare the results to that obtained in Exercise 6.

2019
c Christian Fries 17 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

The following exercises are optional.

2019
c Christian Fries 18 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019

References

[1] F RIES , C HRISTIAN P.: finmath lib - source code repository.


http://finmath.net/java.
F RIES , C HRISTIAN P.: finmath lib - api documentation.
http://finmath.net/java/finmath-lib/apidocs.

19 pages. 0 figures. 0 tables.

2019
c Christian Fries 19 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/

You might also like