Professional Documents
Culture Documents
Lecture 2019.1 Project - Equity Hedge Simulation V0.1
Lecture 2019.1 Project - Equity Hedge Simulation V0.1
Christian P. Fries
email@christian-fries.de
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
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
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
• writing clean, concise, elegant and easy to understand code, avoid code duplica-
tion (DRY)
• 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.
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.
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.
Remark
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
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
under the corresponding martingale measure QN . The Heston model has the parameters
• ξ: volatility of volatility,
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
2019
c Christian Fries 5 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019
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 .
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 .
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
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
θ 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.
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
• 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.
• 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
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
and
1 1 − exp(−λθ)
φ(θ) = 1− ,
λθ λθ
with given constant parameters σ L , λ, ρ (note: the parameter ρ appears in the
implied volatility function).
• 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 ).
– 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
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
and
• if the model is a SSVI model with reasonable parameters (Note: Its part of the
exercise to find out what "reasonable parameters" are).
K = {30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140}.
EuropeanOption
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.
2019
c Christian Fries 12 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019
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
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):
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.
LevenbergMarquardt
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
where
Vi (θ) = product[i].getValue(newModel), i = 1, . . . , M
with
newModel = model.getCloneWithModifiedData(newData)
Create a plot of the market prices and the model values obtained by using the calibrated
parameters.
Notes:
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.
• 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
Underlying Value
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:
• 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:
Remarks:
2019
c Christian Fries 16 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019
2019
c Christian Fries 17 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/
Numerical Methods in Mathematical Finance Project 2019
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
2019
c Christian Fries 19 Version 0.1 (5.0.6) (20190612)
http://www.christianfries.com/finmath/