# simByQuadExp

Simulate `Bates`

, `Heston`

, and
`CIR`

sample paths by quadratic-exponential discretization
scheme

*Since R2020a*

## Syntax

## Description

`[`

simulates `Paths`

,`Times`

,`Z`

] = simByQuadExp(`MDL`

,`NPeriods`

)`NTrials`

sample paths of a Heston model driven by
two Brownian motion sources of risk, or a CIR model driven by one Brownian
motion source of risk. Both Heston and Bates models approximate continuous-time
stochastic processes by a quadratic-exponential discretization scheme. The
`simByQuadExp`

simulation derives 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`

] = simByQuadExp(___,`Name,Value`

)

`[`

simulates `Paths`

,`Times`

,`Z`

,`N`

] = simByQuadExp(`MDL`

,`NPeriods`

)`NTrials`

sample paths of a Bates model driven by
two Brownian motion sources of risk, approximating continuous-time stochastic
processes by a quadratic-exponential discretization scheme. The
`simByQuadExp`

simulation derives 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`

,`N`

] = simByQuadExp(___,`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

### Simulate Bates Sample Paths by Quadratic-Exponential Discretization Scheme

Create a `bates`

object.

AssetPrice = 80; Return = 0.03; JumpMean = 0.02; JumpVol = 0.08; JumpFreq = 0.1; V0 = 0.04; Level = 0.05; Speed = 1.0; Volatility = 0.2; Rho = -0.7; StartState = [AssetPrice;V0]; Correlation = [1 Rho;Rho 1]; batesObj = bates(Return, Speed, Level, Volatility,... JumpFreq, JumpMean, JumpVol,'startstate',StartState,... 'correlation',Correlation)

batesObj = Class BATES: Bates Bivariate Stochastic Volatility -------------------------------------------------- Dimensions: State = 2, Brownian = 2 -------------------------------------------------- StartTime: 0 StartState: 2x1 double array Correlation: 2x2 double array Drift: drift rate function F(t,X(t)) Diffusion: diffusion rate function G(t,X(t)) Simulation: simulation method/function simByEuler Return: 0.03 Speed: 1 Level: 0.05 Volatility: 0.2 JumpFreq: 0.1 JumpMean: 0.02 JumpVol: 0.08

Use `simByQuadExp`

to simulate `NTrials`

sample paths directly from the stochastic differential equation of motion; the discrete-time process approaches the true continuous-time process only in the limit as `DeltaTimes`

approaches zero.

NPeriods = 2; [Paths,Times,Z,N] = simByQuadExp(batesObj,NPeriods)

`Paths = `*3×2*
80.0000 0.0400
64.3377 0.1063
31.5703 0.1009

`Times = `*3×1*
0
1
2

`Z = `*2×2*
0.5377 1.8339
-2.2588 0.8622

`N = `*2×1*
0
0

The output `Paths`

is returned as a (`NPeriods`

+ `1`

)-by-`NVars`

-by-`NTrials`

three-dimensional time-series array.

### Quasi-Monte Carlo Simulation Using Bates Model

This example shows how to use `simByQuadExp`

with a Bates model to perform a quasi-Monte Carlo simulation. Quasi-Monte Carlo simulation is a Monte Carlo simulation that uses quasi-random sequences instead pseudo random numbers.

Define the parameters for the `bates`

object.

AssetPrice = 80; Return = 0.03; JumpMean = 0.02; JumpVol = 0.08; JumpFreq = 0.1; V0 = 0.04; Level = 0.05; Speed = 1.0; Volatility = 0.2; Rho = -0.7; StartState = [AssetPrice;V0]; Correlation = [1 Rho;Rho 1];

Create a `bates`

object.

Bates = bates(Return, Speed, Level, Volatility, ... JumpFreq, JumpMean, JumpVol,'startstate',StartState, ... 'correlation',Correlation)

Bates = Class BATES: Bates Bivariate Stochastic Volatility -------------------------------------------------- Dimensions: State = 2, Brownian = 2 -------------------------------------------------- StartTime: 0 StartState: 2x1 double array Correlation: 2x2 double array Drift: drift rate function F(t,X(t)) Diffusion: diffusion rate function G(t,X(t)) Simulation: simulation method/function simByEuler Return: 0.03 Speed: 1 Level: 0.05 Volatility: 0.2 JumpFreq: 0.1 JumpMean: 0.02 JumpVol: 0.08

Perform a quasi-Monte Carlo simulation by using `simByQuadExp`

with the optional name-value arguments for `'MonteCarloMethod'`

,`'QuasiSequence'`

, and `'BrownianMotionMethod'`

.

[paths,time,z] = simByQuadExp(Bates,10,'ntrials',4096,'montecarlomethod','quasi','quasisequence','sobol','BrownianMotionMethod','brownian-bridge');

## Input Arguments

`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.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **```
[Paths,Times,Z,N] =
simByQuadExp(bates_obj,NPeriods,'DeltaTime',dt)
```

`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 the comma-separated pair consisting of
`'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 the comma-separated pair consisting of
`'NSteps'`

and a positive scalar integer.

The `simByQuadExp`

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
`simByQuadExp`

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`

`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 the
comma-separated pair consisting of `'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`

and `N`

), `simByQuadExp`

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 the comma-separated pair consisting of
`'QuasiSequence'`

and a string or character vector
with one of the following values:

`"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.

**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 the comma-separated
pair consisting of `'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`

`Antithetic`

— Flag to use antithetic sampling to generate the Gaussian random variates

`false`

(no antithetic
sampling) (default) | logical with values `true`

or
`false`

Flag to use antithetic sampling to generate the Gaussian random
variates that drive the Brownian motion vector (Wiener processes),
specified as the comma-separated pair consisting of
`'Antithetic'`

and a scalar numeric or logical
`1`

(`true`

) or
`0`

(`false`

).

When you specify `true`

,
`simByQuadExp`

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`

), `simByEuler`

ignores the
value of `Antithetic`

.

**Data Types: **`logical`

`Z`

— Direct specification of dependent random noise process for generating Brownian motion vector

generates correlated Gaussian variates based on the
`Correlation`

member of the
`heston`

, `bates`

, or
`cir`

object (default) | function | three-dimensional array of dependent random variates

Direct specification of the dependent random noise process for
generating the Brownian motion vector (Wiener process) that drives the
simulation, specified as the comma-separated pair consisting of
`'Z'`

and a function or an ```
(NPeriods ⨉
NSteps)
```

-by-`NBrowns`

-by-`NTrials`

three-dimensional array of dependent random variates.

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*X*_{t}

**Data Types: **`double`

| `function`

`N`

— Dependent random counting process for generating number of jumps

random numbers from Poisson distribution with
parameter `JumpFreq`

from a `bates`

object (default) | three-dimensional array | function

Dependent random counting process for generating the number of jumps,
specified as the comma-separated pair consisting of
`'N'`

and a function or an
(`NPeriods`

⨉ `NSteps`

)
-by-`NJumps`

-by-`NTrials`

three-dimensional array of dependent random variates. If you specify a
function, `N`

must return an
`NJumps`

-by-`1`

column vector, and
you must call it with two inputs: a real-valued scalar observation time
*t* followed by an
`NVars`

-by-`1`

state vector
*X _{t}*.

**Note**

The `N`

name-value pair argument is supported
only when you use a `bates`

object
for the `MDL`

input argument.

**Data Types: **`double`

| `function`

`StorePaths`

— Flag that indicates how `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 the comma-separated pair consisting of
`'StorePaths'`

and a scalar numeric or logical
`1`

(`true`

) or
`0`

(`false`

).

If `StorePaths`

is `true`

(the
default value) or is unspecified, `simByQuadExp`

returns `Paths`

as a three-dimensional time-series
array.

If `StorePaths`

is `false`

(logical
`0`

), `simByQuadExp`

returns
`Paths`

as an empty matrix.

**Data Types: **`logical`

`Processes`

— Sequence of end-of-period processes or state vector adjustments

`simByQuadExp`

makes no adjustments
and performs no processing (default) | function | cell array of functions

Sequence of end-of-period processes or state vector adjustments,
specified as the comma-separated pair consisting of
`'Processes'`

and a function or cell array of
functions of the form

$${X}_{t}=P(t,{X}_{t})$$

The `simByQuadExp`

function runs processing functions
at each interpolation time. The functions must accept the current
interpolation time *t*, and the current state vector
*X _{t}*
and return a state vector that can be an adjustment to the input
state.

If you specify more than one processing function,
`simByQuadExp`

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.

The end-of-period `Processes`

argument allows you to
terminate a given trial early. At the end of each time step,
`simByQuadExp`

tests the state vector
*X _{t}* for an
all-

`NaN`

condition. Thus, to signal an early
termination of a given trial, all elements of the state vector
*X*must be

_{t}`NaN`

. This test enables you to define a
`Processes`

function to signal early termination of
a trial, and offers significant performance benefits in some situations
(for example, pricing down-and-out barrier options).**Data Types: **`cell`

| `function`

## Output Arguments

`Paths`

— Simulated paths of correlated state variables

array

Simulated paths of correlated state variables for a heston, bates, or cir
model, returned as a ```
(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
*X*_{t} at time
*t*. When `StorePaths`

is set to
`false`

, `simByQuadExp`

returns
`Paths`

as an empty matrix.

`Times`

— Observation times associated with simulated paths

column vector

Observation times for a heston, bates, or cir model associated with the
simulated paths, returned as a ```
(NPeriods +
1)
```

-by-`1`

column vector. Each element of
`Times`

is associated with the corresponding row of
`Paths`

.

`Z`

— Dependent random variates for generating Brownian motion vector

array

Dependent random variates for a heston, bates, or cir model for generating
the Brownian motion vector (Wiener processes) that drive the simulation,
returned as an ```
(NPeriods ⨉
NSteps)
```

-by-`NBrowns`

-by-`NTrials`

three-dimensional time-series array.

`N`

— Dependent random variates for generating jump counting process vector

array

Dependent random variates for a bates model for generating the jump
counting process vector, returned as a ```
(NPeriods ⨉
NSteps)
```

-by-`NJumps`

-by-`NTrials`

three-dimensional time-series array.

## More About

### 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

### Heston

In the Heston stochastic volatility model, the asset value process and volatility process are defined as

$$\begin{array}{l}dS(t)=\gamma (t)S(t)dt+\sqrt{V(t)}S(t)d{W}_{S}(t)\\ dV(t)=\kappa (\theta -V(t))dt+\sigma \sqrt{V(t)}d{W}_{V}(t)\end{array}$$

Here:

*γ*is the continuous risk-free rate.*θ*is a long-term variance level.*κ*is the mean reversion speed for the variance.*σ*is the volatility of volatility.

### CIR

You can simulate any vector-valued CIR process of the form

$$d{X}_{t}=S(t)[L(t)-{X}_{t}]dt+D(t,{X}_{t}^{\frac{1}{2}})V(t)d{W}_{t}$$

Here:

*X*is an_{t}`NVars`

-by-`1`

state vector of process variables.*S*is an`NVars`

-by-`NVars`

matrix of mean reversion speeds (the rate of mean reversion).*L*is an`NVars`

-by-`1`

vector of mean reversion levels (long-run mean or level).*D*is an`NVars`

-by-`NVars`

diagonal matrix, where each element along the main diagonal is the square root of the corresponding element of the state vector.*V*is an`NVars`

-by-`NBrowns`

instantaneous volatility rate matrix.*dW*is an_{t}`NBrowns`

-by-`1`

Brownian motion vector.

### Bates

Bates models are bivariate composite models. Each Bates model consists of two coupled univariate models.

A geometric Brownian motion (

`gbm`

) model with a stochastic volatility function and jumps that is expressed as follows.$$d{X}_{1t}=B(t){X}_{1t}dt+\sqrt{{X}_{2t}}{X}_{1t}d{W}_{1t}+Y(t){X}_{1t}d{N}_{t}$$

This model usually corresponds to a price process whose volatility (variance rate) is governed by the second univariate model.

A Cox-Ingersoll-Ross (

`cir`

) square root diffusion model that is expressed as follows.$$d{X}_{2t}=S(t)[L(t)-{X}_{2t}]dt+V(t)\sqrt{{X}_{2t}}d{W}_{2t}$$

This model describes the evolution of the variance rate of the coupled Bates price process.

## References

[1] Andersen, Leif. “Simple and Efficient Simulation of the Heston Stochastic
Volatility Model.” *The Journal of Computational Finance* 11, no. 3
(March 2008): 1–42.

[2] Broadie, M., and O. Kaya. “Exact Simulation of Option Greeks under Stochastic
Volatility and Jump Diffusion Models.” In *Proceedings of the 2004 Winter
Simulation Conference*, 2004., 2:535–43. Washington, D.C.: IEEE,
2004.

[3] Broadie, Mark, and Özgür Kaya. “Exact Simulation of Stochastic Volatility and
Other Affine Jump Diffusion Processes.” *Operations Research* 54,
no. 2 (April 2006): 217–31.

## Version History

**Introduced in R2020a**

### R2022b: Perform Brownian bridge and principal components construction

Perform Brownian bridge and principal components construction using the name-value
argument `BrownianMotionMethod`

.

### R2022a: Perform Quasi-Monte Carlo simulation

Perform Quasi-Monte Carlo simulation using the name-value arguments
`MonteCarloMethod`

and
`QuasiSequence`

.

## See Also

`bates`

| `heston`

| `cir`

| `simByEuler`

| `simByTransition`

### Topics

- Simulating Equity Prices
- Simulating Interest Rates
- Stratified Sampling
- Price American Basket Options Using Standard Monte Carlo and Quasi-Monte Carlo Simulation
- Base SDE Models
- Drift and Diffusion Models
- Linear Drift Models
- Parametric Models
- SDEs
- SDE Models
- SDE Class Hierarchy
- Quasi-Monte Carlo Simulation
- Performance Considerations

## Ouvrir l'exemple

Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?

## Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

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)