Main Content

simulate

Simulate multivariate stochastic differential equations (SDEs) forSDE,BM,GBM,CEV,CIR,HWV,Heston,SDEDDO,SDELD,SDEMRD,Merton, orBatesmodels

Description

example

[Paths,Times,Z] = simulate(MDL)simulatesNTrialssample paths ofNVars相关state variables, driven byNBrownsBrownian motion sources of risk overNPeriodsconsecutive observation periods, approximating continuous-time stochastic processes.

example

[Paths,Times,Z] = simulate(___,Optional,Scheme)adds optional inputs forOptionalandScheme.

TheOptionalinput argument forsimulateaccepts any variable-length list of input arguments that the simulation method or function referenced by theSDE.Simulationparameter requires or accepts. It passes this input list directly to the appropriate SDE simulation method or user-defined simulation function.

The optional inputSchemelets you specify an approximation scheme used to simulate the sample paths and you can use this optional input with or without anOptionalinput argument.

Examples

collapse all

Consider a European up-and-in call option on a single underlying stock. The evolution of this stock's price is governed by a Geometric Brownian Motion (GBM) model with constant parameters:

Assume the following characteristics:

  • The stock currently trades at 105.

  • The stock pays no dividends.

  • The stock volatility is 30% per annum.

  • The option strike price is 100.

  • The option expires in three months.

  • The option barrier is 120.

  • The risk-free rate is constant at 5% per annum.

The goal is to simulate various paths of daily stock prices, and calculate the price of the barrier option as the risk-neutral sample average of the discounted terminal option payoff. Since this is a barrier option, you must also determine if and when the barrier is crossed.

This example performs antithetic sampling by explicitly setting theAntitheticflag totrue, and then specifies an end-of-period processing function to record the maximum and terminal stock prices on a path-by-path basis.

Create a GBM model usinggbm.

barrier = 120;% barrierstrike = 100;% exercise pricerate = 0.05;%年无风险的老鼠esigma = 0.3;% annualized volatilitynPeriods = 63;% 63 trading daysdt = 1 / 252;% time increment = 252 daysTime = nPeriods * dt;% expiration time = 0.25 yearsobj = gbm(rate, sigma,'StartState', 105);

Perform a small-scale simulation that explicitly returns two simulated paths.

rng('default')% make output reproducible[X, T] = obj.simBySolution(nPeriods,'DeltaTime', dt,...'nTrials', 2,'Antithetic', true);

Perform antithetic sampling such that all primary and antithetic paths are simulated and stored in successive matching pairs. Odd paths (1,3,5,...) correspond to the primary Gaussian paths. Even paths (2,4,6,...) are the matching antithetic paths of each pair, derived by negating the Gaussian draws of the corresponding primary (odd) path. Verify this by examining the matching paths of the primary/antithetic pair.

plot(T, X(:,:,1),'blue', T, X(:,:,2),'red') xlabel('Time (Years)'), ylabel('Stock Price'),...title('Antithetic Sampling') legend({'Primary Path''Antithetic Path'},...'Location','Best')

Figure contains an axes object. The axes object with title Antithetic Sampling, xlabel Time (Years), ylabel Stock Price contains 2 objects of type line. These objects represent Primary Path, Antithetic Path.

To price the European barrier option, specify an end-of-period processing function to record the maximum and terminal stock prices. This processing function is accessible by time and state, and is implemented as a nested function with access to shared information that allows the option price and corresponding standard error to be calculated. For more information on using an end-of-period processing function, seePricing Equity Options.

Simulate 200 paths using the processing function method.

rng('default')% make output reproduciblebarrier = 120;% barrierstrike = 100;% exercise pricerate = 0.05;%年无风险的老鼠esigma = 0.3;% annualized volatilitynPeriods = 63;% 63 trading daysdt = 1 / 252;% time increment = 252 daysTime = nPeriods * dt;% expiration time = 0.25 yearsobj = gbm(rate, sigma,'StartState', 105); nPaths = 200;% # of paths = 100 sets of pairsf = Example_BarrierOption(nPeriods, nPaths); simulate(obj, nPeriods,'DeltaTime', dt,...'nTrials', nPaths,'Antithetic', true,...'Processes', f.SaveMaxLast);

Approximate the option price with a 95% confidence interval.

optionPrice = f.OptionPrice(strike, rate, barrier); standardError = f.StandardError(strike, rate, barrier,...true); lowerBound = optionPrice - 1.96 * standardError; upperBound = optionPrice + 1.96 * standardError; displaySummary(optionPrice, standardError, lowerBound, upperBound);
Up-and-In Barrier Option Price: 6.6572 Standard Error of Price: 0.7292 Confidence Interval Lower Bound: 5.2280 Confidence Interval Upper Bound: 8.0864

Utility Function

functiondisplaySummary(optionPrice, standardError, lowerBound, upperBound) fprintf(' Up-and-In Barrier Option Price: %8.4f\n',...optionPrice); fprintf(' Standard Error of Price: %8.4f\n',...standardError); fprintf(' Confidence Interval Lower Bound: %8.4f\n',...lowerBound); fprintf(' Confidence Interval Upper Bound: %8.4f\n',...upperBound);end

The Cox-Ingersoll-Ross (CIR) short rate class derives directly from SDE with mean-reverting drift (SDEMRD): d X t = S ( t ) [ L ( t ) - X t ] d t + D ( t , X t 1 2 ) V ( t ) d W

where D is a diagonal matrix whose elements are the square root of the corresponding element of the state vector.

Create acirobject to represent the model: d X t = 0 . 2 ( 0 . 1 - X t ) d t + 0 . 0 5 X t 1 2 d W .

cir_obj = cir(0.2, 0.1, 0.05)% (Speed, Level, Sigma)
cir_obj = Class CIR: Cox-Ingersoll-Ross ---------------------------------------- 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 Sigma: 0.05 Level: 0.1 Speed: 0.2

Use the optional name-value argument for'Scheme'to specify a scheme to simulate the sample paths.

[paths,times] = simulate(cir_obj,10,'ntrials',4096,'scheme',“quadratic-exponential”);

The Cox-Ingersoll-Ross (CIR) short rate class derives directly from SDE with mean-reverting drift (SDEMRD): d X t = S ( t ) [ L ( t ) - X t ] d t + D ( t , X t 1 2 ) V ( t ) d W

where D is a diagonal matrix whose elements are the square root of the corresponding element of the state vector.

Create acirobject to represent the model: d X t = 0 . 2 ( 0 . 1 - X t ) d t + 0 . 0 5 X t 1 2 d W .

cir_obj = cir(0.2, 0.1, 0.05)% (Speed, Level, Sigma)
cir_obj = Class CIR: Cox-Ingersoll-Ross ---------------------------------------- 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 Sigma: 0.05 Level: 0.1 Speed: 0.2

Use optional name-value inputs for thesimByEulermethod that you can call throughsimulateinterface using thesimulate'Scheme'for“quadratic-exponential”. The optional inputs forsimByEulerdefine a quasi-Monte Carlo simulation using the name-value arguments for'MonteCarloMethod','QuasiSequence', and'BrownianMotionMethod'.

[paths,time] = simulate(cir_obj,10,'ntrials',4096,'montecarlomethod','quasi','quasisequence','sobol','BrownianMotionMethod','brownian-bridge','scheme',“quadratic-exponential”);

Input Arguments

collapse all

Stochastic differential equation model, specified as ansde,bates,bm,gbm,cev,cir,hwv,heston,mertonsdeddo,sdeld, orsdemrdobject.

Data Types:object

(Optional) Any variable-length list of input arguments that the simulation method or function referenced by theSDE.Simulationparameter requires or accepts, specified as a variable-length list of input arguments. This input list is passed directly to the appropriate SDE simulation method or user-defined simulation function.

Data Types:double

(Optional) Approximation scheme used to simulate the sample paths, specified as a character vector or string. When you specifyScheme, the MDL simulation method using the corresponding scheme is used instead of the one defined in theMDL.Simulationproperty which is thesimByEulermethod by default.

Note

The supportedSchemedepends on which SDE object you use with thesimulatemethod as follows:

simulateSchemeValue Supported Objects
"euler" sde,sdeddo,sdeld,sdemrd,bm,cev,gbm,merton,hwv,cir,heston, orbates
"solution" gbm,merton, orhwv
"transition" cir,heston, orbates
"quadratic-exponential" cir,heston, orbates
"milstein" sdeddo,sdeld,sdemrd,bm,cev,gbm,merton,hwv,cir,heston, orbates

Data Types:char|string

Output Arguments

collapse all

Three-dimensional time series array, consisting of simulated paths of correlated state variables, returned as an(NPeriods + 1)-by-NVars-by-NTrialsarray.

For a given trial, each row ofPathsis the transpose of the state vectorXtat timet.

Observation times associated with the simulated paths, returned as a(NPeriods + 1)-by-1column vector.

Three-dimensional time series array of dependent random variates used to generate the Brownian motion vector (Wiener processes) that drove the simulated results found inPaths,返回as aNTimes-by-NBrowns-by-NTrialsarray.

NTimesis the number of time steps at which thesimulatefunction samples the state vector.NTimesincludes intermediate times designed to improve accuracy, whichsimulatedoes not necessarily report in thePathsoutput time series.

More About

collapse all

Antithetic Sampling

Simulation methods allow you to specify a popularvariance reductiontechnique calledantithetic 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 theprimary path, and the second as theantithetic 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:

d X t = F ( t , X t ) d t + G ( t , X t ) d W t (1)
where:

  • Xis anNVars-by-1state vector of process variables (for example, short rates or equity prices) to simulate.

  • Wis anNBrowns-by-1Brownian motion vector.

  • Fis anNVars-by-1vector-valued drift-rate function.

  • Gis anNVars-by-NBrownsmatrix-valued diffusion-rate function.

References

[1] 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.

[2] Ait-Sahalia, Y. “Transition Densities for Interest Rate and Other Nonlinear Diffusions.”The Journal of Finance, Vol. 54, No. 4, August 1999.

[3] Glasserman, P.Monte Carlo Methods in Financial Engineering.New York, Springer-Verlag, 2004.

[4]船体,j . C。Options, Futures, and Other Derivatives, 5th ed. Englewood Cliffs, NJ: Prentice Hall, 2002.

[5] Johnson, N. L., S. Kotz, and N. Balakrishnan.Continuous Univariate Distributions.Vol. 2, 2nd ed. New York, John Wiley & Sons, 1995.

[6] Shreve, S. E.Stochastic Calculus for Finance II: Continuous-Time Models.New York: Springer-Verlag, 2004.

Version History

Introduced in R2008a

expand all