Vous êtes sur la page 1sur 10

Monte Carlo Simulations

With implementation in Matlab


Cliff Andrus

Simulation is widely used to solve problems that are intractable from an analytical
point of view. Basically, Monte Carlo Simulation is based on statistical sampling, and it
may be visualized as black box in which a stream of pseudorandom numbers enters.
Simulation is an imitation of real-world process or system over time. Simulation involves
the generation of an artificial history to draw inferences concerning the operating
characteristics of the real system that is represented.
The advantages of simulations include: ability to study complicated models for
analytical or numerical treatment. It can study detailed relations that might be lost in the
analytical or numerical treatment. It can be used as a basis for experimental studies of
systems and used to check results and give credibility to conclusions obtained by other
methods. Finally, simulation is a really nice demo method. Except above advantages,
simulation also has some disadvantages. For example, sometimes it is very time
consuming and costly to run a simulation and sometimes it gives random output and lots
of misinterpretation of results. For some certain problem, better methods than simulation
may exist.

Monte Carlo methods in finance


Recall from the fundamental theorem of arbitrage-free pricing that the value of a
derivative is equal to the discounted expected value of the derivative payoff where the
expectation is taken under the risk-neutral measure [1]. An expectation is, in the language
of pure mathematics, simply an integral with respect to the measure. Monte Carlo
methods are ideally suited to evaluating difficult integrals (see also Monte Carlo method).
Thus let us suppose that our risk-neutral probability space is and that we have a
derivative H that depends on a set of underlying instruments S_1,...,S_n. Then given a

sample

from

the

probability

space

the

value

of

the

derivative

is

H(S1(),S2(),...,Sn() = :H(). Today's value of the derivative is found by taking the


expectation over all possible samples and discounting at the risk-free rate. I.e. the
derivative has value:

where P(0,T) is the discount factor corresponding to the risk-free rate at the final maturity
date T years into the future.
Now suppose the integral is hard to compute. We can approximate the integral by
generating sample paths and then taking an average. Suppose we generate N samples then

which is much easier to compute.

Sample paths for standard models


In finance underlying random variables (such as an underlying stock price) are usually
assumed to follow a path that is a function of a Brownian motion 2. For example in the
standard Black-Scholes model, the stock price evolves as
dS = (t)Sdt + (t)SdWt.
To sample a path following this distribution from time 0 to T, we chop the time interval of
M units of length t, and approximate the Brownian motion over the interval dt by a
single normal variable of mean 0 and variance t. This leads to a sample path of

for each k between 1 and M. Here each i is a draw from a standard normal distribution.
Let us suppose that a derivative H pays the average value of S between 0 and T then a
sample path corresponds to a set {1,...,M} and

We obtain the Monte-Carlo value of this derivative by generating N lots of M normal


variables, creating N sample paths and so N values of H, and then taking the derivative.
Commonly the derivative will depend on two or more (possibly correlated) underlyings.
The method here can be extended to generate sample paths of several variables, where
the normal variables building up the sample paths are appropriately correlated.
It follows from the Central Limit Theorem that quadrupling the number of sample paths
approximately halves the error in the simulated price (i.e. the error has order sqrt(N)
convergence).
In practice Monte Carlo methods are used for European-style derivatives involving at
least three variables (more direct methods involving numerical integration can usually be
used for those problems with only one or two underlyings. See Monte Carlo option model
Greeks
Estimates for the "Greeks" of an option i.e. the (mathematical) derivatives of option value
with respect to input parameters, can be obtained by numerical differentiation. This can
be a time-consuming process (an entire Monte Carlo run must be performed for each
"bump" or small change in input parameters). Further taking numerical derivatives tends
to emphasize the error (or noise) in the Monte Carlo value - making it necessary to
simulate with a large number of sample paths. Practitioners regard these points as the key
problem with using Monte Carlo methods.

Variance reduction
Square root convergence is slow, and so using the naive approach described above
requires using a very large number of sample paths (1 million, say, for a typical problem)
in order to obtain an accurate result. This state of affairs can be mitigated by variance
reduction techniques. A simple technique is, for every sample path obtained, to take its
antithetic path - that is given a path {1,...,M} to also take { 1,..., M}. Not only does
this reduce the number of normal samples to be taken to generate N paths, but also
reduces the variance of the sample paths, improving the accuracy.
Secondly it is also natural to use a control variate. Let us suppose that we wish to obtain
the Monte Carlo value of a derivative H, but know the value analytically of a similar
derivative I. Then H* = (Value of H according to Monte Carlo) + (Value of I analytically)
- (Value of I according to same Monte Carlo paths) is a better estimate.
Quasi-random (low-discrepancy) methods
Instead of generating sample paths randomly, it is possible to systematically (and in fact
completely deterministically, despite the "quasi-random" in the name) select points in a
probability spaces so as to optimally "fill up" the space. The selection of points is a lowdiscrepancy sequence such as a Sobol sequence. Taking averages of derivative payoffs at
points in a low-discrepancy sequence is often more efficient than taking averages of
payoffs at random points.

Quasi-Monte Carlo method


In numerical analysis, a quasi-Monte Carlo method is a method for the computation of an
integral (or some other problem) that is based on low-discrepancy sequences. This is in
contrast to a regular Monte Carlo method, which is based on sequences of pseudorandom
numbers.
Monte Carlo and quasi-Monte Carlo methods are stated in a similar way. The problem is
to approximate the integral of a function f as the average of the function evaluated at a set
of points x1, ..., xN.

where s is the s-dimensional unit cube, s = [0, 1] ... [0, 1]. (Thus each xi is a vector
of s elements.) In a Monte Carlo method, the set x1, ..., xN is a subsequence of
pseudorandom numbers. In a quasi-Monte Carlo method, the set is a subsequence of a
low-discrepancy sequence.
The approximation error of a method of the above type is bounded by a term proportional
to the discrepancy of the set x1, ..., xN, by the Koksma-Hlawka inequality. The
discrepancy of sequences typically used for the quasi-Monte Carlo method is bounded by
constant times

In comparison, with probability one, the expected discrepancy of a uniform random


sequence (as used in the Monte Carlo method) has an order of convergence

by the law of the iterated logarithm.

Thus it would appear that the accuracy of the quasi-Monte Carlo method increases faster
than that of the Monte Carlo method. However, Morokoff and Caflisch cite examples of
problems in which the advantage of the quasi-Monte Carlo is less than expected
theoretically. Still, in the examples studied by Morokoff and Caflisch, the quasi-Monte
Carlo method did yield a more accurate result than the Monte Carlo method with the
same number of points.
Morokoff and Caflisch remark that the advantage of the quasi-Monte Carlo method is
greater if the integrand is smooth, and the number of dimensions s of the integral is small.
A technique, coined randomized quasi-Monte Carlo, that mixes quasi-Monte Carlo with
traditional Monte Carlo, extends the benefits of quasi-Monte Carlo to medium to large s.
Here is a Monte Carlo Simulation example from the help file in Matlab:
The third part of the example uses the same estimated model (coeff) it used in the second
part of the example, Forecasting, to simulate 20000 realizations for the same 30-day
period. The example explicitly specifies the needed presample data. It uses the inferred
residuals (eFit) and standard deviations (sFit) from the first part of the example,
Estimating the Model, as the presample inputs PreInnovations and PreSigmas,
respectively. It uses the nasdaq return series as the presample input PreSeries. Because all
three inputs are vectors, garchsim applies the same vector to each column of the
corresponding outputs, Innovations, Sigmas, and Series. In this context, referred to as
dependent-path simulation, all simulated sample paths share a common conditioning set
and evolve from the same set of initial conditions, thus enabling Monte Carlo simulation
of forecasts and forecast error distributions. Note that you can specify PreInnovations,
PreSigmas, and PreSeries as matrices, where each column is a realization, or as singlecolumn vectors. In either case, they must have a sufficient number of rows to initiate the
simulation (see User-Specified Presample Data). For this application of Monte Carlo
simulation, the example generates a relatively large number of realizations, or sample
paths, so that it can aggregate across realizations. Because each realization corresponds to
a column in the garchsim time-series output arrays, the output arrays are large, with many
columns. The following code simulates 20000 paths (i.e., columns). As a result, each

time-series output that garchsim returns is an array of size horizon-by-nPaths, or 30-by20000. Although more realizations (e.g., 100000) provide more accurate simulation
results, you may want to decrease the number of paths (e.g., to 10000) to avoid memory
limitations. nPaths = 20000; % Define the number of realizations.
[eSim,sSim,ySim] = garchsim(coeff,horizon,nPaths,[],[],[],...
eFit,sFit,nasdaq);

Because garchsim needs only the last, or most recent, observation of each, the following
command produces identical results.
[eSim,sSim,ySim] = garchsim(coeff,horizon,nPaths,[],[],[],...
eFit(end),sFit(end),nasdaq(end));

The following is a basic example of a Monte-Carlo Simulation used to estimate the value
of Pi:
Let us do a simple example of a Monte Carlo simulation to illustrate the technique. First,
let us consider the following problem; we want to make a simulation that will allow us to
find the value of pi. We will do this in the following way: consider a square that has one
corner at the origin of a coordinate system and has sides of length 1 - it will obviously
have an area of 1. Now consider inscribing a quarter of a circle inside of this with a
radius of 1 - we know that its area is pi/4. We can do a Monte Carlo simulation to find the

relative area of the circle and square and then multiply the circle's area by 4 to find pi. In
particular, the way we will find the area of the circle is to note the following: for a point
(X,Y) to be inside of a circle of radius 1, its distance from the origin (X 2+Y2) will be less
than or equal to 1. We can generate thousands of random (X,Y) positions (with 0<X,Y<1)
and determine whether each of them are inside of the circle. Each time it is inside of the
circle, we will add one to a counter. After generating a large number of points, the ratio of
the number of points inside the circle to the total number of points generated will
approach the ratio of the area of the circle to the area of the square. Thus the value of pi
would simply be
pi is approximately 4*(Number of Points inside circle)/ (Total Points Generated)
Thus we can find an approximation to pi using simple math

%
%

pimc2.m
Optimized Matlab Program to Find Pi using Random Numbers

Nrand = 8192;
% Largest size of an array in Student Version of Matlab
Nmax = input('How Many Loops (of 8192 Random Numbers Each) ');
NTrand = 0;
NInside = 0;
for nloops=1:Nmax
Xrand = rand(1,Nrand);
% Generates 8192 Random XY Points
Yrand = rand(1,Nrand);
Rrand = Xrand.^2 + Yrand.^2; % Finds the radius for all 8192
random points
CheckValue = Rrand<=1.; % Has 1 if True & 0 if False for each
element
NInside = NInside + sum(CheckValue); % Total number of Points
Inside
NTrand = NTrand + Nrand;
% Total number of Points Generated
end
disp(['Total Generated: ' num2str(NTrand) ' Inside Pts: ' ...
num2str(NInside)]);
piapprox = 4*NInside/NTrand;
pierror = 4*sqrt(NInside)/NTrand;
disp([' Approximation to pi = ' num2str(piapprox) ...
' With Error ' num2str(pierror)]);

The following is an example of code used to price a spread option using Monte Carlo
simulations (Haug)
Example:
Monte Carlo Simulation Spread Options
function MCSpreadOption(CallPutFlag, S1, S2, X, T, r, b1, b2, v1, v2,
rho , nSimulations)
%
%
Monte Carlo Simulation Spread Options
%
Key words: finance, option valuation, Monte Carlo simulation
%
%
Author:
Espen Gaarder Haug
%
(The author of "The
Complete Guide to Option Pricing Formulas," McGraw-Hill 1997
%
E-mail:
espehaug@online.no
%
hompage:
http://home.sol.no/~eshaug/
%
Environment: MATLAB 5.3 in Windows 98
%
%
Application: Monte Carlo Simulation of Spread Option Values:
%
%
The MCSpreadOption function can be used for valuation of spread
options
%
Spread options are actively traded on New York Mercantile
Exchange (NYMEX)
%
on the difference/spread between different oil qualities. Spread
options
%
are also popular in many other markets.
%
%
The code can easily be modified to also value other option
contracts dependent on
%
two correlated assets. Assuming correlated geometric Brownian
motions
%
%
Variable Description:
%
%
CallPutFlag= 'c' gives call option, 'p'
gives put option
%
S1= Asset one
%
S2= Asset two
%
X= Strike price
%
T= time to option maturity in number of
years
%
r= Risk-free-rate
%
b1= Cost of carry asset one
%
b2= Cost of carry asset two
%
v1= Volatility asset one
%
v2= Volatility asset two
%
rho= Correlation between assets (asset
return)

%
nSimulations=Number of simulations used
for Monte Carlo simulation
%
More simulations increase
accurancy, typically minimum 10000
%
%
At maturity the payoff from a call
spread option is max(S1-S2-X,0)
%
At maturity the payoff from a put spread
option is max(X-S1+S2,0)
%
%
%
For example :
%
%
MCSpreadOption('c',122,120,3,0.5,0.1,0,0,0.25,0.2,0.5,10000)
%
%
% To learn more about pricing of Spread Options
% and other exotic options see:
% Haug, E. G. 1997: "The Complete Guide To Option Pricing Formulas,"
McGraw-Hill
if CallPutFlag == 'c'
z = 1; % Will return call option value
else
z = -1;
% Will return put option value
end
Drift1 = (b1 - v1 ^ 2 / 2) * T; %Drift asset one
Drift2 = (b2 - v2 ^ 2 / 2) * T; % Drift asset two
v1Sqrdt = v1 * sqrt(T);
v2Sqrdt = v2 * sqrt(T);
sum=0;
for i = 1: nSimulations,
Epsilon1 = normrnd(0,1); % Random number from a standard normal
distribution
Epsilon2 = rho * Epsilon1 + normrnd(0,1) * sqrt(1 - rho ^ 2); %
St1 = S1 * exp(Drift1 + v1Sqrdt * Epsilon1);
St2 = S2 * exp(Drift2 + v2Sqrdt * Epsilon2);
sum = sum + max(z * (St1 - St2 - X), 0);
end
exp(-r * T) * (sum / nSimulations)% Return Monte Carlo estimate of
spread option

10

Vous aimerez peut-être aussi