Content uploaded by Thierry Moudiki
Author content
All content in this area was uploaded by Thierry Moudiki on Jan 13, 2020
Content may be subject to copyright.
, a tool for stochastic simulation
( )
Thierry Moudiki
13th January 2020
Contents
1 Overview 2
1.1 Context ................................. 2
1.2 ................................. 3
1.3 ............................... 5
2 Examples 6
2.1 Installation ............................... 6
2.2 Generating dependent shocks ewith ......... 6
2.3 Example with and : Option pricing under
the Bates model (SVJD) for equity ................. 10
1
, tools for stochastic simulation •January 2020
1 Overview
1.1 Context
Initially, I developped this package for insurance. In 2014. If you’re not
working in insurance, is still relevant for stochastic simulation
in Finance, Economics, or Physics (...). In that case, you can start directly by
reading 1.2. Oh, in this section, read at least this paragraph: 1.1.
An Economic Scenario Generator (ESG) is a tool for projection of plausible
future paths of insurers’ financial assets. It helps in pricing its products, and
assessing its current and future solvency. Two types of ESGs are generally
needed: a real-world ESG, and a a market consistent ESG.
The aim of a real-world ESG is to produce projections of risk factors, whose
patterns are coherent with the past distribution of those risk factors. Real-
world scenarios are mainly used for the valuation of solvency requirements.
A market consistent ESG shall produce projections of risk factors that are
coherent with market prices observed at the valuation date. Market consistent
scenarios are mainly used for the best estimate valuation of technical reserves.
Hence, in real-world simulations the historical probability is used and in
market consistent simulations, the projection of risk factors is made in a risk-
neutral probability. A risk-neutral probability measure is a measure under
which the discounted prices of assets are martingales.
A simple example of transitioning from a simulation under the histori-
cal probability to a simulation under a risk-neutral probability can be made
by using the Black-Scholes model, a geometric Brownian motion. In a real-
world simulation, we can assume that an asset evolves according to the fol-
lowing Stochastic Differential Equation (SDE) (with a drift µ, a volatility σ,
and (W(t))t≥0being a standard brownian motion):
dS(t) = µS(t)dt +σS(t)dW(t)(1)
Let rbe a constant risk-free rate. e−rt S(t), the discounted price of S(t), will
be a martingale if
d(e−rt S(t)) (2)
is driftless. Applying Ito’s formula to e−rt S(t), we have :
d(e−rt S(t)) = −re−rt S(t)dt +e−rtdS(t)−1
2.0 <dS(t),dS(t)>(3)
=−re−rt S(t)dt +e−rt µS(t)dt +e−rtS(t)σdW(t)(4)
=e−rt S(t)[(µ−r)dt +σdW(t)](5)
Thus, the drift vanishes iff µ=r. That is, if our asset with price S(t)at
time trewards the risk-free rate r. Under this martingale probability measure,
asset price dynamics over time can be re-written as:
dS(t) = rS(t)dt +σS(t)dW ∗(t)(6)
2
, tools for stochastic simulation •January 2020
Where (W∗(t))t≥0is a standard brownian motion under the chosen risk-
neutral measure.
As we’ll see in section 1.2, does not directly provide multiple
asset models but instead, some building blocks for constructing a variety of
these. Two main functions are therefore provided for his purpose: ,
. Other tools for statistical testing and visualization are presented as
well.
As a reminder: There are no perfect models, and the more sophisticated
doesn’t necessarily mean the most judicious. To avoid possible disasters, it’s
important to know precisely the strengths and weaknesses of a model before
using it.
1.2
Let (W(t))t≥0be a standard brownian motion. makes simulations
of a diffusion process (X(t))t≥0, which evolves through time according to the
following equation:
dX(t) = µ(t,X(t))dt +σ(t,X(t))dW (t)+γ(t,X(t−),J)dN(t)(7)
Actually, (Eq. 7) is a generic formulation of all models. Not
all parts of this expression are required all the times, but σ(t,X(t))dW (t),
describing our process’ volatility. Let’s describe the other parts.
γ(t,X(t−),J)dN(t)is optional. It contains jumps of the process, that occur
according to a homogeneous Poisson process (N(t))t≥0with intensity λ. The
time elasped between two jumping times follows an exponential e(λ)distri-
bution; and the number of jumps of the process on [0, t[follows a Poisson
distribution P(λt). The magnitude of the jumps is controlled by J.
Now, for the blue part of (Eq. 7), we could have:
• An Orsnstein-Uhlenbeck process; for used with parameter
, and parameters , and provided (if
or are not necessary for building the model, they are to
be provided and set to ):
µ(t,X(t)) = (θ1−θ2X(t))
σ(t,X(t)) =θ3
• A Cox-Ingersoll-Ross process; for used with parameter
, and parameters , , provided (if
or are not necessary for building the model, they are to
be provided and set to ) :
µ(t,X(t)) = (θ1−θ2X(t))
σ(t,X(t)) =θ3qX(t)
3
, tools for stochastic simulation •January 2020
• A Geometric Brownian motion, or augmented versions; for used
with parameter , and parameters , ,
provided. For the sake of clarity, the argument is set to , but
not only the Geometric Brownian motion with constant parameters is
available. We could have :
A Geometric Brownian Motion
µ(t,X(t)) =θ1X(t)
σ(t,X(t)) =θ2X(t)
A modified Geometric Brownian Motion, with time-varying drift and
constant volatility
µ(t,X(t)) =θ1(t)X(t)
σ(t,X(t)) =θ2X(t)
A modified Geometric Brownian Motion, with time-varying volatility
and constant drift
µ(t,X(t)) =θ1X(t)
σ(t,X(t)) =θ2(t)X(t)
It’s technically possible to have both θ1and θ2varying with time (both
provided as multivariate time series). But it’s not advisable to do this, unless
you know exactly why you’re doing it.
Jumps are available only for . The jumps arising from the
Poisson process have a common magnitude J=1+Z, whose distribution ν
is either lognormal or double-exponential. Between two jumps, the process
behaves like a Geometric Brownian motion, and at jumping times, it increases
by Z%. For lognormal jumps (Merton model), the distribution νof Jis:
log(J) = log(1+Z)∼ N (log(1+µZ)−σ2
Z
2,σ2
Z)(8)
For double exponential jumps (Kou’s model), the distribution νof Jis:
log(J) = log(1+Z)∼ν(dy) = p1
ηu
e−1
ηu11y>0+ (1−p)1
ηd
e
1
ηd11y<0(9)
Hence for taking jumps into account when , optional pa-
rameters are to be provided to , namely:
4
, tools for stochastic simulation •January 2020
• : intensity of the Poisson process
• : average jump magnitude (only for lognormal jumps)
• : standard deviation of the jump magnitude (only for lognormal
jumps)
• : probability of positive jumps (only for double exponential jumps)
• : the mean of positive jumps (only for double exponential jumps)
• : the mean of negative jumps (only for double exponential
jumps)
’s core loops are written in C++ via Rcpp because: speed. Cur-
rently, for an Ornstein-Uhlenbeck process with , a Cox-Ingersoll-
Ross process with , or a geometric brownian motion with ,
an exact simulation is used, which means there’s no discretization of (X(t))t≥0
on a time grid. You can also choose an of projection and a sampling
(annual, semi-annual, quarterly . . .). ’s output is a time
series object created by base function . And since this output is a
object, it means you can use functions such as or on
it.
For a customized simulation of e∼ N (0, 1)embedded in (Eq. 7)via
dW(t) = edt, you can fill ’s parameter with an output of function
. is described in the next section, 1.3, and an example of
such a procedure is described in 2.
1.3
is the complementary function to , with which you can
simulate e∼ N (0, 1)(that we call shocks), embedded into diffusion (Eq. 7)
as:
dW(t) = edt (10)
As , is written in C++ via . And when it comes
to the simulation of multi-factors models, or the simulation of risk factors
with flexible dependence structure, calls the underlying function
, from package CDVine. makes simulations of canonical
(C-vine) and D-vine copulas.
Simply put, a copula is a function which gives a multidimensional distri-
bution to given margins. If (X1, . . . , Xd)Tis a random vector with margins of
cumulative distribution functions F1, . . . , Fd, there exists a copula function C,
such that the d-dimensional cumulative distribution function of (X1, . . . , Xd)T
is :
F(x1, . . . , xd) = C(F1(x1), . . . , Fd(xd)) (11)
5
, tools for stochastic simulation •January 2020
If the marginal distributions F1, . . . , Fdare continuous, then Cis unique.
On the other hand, if Cis a copula, and F1, . . . , Fdare 1-dimensional cumu-
lative distribution functions, the previous equation defines a joint cumulative
distribution function for (X1, . . . , Xd)T, with margins F1, . . . , Fd.
Contrary to the multivariate Gaussian or Student-t copulas, vine copulas
accurately model the dependence in high dimensions. They use the density
functions of bivariate copulas (called pair-copula) to iteratively build a mul-
tivariate density function, which leads to a great flexibility in modeling the
dependence.
applies inverse standard gaussian cumulative distribution func-
tion to the uniform margins of to obtains gaussian shocks, with
various dependence structures between them.
can be used first, to choose the copula, and make an inference
on it. Sometimes, the choice of the relevant copula is also made with expert
knowledge.
2 Examples
Section 2.1 is about ’s installation. Section 2.2 is related to 1.3.
That is, to generating correlated e’s from dW(t) = edt in (Eq. 7). Then, section
2.3 presents a complete example of simulation of a Stochastic Volatility Jump
Diffusion (SVJD) model. This SVJD model uses 1.3.
2.1 Installation
• From Github:
• From CRAN:
TBD
2.2 Generating dependent shocks ewith
To use , you need the specify the number of simulations of ethat
you need, , the type of dependence, , and additional parameters de-
pending on the copula that you want to use. For a simulation of a Gaussian
copula, is :
6
, tools for stochastic simulation •January 2020
A correlation coefficient is provided to through its argument
:
You can make a correlation test on outputs with ,
to assess whether correlation estimate between shocks is significantly close
to the correlation you specified or not. If ’s confidence interval
contains the true value at a given confidence level, the null hypothesis is not
to be rejected at this level.
7
, tools for stochastic simulation •January 2020
These confidence intervals on the estimated correlations can also be visu-
alized with :
1.0 2.0 3.0 4.0
0.00 0.05 0.10 0.15 0.20
conf. int for the correlations
time
conf. int.
1.0 2.0 3.0 4.0
−0.915 −0.905 −0.895 −0.885
conf. int for the correlations
time
conf. int.
Now with other types of dependences, namely rotated versions of the
Clayton copula :
8
, tools for stochastic simulation •January 2020
2.3 Example with and : Option pricing un-
der the Bates model (SVJD) for equity
SVJD stands for Stochastic Volatility with Jump Diffusion. In this model, the
volatility of our asset’s price evolves as a CIR process. The price itself is a
Geometric Brownian motion between jumps, arising from a Poisson process.
Here, we consider jumps with lognormal magnitude.
The model
dS(t)=(r−λµZ)S(t)dt +qv(t)S(t)dW(t)(1)+ (J−1)dN (t)
dv(t) = κ(θ−v(t))dt +σqv(t)dW (t)(2)
dW(t)(1)dW(t)(2)=ρdt
We use the package to compute options’ prices from market
implied volatility :
The parameters of Bates model are :
Now we make simulations of shocks and diffusions, on a weekly ba-
sis, from today, up to year 1. The shocks are simulated by using a variance
reduction technique : antithetic variates (argument ).
10
, tools for stochastic simulation •January 2020
0.120
0.125
0.130
0.135
0.140
0.00 0.25 0.50 0.75 1.00
Maturity
Values
To finish, the simulation of asset price Stakes exactly the same parameters
as and , and diffusion’s volatility
is embedded through .
11
, tools for stochastic simulation •January 2020
In the figure below, we can clearly see asset prices jumping with .
, which depicts asset paths by percentiles, will be more useful
for thousands of simulations :
0.0 0.2 0.4 0.6 0.8 1.0
2000 4000 6000
with matplot
time(sim_price)
sim_price
0.0 0.2 0.4 0.6 0.8 1.0
2000 4000 6000
with esgplotbands
time
values
Now, we would like to study the convergence of estimated discounted
12
, tools for stochastic simulation •January 2020
prices to the initial asset price :
1
N
N
∑
i=1
e−rT S(i)
T−→ E[e−rTST] = S0(12)
where Nis the number of simulations, ris the constant risk free rate, and
Tis a maturity of 2 weeks.
One would also want to see how fast is the convergence towards S0 :
0 50 100 150 200 250 300
4000 4500 5000 5500
Convergence towards the initial
asset price
number of simulations
monte carlo estim. price
and give information about the mean, but a statisti-
cal test gives more information.
13
, tools for stochastic simulation •January 2020
computes for each T, a Student’s t-test of
H0:E[e−rT ST−S0] = 0
versus the alternative hypothesis that the mean is not 0, at a given confidence
level (default is 95%).
also provides p-values, and confidence intervals for
the mean value (print !). If all the confidence in-
tervals contain 0, then the null hypothesis is not rejected at the given level,
let’s say 95%. Which means that there are less than 5 chances out of 100 to
be wrong by saying that the true mean of the distribution is 0.
is a companion function to , that gives a visualization of
confidence intervals and average discounted prices.
0.0 0.2 0.4 0.6 0.8 1.0
−150 −50 0 50
conf. int.
for the martingale difference
time
conf. int.
0.0 0.2 0.4 0.6 0.8 1.0
4350 4450 4550
true (black) vs
monte carlo (blue) prices
time
prices
14
, tools for stochastic simulation •January 2020
0 50 100 150 200 250 300
500 1000 1500 2000
Convergence towards the call
option price
number of simulations
monte carlo estim. price
16
, tools for stochastic simulation •January 2020
References
Bates DS (1996). “Jumps and stochastic volatility: Exchange rate processes
implicit in deutsche mark options.” Review of financial studies,9(1), 69–107.
Black F, Scholes M (1973). “The pricing of options and corporate liabilities.”
The journal of political economy, pp. 637–654.
Brechmann EC, Czado C (2012). “Risk management with high-dimensional
vine copulas: An analysis of the Euro Stoxx 50.”
Brechmann EC, Schepsmeier U (2013). “Modeling dependence with C-and
D-vine copulas: The R-package CDVine.” Journal of Statistical Software,5(3),
1–27.
Brigo D, Mercurio F (2006). Interest rate models-theory and practice: with smile,
inflation and credit. Springer.
Cox JC, Ingersoll Jr JE, Ross SA (1985). “A theory of the term structure of
interest rates.” Econometrica: Journal of the Econometric Society, pp. 385–407.
Eddelbuettel D, François R (2011). “Rcpp: Seamless R and C++ integration.”
Journal of Statistical Software,40(8), 1–18.
Glasserman P (2004). Monte Carlo methods in financial engineering, volume 53.
Springer.
Iacus SM (2008). Simulation and inference for stochastic differential equations: with
R examples. Springer.
Kou SG (2002). “A jump-diffusion model for option pricing.” Management
science,48(8), 1086–1101.
Merton RC (1976). “Option pricing when underlying stock returns are discon-
tinuous.” Journal of financial economics,3(1), 125–144.
Uhlenbeck GE, Ornstein LS (1930). “On the theory of the Brownian motion.”
Physical review,36(5), 823.
Vasicek O (1977). “An equilibrium characterization of the term structure.”
Journal of financial economics,5(2), 177–188.
Wickham H (2009). ggplot2: elegant graphics for data analysis. Springer.
17