simByMilstein
Simulate diagonal diffusion for BM
, GBM
,
CEV
, HWV
, SDEDDO
,
SDELD
, or SDEMRD
sample paths by Milstein
approximation
Since R2023a
Description
[
simulates Paths
,Times
,Z
] = simByMilstein(MDL
,NPeriods
)NTrials
sample paths of NVARS
state
variables driven by the BM
, GBM
,
CEV
, HWV
, SDEDDO
,
SDELD
, or SDEMRD
process sources of risk
over NPeriods
consecutive observation periods, approximating
continuous-time by the Milstein approximation.
simByMilstein
provides a discrete-time approximation of the
underlying generalized continuous-time process. The simulation is derived directly
from the stochastic differential equation of motion; the discrete-time process
approaches the true continuous-time process only in the limit as
DeltaTime
approaches zero.
[
specifies options using one or more name-value pair arguments in addition to the
input arguments in the previous syntax.Paths
,Times
,Z
] = simByMilstein(___,Name=Value
)
You can perform quasi-Monte Carlo simulations using the name-value arguments for
MonteCarloMethod
, QuasiSequence
, and
BrownianMotionMethod
. For more information, see Quasi-Monte Carlo Simulation.
Examples
Quasi-Monte Carlo Simulation with Milstein Scheme Using GBM Model
This example shows how to use simByMilstein
with a GBM model to perform a quasi-Monte Carlo simulation. Quasi-Monte Carlo simulation is a Monte Carlo simulation that uses quasi-random sequences instead of pseudo random numbers.
Create a univariategbm
object to represent the model: .
GBM_obj = gbm(0.25, 0.3) % (B = Return, Sigma)
GBM_obj = Class GBM: Generalized Geometric Brownian Motion ------------------------------------------------ Dimensions: State = 1, Brownian = 1 ------------------------------------------------ StartTime: 0 StartState: 1 Correlation: 1 Drift: drift rate function F(t,X(t)) Diffusion: diffusion rate function G(t,X(t)) Simulation: simulation method/function simByEuler Return: 0.25 Sigma: 0.3
gbm
objects display the parameter B
as the more familiar Return
.
Perform a quasi-Monte Carlo simulation by using simByMilstein
with the optional name-value arguments for MonteCarloMethod
, QuasiSequence
, and BrownianMotionMethod
.
[paths,time,z] = simByMilstein(GBM_obj,10,ntrials=4096,montecarlomethod="quasi",quasisequence="sobol",BrownianMotionMethod="brownian-bridge");
Input Arguments
MDL
— Stochastic differential equation model
BM
object | GBM
object | CEV
object | HWV
object | SDEDDO
object | SDELD
object | SDEMRD
object
NPeriods
— Number of simulation periods
positive scalar integer
Number of simulation periods, specified as a positive scalar integer. The
value of NPeriods
determines the number of rows of the
simulated output series.
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: [Paths,Times,Z] =
simByMilstein(GBM_obj,NPeriods,DeltaTime=dt,Method="reflection")
Method
— Method to handle negative values
'basic'
(default) | character vector with values'basic'
,
'absorption'
, 'reflection'
,
'partial-truncation'
,
'full-truncation'
, or
'higham-mao'
| string with values "basic"
,
"absorption"
, "reflection"
,
"partial-truncation"
,
"full-truncation"
, or
"higham-mao"
Method to handle negative values, specified as
Method
and a character vector or string with a
supported value.
Data Types: char
| string
NTrials
— Simulated trials (sample paths) of NPeriods
observations each
1
(single path of correlated state
variables) (default) | positive scalar integer
Simulated trials (sample paths) of NPeriods
observations each, specified as NTrials
and a
positive scalar integer.
Data Types: double
DeltaTime
— Positive time increments between observations
1
(default) | scalar | column vector
Positive time increments between observations, specified as the
comma-separated pair consisting of 'DeltaTime'
and a
scalar or a NPeriods
-by-1
column
vector.
DeltaTime
represents the familiar
dt found in stochastic differential equations,
and determines the times at which the simulated paths of the output
state variables are reported.
Data Types: double
NSteps
— Number of intermediate time steps within each time increment dt (specified as
DeltaTime
)
1
(indicating no intermediate
evaluation) (default) | positive scalar integer
Number of intermediate time steps within each time increment
dt (specified as DeltaTime
),
specified as NSteps
and a positive scalar
integer.
The simByMilestein
function partitions each time
increment dt into NSteps
subintervals of length dt/NSteps
,
and refines the simulation by evaluating the simulated state vector at
NSteps − 1
intermediate points. Although
simByMilstein
does 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.
Data Types: double
Antithetic
— Flag to indicate whether simByMilstein
uses antithetic sampling to generate Gaussian random variates
False
(no antithetic
sampling) (default) | logical with values True
or
False
Flag that indicates whether simByMilstein
uses
antithetic sampling to generate the Gaussian random variates that drive
the Brownian motion vector (Wiener processes). This argument is
specified as Antithetic
and a scalar logical flag
with a value of True
or
False
.
When you specify True
,
simByMilstein
performs sampling such that all
primary and antithetic paths are simulated and stored in successive
matching pairs:
Odd trials
(1,3,5,...)
correspond to the primary Gaussian paths.Even trials
(2,4,6,...)
are the matching antithetic paths of each pair derived by negating the Gaussian draws of the corresponding primary (odd) trial.
Note
If you specify an input noise process (see
Z
), simByMilstein
ignores
the value of Antithetic
.
Data Types: logical
Z
— Direct specification of the dependent random noise process used to generate Brownian motion vector
generates correlated Gaussian variates based on the
Correlation
member of the SDE
object (default) | function | three-dimensional array of dependent random variates
Direct specification of the dependent random noise process used to
generate the Brownian motion vector (Wiener process) that drives the
simulation. This argument is specified as Z
and a
function or as an (NPeriods ⨉
NSteps)
-by-NBrowns
-by-NTrials
three-dimensional array of dependent random variates.
Note
If you specify Z
as a function, it must return
an NBrowns
-by-1
column vector,
and you must call it with two inputs:
A real-valued scalar observation time t.
An
NVars
-by-1
state vector Xt.
Data Types: double
| function
StorePaths
— Flag that indicates how the output array Paths
is stored and returned
True
(default) | logical with values True
or
False
Flag that indicates how the output array Paths
is
stored and returned, specified as StorePaths
and a
scalar logical flag with a value of True
or
False
.
If
StorePaths
isTrue
(the default value) or is unspecified,simByMilstein
returnsPaths
as a three-dimensional time series array.If
StorePaths
isFalse
(logical0
),simByMilstein
returns thePaths
output array as an empty matrix.
Data Types: logical
MonteCarloMethod
— Monte Carlo method to simulate stochastic processes
"standard"
(default) | string with values "standard"
,
"quasi"
, or
"randomized-quasi"
| character vector with values 'standard'
,
'quasi'
, or
'randomized-quasi'
Monte Carlo method to simulate stochastic processes, specified as
MonteCarloMethod
and a string or character vector
with one of the following values:
"standard"
— Monte Carlo using pseudo random numbers"quasi"
— Quasi-Monte Carlo using low-discrepancy sequences"randomized-quasi"
— Randomized quasi-Monte Carlo
Note
If you specify an input noise process (see
Z
), simByMilstein
ignores
the value of MonteCarloMethod
.
Data Types: string
| char
QuasiSequence
— Low discrepancy sequence to drive stochastic processes
"sobol"
(default) | string with value "sobol"
| character vector with value 'sobol'
Low discrepancy sequence to drive the stochastic processes, specified
as QuasiSequence
and a string or character vector
with the following value:
"sobol"
— Quasi-random low-discrepancy sequences that use a base of two to form successively finer uniform partitions of the unit interval and then reorder the coordinates in each dimension.
Note
If MonteCarloMethod
option is not specified
or specified as"standard"
,
QuasiSequence
is ignored.
If you specify an input noise process (see
Z
), simByMilstein
ignores
the value of QuasiSequence
.
Data Types: string
| char
BrownianMotionMethod
— Brownian motion construction method
"standard"
(default) | string with value "brownian-bridge"
or
"principal-components"
| character vector with value 'brownian-bridge'
or
'principal-components'
Brownian motion construction method, specified as
BrownianMotionMethod
and a string or character
vector with one of the following values:
"standard"
— The Brownian motion path is found by taking the cumulative sum of the Gaussian variates."brownian-bridge"
— The last step of the Brownian motion path is calculated first, followed by any order between steps until all steps have been determined."principal-components"
— The Brownian motion path is calculated by minimizing the approximation error.
Note
If an input noise process is specified using the
Z
input argument,
BrownianMotionMethod
is ignored.
The starting point for a Monte Carlo simulation is the construction of a Brownian motion sample path (or Wiener path). Such paths are built from a set of independent Gaussian variates, using either standard discretization, Brownian-bridge construction, or principal components construction.
Both standard discretization and Brownian-bridge construction share
the same variance and, therefore, the same resulting convergence when
used with the MonteCarloMethod
using pseudo random
numbers. However, the performance differs between the two when the
MonteCarloMethod
option
"quasi"
is introduced, with faster convergence
seen for "brownian-bridge"
construction option and
the fastest convergence when using the
"principal-components"
construction
option.
Data Types: string
| char
Processes
— Sequence of end-of-period processes or state vector adjustments
simByEuler
makes no adjustments and
performs no processing (default) | function | cell array of functions
Sequence of end-of-period processes or state vector adjustments of the
form, specified as Processes
and a function or cell
array of functions of the form
The simByMilstein
function runs processing
functions at each interpolation time. They must accept the current
interpolation 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,
simByMilstein
invokes 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.
Data Types: cell
| function
Output Arguments
Paths
— Simulated paths of correlated state variables
array
Simulated paths of correlated state variables, returned as an
(NPeriods +
1)
-by-NVars
-by-NTrials
three-dimensional time series array.
For a given trial, each row of Paths
is the transpose
of the state vector
Xt at time
t. When the input flag
StorePaths
= False
,
simByEuler
returns Paths
as an
empty matrix.
Times
— Observation times associated with simulated paths
column vector
Observation times associated with the simulated paths, returned as an
(NPeriods + 1)
-by-1
column vector.
Each element of Times
is associated with the
corresponding row of Paths
.
Z
— Dependent random variates used to generate Brownian motion vector
array
Dependent random variates used to generate the Brownian motion vector
(Wiener processes) that drive the simulation, returned as an
(NPeriods ⨉
NSteps)
-by-NBrowns
-by-NTrials
three-dimensional time series array.
More About
Milstein Method
The Milstein method is a numerical method for approximating solutions to stochastic differential equations (SDEs).
The Milstein method is an extension of the Euler-Maruyama method, which is a first-order numerical method for SDEs. The Milstein method adds a correction term to the Euler-Maruyama method that takes into account the second-order derivative of the SDE. This correction term improves the accuracy of the approximation, especially for SDEs with non-linearities.
Antithetic Sampling
Simulation methods allow you to specify a popular variance reduction technique called antithetic sampling.
This technique attempts to replace one sequence of random observations with another of the same expected value, but smaller variance. In a typical Monte Carlo simulation, each sample path is independent and represents an independent trial. However, antithetic sampling generates sample paths in pairs. The first path of the pair is referred to as the primary path, and the second as the antithetic path. Any given pair is independent of any other pair, but the two paths within each pair are highly correlated. Antithetic sampling literature often recommends averaging the discounted payoffs of each pair, effectively halving the number of Monte Carlo trials.
This technique attempts to reduce variance by inducing negative dependence between paired input samples, ideally resulting in negative dependence between paired output samples. The greater the extent of negative dependence, the more effective antithetic sampling is.
Algorithms
This function simulates any vector-valued SDE of the form
where:
X is an NVars-by-
1
state vector of process variables (for example, short rates or equity prices) to simulate.W is an NBrowns-by-
1
Brownian motion vector.F is an NVars-by-
1
vector-valued drift-rate function.G is an NVars-by-NBrowns matrix-valued diffusion-rate function.
simByEuler
simulates NTrials
sample
paths of NVars
correlated state variables driven by
NBrowns
Brownian motion sources of risk over
NPeriods
consecutive observation periods, using the Euler
approach to approximate continuous-time stochastic processes.
Consider the process X satisfying a stochastic differential equation of the form.
The attempt of including a term of O(dt) in the drift refines the Euler scheme and results in the algorithm derived by Milstein [1].
References
[1] Milstein, G.N. "A Method of Second-Order Accuracy Integration of Stochastic Differential Equations."Theory of Probability and Its Applications, 23, 1978, pp. 396–401.
Version History
Introduced in R2023a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)