Simulate approximate solution of diagonal-drift GBM processes
[Paths,Times,Z] = simBySolution(MDL,NPERIODS)
[Paths,Times,Z] = simBySolution(MDL,NPERIODS,Name,Value)
[Paths,Times,Z] = simBySolution(MDL,NPERIODS) simulates
approximate solution of diagonal-drift for geometric Brownian motion
[Paths,Times,Z] = simBySolution(MDL,NPERIODS,Name,Value) simulates
approximate solution of diagonal-drift for GBM processes with additional
options specified by one or more
simBySolution method simulates
NVARS correlated state variables, driven
NBROWNS Brownian motion sources of risk over
observation periods, approximating continuous-time GBM short-rate
models by an approximation of the closed-form solution.
Consider a separable, vector-valued GBM model of the form:
Xt is an
vector of process variables.
μ is an
expected instantaneous rate of return matrix.
V is an
volatility rate matrix.
dWt is an
simBySolution method simulates the state
vector Xt using an approximation
of the closed-form solution of diagonal-drift models.
When evaluating the expressions,
that all model parameters are piecewise-constant over each simulation
In general, this is not the exact solution to the models, because the probability distributions of the simulated and true state vectors are identical only for piecewise-constant parameters.
When parameters are piecewise-constant over each observation period, the simulated process is exact for the observation times at which Xt is sampled.
MDL— Geometric Brownian motion (GBM) model
Geometric Brownian motion (GBM) model, specified as a
that is created using the
NPERIODS— Number of simulation periods
Number of simulation periods, specified as a positive scalar integer. The value of this argument determines the number of rows of the simulated output series.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside single quotes (
' '). You can
specify several name and value pair arguments in any order as
'NTRIALS'— Number of simulated trials (sample paths)
1(default) | positive scalar integer
Number of simulated trials (sample paths), specified as positive
scalar integer of
NPERIODS observations each. If
you do not specify a value for this argument, the default is
indicating a single path of correlated state variables.
'DeltaTime'— Time increments between observations
1(default) | positive scalar
Time increments between observations, specified as scalar or
vector of positive values.
the familiar dt found in stochastic differential
equations, and determines the times at which
the simulated paths of the output state variables. If you do not specify
a value for this argument, the default is
'NSTEPS'— Number of intermediate time steps within each time increment
1(default) | positive scalar integer
Number of intermediate time steps within each time increment dt (defined
DeltaTime), specified positive scalar integer.
each time increment dt into
of length dt/
NSTEPS, and refines
the simulation by evaluating the simulated state vector at
- 1 intermediate points. Although
not report the output state vector at these intermediate points, the
refinement improves accuracy by allowing the simulation to more closely
approximate the underlying continuous-time process. If you do not
specify a value for
NSTEPS, the default is
indicating no intermediate evaluation.
'Antithetic'— Flag that indicates whether antithetic sampling is used
0(default) | scalar logical with values
Flag that indicates whether antithetic sampling is used to generate
the Gaussian random variates that drive the Brownian motion vector
(Wiener processes), specified using a scalar logical with values
sampling such that all primary and antithetic paths are simulated
and stored in successive matching pairs:
to the primary Gaussian paths
(2,4,6,...) are the
matching antithetic paths of each pair derived by negating the Gaussian
draws of the corresponding primary (odd) trial.
If you specify
Antithetic to be any value
that it is
by default, and does not perform antithetic sampling. When you specify
an input noise process (see
the value of
'Z'— Direct specification of the dependent random noise process
simBySolutiongenerates correlated Gaussian variates based on the
Correlationmember of the
sdeobject (default) | array
Direct specification of the dependent random noise process used
to generate the Brownian motion vector (Wiener process) that drives
the simulation, specified as an
(NPERIODS * NSTEPS)-by-
of dependent random variates. If you specify
a function, it must return an
vector, and you must call it with two inputs:
A real-valued scalar observation time t.
'StorePaths'— Flag that indicates how output array
1(default) | scalar logical with values
Flag that indicates how output array
stored, specified as a scalar logical with values
TRUE (the default
value) or is unspecified,
a three-dimensional time series array.
Paths output array as an empty matrix.
'Processes'— Function or cell array of functions indicating a sequence of end-of-period processes or state vector adjustments
simBySolutionmakes no adjustments and performs no processing (default) | function or cell array of functions
Function or cell array of functions indicating a sequence of end-of-period processes or state vector adjustments of the form
simBySolution applies processing functions
at the end of each observation period. These functions must accept
the current observation time t and the current
state vector Xt, and return
a state vector that may be an adjustment to the input state. If you
specify more than one processing function,
the functions in the order in which they appear in the cell array.
You can use this argument to specify boundary conditions, prevent
negative prices, accumulate statistics, plot graphs, and more.
Paths— Simulated paths of correlated state variables
Simulated paths of correlated state variables, returned as a
time series array. For a given trial, each row of
the transpose of the state vector Xt at
When the input flag
an empty matrix.
Times— Observation times associated with simulated paths
Observation times associated with simulated paths, returned
(NPERIODS + 1)-by-
vector. Each element of
Times is associated with
the corresponding row of
Z— Array of dependent random variates used to generate the Brownian motion vector
Array of dependent random variates used to generate the Brownian
motion vector, returned as a
(NPERIODS * NSTEPS)-by-
time series array.
Use GBM simulation methods. Separable GBM models have two specific simulation methods:
An overloaded Euler
simulation method, designed for optimal performance.
simBySolution method that provides an approximate solution of the underlying stochastic differential equation, designed for accuracy.
Data_GlobalIdx2 data set and specify the SDE model as in Representing Market Models Using SDE Objects, and the GBM model as in Representing Market Models Using SDELD, CEV, and GBM Objects.
load Data_GlobalIdx2 prices = [Dataset.TSX Dataset.CAC Dataset.DAX ... Dataset.NIK Dataset.FTSE Dataset.SP]; returns = tick2ret(prices); nVariables = size(returns,2); expReturn = mean(returns); sigma = std(returns); correlation = corrcoef(returns); t = 0; X = 100; X = X(ones(nVariables,1)); F = @(t,X) diag(expReturn)* X; G = @(t,X) diag(X) * diag(sigma); SDE = sde(F, G, 'Correlation', ... correlation, 'StartState', X); GBM = gbm(diag(expReturn),diag(sigma), 'Correlation', ... correlation, 'StartState', X);
To illustrate the performance benefit of the overloaded Euler approximation method, increase the number of trials to
nPeriods = 249; % # of simulated observations dt = 1; % time increment = 1 day rng(142857,'twister') [X,T] = simulate(GBM, nPeriods, 'DeltaTime', dt, ... 'nTrials', 10000); whos X
Name Size Bytes Class Attributes X 250x6x10000 120000000 double
Using this sample size, examine the terminal distribution of Canada's TSX Composite to verify qualitatively the lognormal character of the data.
histogram(squeeze(X(end,1,:)), 30), xlabel('Price'), ylabel('Frequency') title('Histogram of Prices after One Year: Canada (TSX Composite)')
Simulate 10 trials of the solution and plot the first trial:
rng('default') [S,T] = simulate(SDE, nPeriods, 'DeltaTime', dt, 'nTrials', 10); rng('default') [X,T] = simBySolution(GBM, nPeriods,... 'DeltaTime', dt, 'nTrials', 10); subplot(2,1,1) plot(T, S(:,:,1)), xlabel('Trading Day'),ylabel('Price') title('1st Path of Multi-Dim Market Model:Euler Approximation') subplot(2,1,2) plot(T, X(:,:,1)), xlabel('Trading Day'),ylabel('Price') title('1st Path of Multi-Dim Market Model:Analytic Solution')
In this example, all parameters are constants, and
simBySolution does indeed sample the exact solution. The details of a single index for any given trial show that the price paths of the Euler approximation and the exact solution are close, but not identical.
The following plot illustrates the difference between the two methods:
subplot(1,1,1) plot(T, S(:,1,1) - X(:,1,1), 'blue'), grid('on') xlabel('Trading Day'), ylabel('Price Difference') title('Euler Approx Minus Exact Solution:Canada(TSX Composite)')
simByEuler Euler approximation literally evaluates the stochastic differential equation directly from the equation of motion, for some suitable value of the
dt time increment. This simple approximation suffers from discretization error. This error can be attributed to the discrepancy between the choice of the
dt time increment and what in theory is a continuous-time parameter.
The discrete-time approximation improves as
DeltaTime approaches zero. The Euler method is often the least accurate and most general method available. All models shipped in the simulation suite have this method.
In contrast, the
simBySolution method provides a more accurate description of the underlying model. This method simulates the price paths by an approximation of the closed-form solution of separable models. Specifically, it applies a Euler approach to a transformed process, which in general is not the exact solution to this
GBM model. This is because the probability distributions of the simulated and true state vectors are identical only for piecewise constant parameters.
When all model parameters are piecewise constant over each observation period, the simulated process is exact for the observation times at which the state vector is sampled. Since all parameters are constants in this example,
simBySolution does indeed sample the exact solution.
For an example of how to use
simBySolution to optimize the accuracy of solutions, see Optimizing Accuracy: About Solution Precision and Error.
The input argument
Z allows you
to directly specify the noise generation process. This process takes
precedence over the
Correlation parameter of the
and the value of the
Antithetic input flag. If
you do not specify a value for
correlated Gaussian variates, with or without antithetic sampling
Gaussian diffusion models, such as HWV, allow negative
states. By default,
simBySolution does nothing
to prevent negative states, nor does it guarantee that the model be
strictly mean-reverting. Thus, the model may exhibit erratic or explosive
allows you to terminate a given trial early. At the end of each time
simBySolution tests the state vector Xt for
NaN condition. Thus, to signal an early
termination of a given trial, all elements of the state vector Xt must
NaN. This test enables a user-defined
to signal early termination of a trial, and offers significant performance
benefits in some situations (for example, pricing down-and-out barrier
Ait-Sahalia, Y. “Testing Continuous-Time Models of the Spot Interest Rate.” The Review of Financial Studies, Spring 1996, Vol. 9, No. 2, pp. 385–426.
Ait-Sahalia, Y. “Transition Densities for Interest Rate and Other Nonlinear Diffusions.” The Journal of Finance, Vol. 54, No. 4, August 1999.
Glasserman, P. Monte Carlo Methods in Financial Engineering. New York, Springer-Verlag, 2004.
Hull, J. C. Options, Futures, and Other Derivatives, 5th ed. Englewood Cliffs, NJ: Prentice Hall, 2002.
Johnson, N. L., S. Kotz, and N. Balakrishnan. Continuous Univariate Distributions. Vol. 2, 2nd ed. New York, John Wiley & Sons, 1995.
Shreve, S. E. Stochastic Calculus for Finance II: Continuous-Time Models. New York: Springer-Verlag, 2004.