PreprintPDF Available

ESGtoolkit, a tool for stochastic simulation (v0.2.0)

Authors:
Preprints and early-stage research may not have been peer reviewed yet.

Abstract

This preprint is about a tool for stochastic simulation in Finance, Insurance, Economics or Physics (...).
, 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))t0being a standard brownian motion):
dS(t) = µS(t)dt +σS(t)dW(t)(1)
Let rbe a constant risk-free rate. ert S(t), the discounted price of S(t), will
be a martingale if
d(ert S(t)) (2)
is driftless. Applying Ito’s formula to ert S(t), we have :
d(ert S(t)) = rert S(t)dt +ertdS(t)1
2.0 <dS(t),dS(t)>(3)
=rert S(t)dt +ert µS(t)dt +ertS(t)σdW(t)(4)
=ert 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))t0is 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))t0be a standard brownian motion. makes simulations
of a diffusion process (X(t))t0, 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))t0with 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
e1
ηu11y>0+ (1p)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))t0
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
There’s a nice function from the package, , that helps you
in visualizing dependence between shocks (inspired by this blog post) :
0.0
0.1
0.2
0.3
0.4
−2 0 2
xvar
density
−2
0
2
−2 0 2
xvar
yvar
zvar
x
y
−2
0
2
0.00.10.20.30.4
density
yvar
9
, 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)+ (J1)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
erT S(i)
TE[erTST] = 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[erT STS0] = 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
Another interesting exercise is to price a Call Option under the Bates model
described at the beginning of this section:
15
, 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
ResearchGate has not been able to resolve any citations for this publication.
Article
Full-text available
Flexible multivariate distributions are needed in many areas. The popular multivariate Gaussian distribution is however very restrictive and cannot account for features like asymmetry and heavy tails. Therefore dependence modeling using copulas is nowadays very common to account for such patterns. The use of copulas is however challenging in higher dimensions, where standard multivariate copulas suffer from rather inflexible structures. Vine copulas overcome such limitations and are able to model complex dependency patterns by benefiting from the rich variety of bivariate copulas as building blocks. This article presents the R package CDVine which provides functions and tools for statistical inference of canonical vine (C-vine) and D-vine copulas. It contains tools for bivariate exploratory data analysis and for bivariate copula selection as well as for selection of pair-copula families in a vine. Models can be estimated either sequentially or by joint maximum likelihood estimation. Sampling algorithms and graphical methods are also included.
Article
Full-text available
The Rcpp package simplifies integrating C++ code with R. It provides a consistent C++ class hierarchy that maps various types of R objects (vectors, matrices, functions, environments, . . . ) to dedicated C++ classes. Object interchange between R and C++ is managed by simple, flexible and extensible concepts which include broad support for C++ Standard Template Library idioms. C++ code can both be compiled, linked and loaded on the fly, or added via packages. Flexible error and exception code handling is provided. Rcpp substantially lowers the barrier for programmers wanting to combine C++ code with R.
Article
Full-text available
The validity of the classic Black-Scholes option pricing formula depends on the capability of investors to follow a dynamic portfolio strategy in the stock that replicates the payoff structure to the option. The critical assumption required for such a strategy to be feasible, is that the underlying stock return dynamics can be described by a stochastic process with a continuous sample path. In this paper, an option pricing formula is derived for the more-general case when the underlying stock returns are generated by a mixture of both continuous and jump processes. The derived formula has most of the attractive features of the original Black-Scholes formula in that it does not depend on investor preferences or knowledge of the expected return on the underlying stock. Moreover, the same analysis applied to the options can be extended to the pricing of corporate liabilities.
Article
With a method first indicated by Ornstein the mean values of all the powers of the velocity u and the displacement s of a free particle in Brownian motion are calculated. It is shown that u−u0exp(−βt) and s−u0β[1−exp(−βt)] where u0 is the initial velocity and β the friction coefficient divided by the mass of the particle, follow the normal Gaussian distribution law. For s this gives the exact frequency distribution corresponding to the exact formula for s2 of Ornstein and Fürth. Discussion is given of the connection with the Fokker-Planck partial differential equation. By the same method exact expressions are obtained for the square of the deviation of a harmonically bound particle in Brownian motion as a function of the time and the initial deviation. Here the periodic, aperiodic and overdamped cases have to be treated separately. In the last case, when β is much larger than the frequency and for values of t≫β−1, the formula takes the form of that previously given by Smoluchowski.
Article
The demand for an accurate financial risk management involving larger numbers of assets is strong not only in view of the financial crisis of 2007-2009. In particular dependencies among assets have not been captured adequately. While standard multivariate copulas have added some flexibility, this flexibility is insufficient in higher dimensional applications. Vine copulas can fill this gap by benefiting from the rich class of existing bivariate parametric copula families. Exploiting this in combination with GARCH models for margins, we develop a regular vine copula based factor model for asset returns, the Regular Vine Market Sector model, that is motivated by the classical CAPM and shown to be superior to the CAVA model proposed by Heinen and Valdesogo (2009). While the model can also be used to separate the systematic and idiosyncratic risk of specific stocks, we explicitly discuss how vine copula models can be employed for active and passive portfolio management. In particular, Value-at-Risk forecasting and asset allocation are treated in detail. All developed models and methods are used to analyze the Euro Stoxx 50 index, a major market indicator for the Eurozone. Relevant benchmark models such as the popular DCC model and the common Student-t copula are taken into account.
Book
The 2nd edition of this successful book has several new features. The calibration discussion of the basic LIBOR market model has been enriched considerably, with an analysis of the impact of the swaptions interpolation technique and of the exogenous instantaneous correlation on the calibration outputs. A discussion of historical estimation of the instantaneous correlation matrix and of rank reduction has been added, and a LIBOR-model consistent swaption-volatility interpolation technique has been introduced. The old sections devoted to the smile issue in the LIBOR market model have been enlarged into several new chapters. New sections on local-volatility dynamics, and on stochastic volatility models have been added, with a thorough treatment of the recently developed uncertain-volatility approach. Examples of calibrations to real market data are now considered. The fast-growing interest for hybrid products has led to new chapters. A special focus here is devoted to the pricing of inflation-linked derivatives. The three final new chapters of this second edition are devoted to credit. Since Credit Derivatives are increasingly fundamental, and since in the reduced-form modeling framework much of the technique involved is analogous to interest-rate modeling, Credit Derivatives -- mostly Credit Default Swaps (CDS), CDS Options and Constant Maturity CDS - are discussed, building on the basic short rate-models and market models introduced earlier for the default-free market. Counterparty risk in interest rate payoff valuation is also considered, motivated by the recent Basel II framework developments.
Article
Brownian motion and normal distribution have been widely used in the Black--Scholes option-pricing framework to model the return of assets. However, two puzzles emerge from many empirical investigations: the leptokurtic feature that the return distribution of assets may have a higher peak and two (asymmetric) heavier tails than those of the normal distribution, and an empirical phenomenon called "volatility smile" in option markets. To incorporate both of them and to strike a balance between reality and tractability, this paper proposes, for the purpose of option pricing, a double exponential jump-diffusion model. In particular, the model is simple enough to produce analytical solutions for a variety of option-pricing problems, including call and put options, interest rate derivatives, and path-dependent options. Equilibrium analysis and a psychological interpretation of the model are also presented.
Article
The paper derives a general form of the term structure of interest rates. The following assumptions are made: (A.1) The instantaneous (spot) interest rate follows a diffusion process; (A.2) the price of a discount bond depends only on the spot rate over its term; and (A.3) the market is efficient. Under these assumptions, it is shown by means of an arbitrage argument that the expected rate of return on any bond in excess of the spot rate is proportional to its standard deviation. This property is then used to derive a partial differential equation for bond prices. The solution to that equation is given in the form of a stochastic integral representation. An interpretation of the bond pricing formula is provided. The model is illustrated on a specific case.