Main Content

simulate

Monte Carlo simulation of conditional variance models

Description

example

V= simulate(Mdl,numObs)simulates anumObs-period conditional variance path from the fully specified conditional variance modelMdl.Mdlcan be agarch,egarch, orgjrmodel.

example

V= simulate(Mdl,numObs,Name,Value)simulates conditional variance paths with additional options specified by one or moreName,Valuepair arguments. For example, you can generate multiple sample paths or specify presample innovation paths.

example

[V,Y] = simulate(___)additionally simulates response paths using any of the input arguments in the previous syntaxes.

Examples

collapse all

Simulate conditional variance and response paths from a GARCH(1,1) model.

Specify a GARCH(1,1) model with known parameters.

Mdl = garch('Constant',0.01,'GARCH',0.7,'ARCH',0.2);

Simulate 500 sample paths, each with 100 observations.

rngdefault;% For reproducibility[V,Y] = simulate(Mdl,100,'NumPaths',500); figure subplot(2,1,1) plot(V) title('Simulated Conditional Variances') subplot(2,1,2) plot(Y) title('Simulated Responses')

Figure contains 2 axes. Axes 1 with title Simulated Conditional Variances contains 500 objects of type line. Axes 2 with title Simulated Responses contains 500 objects of type line.

The simulated responses look like draws from a stationary stochastic process.

Plot the 2.5th, 50th (median), and 97.5th percentiles of the simulated conditional variances.

lower = prctile(V,2.5,2); middle = median(V,2); upper = prctile(V,97.5,2); figure plot(1:100,lower,'r:',1:100,middle,'k',...1:100,upper,'r:','LineWidth',2) legend('95% Interval','Median') title('Approximate 95% Intervals')

Figure contains an axes. The axes with title Approximate 95% Intervals contains 3 objects of type line. These objects represent 95% Interval, Median.

The intervals are asymmetric due to positivity constraints on the conditional variance.

Simulate conditional variance and response paths from an EGARCH(1,1) model.

Specify an EGARCH(1,1) model with known parameters.

Mdl = egarch('Constant',0.001,'GARCH',0.7,'ARCH',0.2,...'Leverage',-0.3);

Simulate 500 sample paths, each with 100 observations.

rngdefault;% For reproducibility[V,Y] = simulate(Mdl,100,'NumPaths',500); figure subplot(2,1,1) plot(V) title('Simulated Conditional Variances') subplot(2,1,2) plot(Y) title('Simulated Responses (Innovations)')

Figure contains 2 axes. Axes 1 with title Simulated Conditional Variances contains 500 objects of type line. Axes 2 with title Simulated Responses (Innovations) contains 500 objects of type line.

The simulated responses look like draws from a stationary stochastic process.

Plot the 2.5th, 50th (median), and 97.5th percentiles of the simulated conditional variances.

lower = prctile(V,2.5,2); middle = median(V,2); upper = prctile(V,97.5,2); figure plot(1:100,lower,'r:',1:100,middle,'k',...1:100, upper,'r:','LineWidth',2) legend('95% Interval','Median') title('Approximate 95% Intervals')

Figure contains an axes. The axes with title Approximate 95% Intervals contains 3 objects of type line. These objects represent 95% Interval, Median.

The intervals are asymmetric due to positivity constraints on the conditional variance.

Simulate conditional variance and response paths from a GJR(1,1) model.

Specify a GJR(1,1) model with known parameters.

Mdl = gjr('Constant',0.001,'GARCH',0.7,'ARCH',0.2,...'Leverage',0.1);

Simulate 500 sample paths, each with 100 observations.

rngdefault;% For reproducibility[V,Y] = simulate(Mdl,100,'NumPaths',500); figure subplot(2,1,1) plot(V) title('Simulated Conditional Variances') subplot(2,1,2) plot(Y) title('Simulated Responses (Innovations)')

Figure contains 2 axes. Axes 1 with title Simulated Conditional Variances contains 500 objects of type line. Axes 2 with title Simulated Responses (Innovations) contains 500 objects of type line.

The simulated responses look like draws from a stationary stochastic process.

Plot the 2.5th, 50th (median), and 97.5th percentiles of the simulated conditional variances.

lower = prctile(V,2.5,2); middle = median(V,2); upper = prctile(V,97.5,2); figure plot(1:100,lower,'r:',1:100,middle,'k',...1:100, upper,'r:','LineWidth',2) legend('95% Interval','Median') title('Approximate 95% Intervals')

Figure contains an axes. The axes with title Approximate 95% Intervals contains 3 objects of type line. These objects represent 95% Interval, Median.

The intervals are asymmetric due to positivity constraints on the conditional variance.

Simulate conditional variances of the daily NASDAQ Composite Index returns for 500 days. Use the simulations to make forecasts and approximate 95% forecast intervals. Compare the forecasts among GARCH(1,1), EGARCH(1,1), and GJR(1,1) fits.

Load the NASDAQ data included with the toolbox. Convert the index to returns.

loadData_EquityIdxnasdaq = DataTable.NASDAQ; r = price2ret(nasdaq); T = length(r);

Fit GARCH(1,1), EGARCH(1,1), and GJR(1,1) models to the entire data set. Infer conditional variances to use as presample conditional variances for the forecast simulation.

Mdl = cell(3,1);% PreallocationMdl{1} = garch(1,1); Mdl{2} = egarch(1,1); Mdl{3} = gjr(1,1); EstMdl = cellfun(@(x)estimate(x,r,'Display','off'),Mdl,...'UniformOutput',false); v0 = cellfun(@(x)infer(x,r),EstMdl,'UniformOutput',false);

EstMdlis 3-by-1 cell vector. Each cell is a different type of estimated conditional variance model, e.g.,EstMdl{1}is an estimated GARCH(1,1) model.V0is a 3-by-1 cell vector, and each cell contains the inferred conditional variances from the corresponding, estimated model.

Simulate 1000 samples paths with 500 observations each. Use the observed returns and inferred conditional variances as presample data.

vSim = cell(3,1);% Preallocationforj = 1:3 rngdefault;% For reproducibilityvSim{j} = simulate(EstMdl{j},500,'NumPaths',1000,'E0',r,'V0',v0{j});end

vSimis a 3-by-1 cell vector, and each cell contains a 500-by-1000 matrix of simulated conditional variances generated from the corresponding, estimated model.

Plot the simulation mean forecasts and approximate 95% forecast intervals, along with the conditional variances inferred from the data.

lower = cellfun(@(x)prctile(x,2.5,2),vSim,'UniformOutput',false); upper = cellfun(@(x)prctile(x,97.5,2),vSim,'UniformOutput',false); mn = cellfun(@(x)mean(x,2),vSim,'UniformOutput',false); datesPlot = dates(end - 250:end); datesFH = dates(end) + (1:500)'; h = zeros(3,4); figureforj = 1:3坳= 0(1、3);坳(j) = 1;h (j, 1) =巴解组织t(datesPlot,v0{j}(end-250:end),'Color',col); holdonh(j,2) = plot(datesFH,mn{j},'Color',col,'LineWidth',3); h(j,3:4) = plot([datesFH datesFH],[lower{j} upper{j}],':',...'Color',col,'LineWidth',2);endhGCA = gca; plot(datesFH(1)*[1 1],hGCA.YLim,'k--'); datetick; axistight; h = h(:,1:3); legend(h(:),'GARCH - Inferred','EGARCH - Inferred','GJR - Inferred',...'GARCH - Sim. Mean','EGARCH - Sim. Mean','GJR - Sim. Mean',...'GARCH - 95% Fore. Int.','EGARCH - 95% Fore. Int.',...“GJR - 95%。Int。,'Location','NorthEast') title('Simulated Conditional Variance Forecasts') holdoff

Figure contains an axes. The axes with title Simulated Conditional Variance Forecasts contains 13 objects of type line. These objects represent GARCH - Inferred, GARCH - Sim. Mean, GARCH - 95% Fore. Int., EGARCH - Inferred, EGARCH - Sim. Mean, EGARCH - 95% Fore. Int., GJR - Inferred, GJR - Sim. Mean, GJR - 95% Fore. Int..

Input Arguments

collapse all

Conditional variance model without any unknown parameters, specified as agarch,egarch, orgjrmodel object.

Mdlcannot contain any properties that haveNaNvalue.

Sample path length, specified as a positive integer. That is, the number of random observations to generate per output path.VandYnumObsrows.

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Example:'numPaths',1000,'E0',[0.5; 0.5]specifies to generate1000sample paths and to use[0.5; 0.5]as presample innovations per path.

Number of sample paths to generate, specified as the comma-separated pair consisting of'NumPaths'and a positive integer.VandYNumPathscolumns.

Example:'NumPaths',1000

Data Types:double

Presample innovations, specified as the comma-separated pair consisting of'E0'and a numeric column vector or matrix. The presample innovations provide initial values for the innovations process of the conditional variance modelMdl. The presample innovations derive from a distribution with mean 0.

E0must contain at leastMdl.Qelements or rows. IfE0contains extra rows,simulateuses the latestMdl.Qonly.

The last element or row contains the latest presample innovation.

  • IfE0is a column vector, it represents a single path of the underlying innovation series.simulateappliesE0to each simulated path.

  • IfE0is a matrix, then each column represents a presample path of the underlying innovation series.E0必须至少有NumPathscolumns. IfE0has more columns than necessary,simulateuses the firstNumPathscolumns only.

The defaults are:

  • For GARCH(P,Q) and GJR(P,Q) models,simulatesets any necessary presample innovations to an independent sequence of disturbances with mean zero and standard deviation equal to the unconditional standard deviation of the conditional variance process.

  • For EGARCH(P,Q) models,simulatesets any necessary presample innovations to an independent sequence of disturbances with mean zero and variance equal to the exponentiated unconditional mean of the logarithm of the EGARCH variance process.

Example:'E0',[0.5; 0.5]

Positive presample conditional variance paths, specified as a numeric vector or matrix.V0provides initial values for the conditional variances in the model.

  • IfV0is a column vector, thensimulateapplies it to each output path.

  • IfV0is a matrix, then it must have at leastNumPathscolumns. IfV0has more columns than necessary,simulateuses the firstNumPathscolumns only.

  • For GARCH(P,Q) and GJR(P,Q) models:

    • V0必须至少有Mdl.Prows to initialize the variance equation.

    • By default,simulatesets any necessary presample variances to the unconditional variance of the conditional variance process.

  • For EGARCH(P,Q) models,simulate:

    • V0必须至少有max(Mdl.P,Mdl.Q)rows to initialize the variance equation.

    • By default,simulatesets any necessary presample variances to the exponentiated unconditional mean of the logarithm of the EGARCH variance process.

If the number of rows inV0exceeds the number necessary, thensimulateuses the latest, required number of observations only. The last element or row contains the latest observation.

Example:'V0',[1; 0.5]

Data Types:double

Notes

  • IfE0andV0are column vectors,simulateapplies them to every column of the outputsVandY. This application allows simulated paths to share a common starting point for Monte Carlo simulation of forecasts and forecast error distributions.

  • NaNs indicate missing values.simulateremoves missing values. The software merges the presample data (E0andV0), and then uses list-wise deletion to remove any rows containing at least oneNaN. RemovingNaNs in the data reduces the sample size. RemovingNaNscan also create irregular time series.

  • simulateassumes that you synchronize presample data such that the latest observation of each presample series occurs simultaneously.

Output Arguments

collapse all

Simulated conditional variance paths of the mean-zero innovations associated withY, returned as a numeric column vector or matrix.

Vis anumObs-by-NumPathsmatrix, in which each column corresponds to a simulated conditional variance path. Rows ofVare periods corresponding to the periodicity ofMdl.

Simulated response paths, returned as a numeric column vector or matrix.Yusually represents a mean-zero, heteroscedastic time series of innovations with conditional variances given inV(a continuation of the presample innovation seriesE0).

Ycan also represent a time series of mean-zero, heteroscedastic innovations plus an offset. IfMdlincludes an offset, thensimulateadds the offset to the underlying mean-zero, heteroscedastic innovations so thatYrepresents a time series of offset-adjusted innovations.

Yis anumObs-by-NumPathsmatrix, in which each column corresponds to a simulated response path. Rows ofYare periods corresponding to the periodicity ofMdl.

References

[1] Bollerslev, T. “Generalized Autoregressive Conditional Heteroskedasticity.”Journal of Econometrics. Vol. 31, 1986, pp. 307–327.

[2] Bollerslev, T. “A Conditionally Heteroskedastic Time Series Model for Speculative Prices and Rates of Return.”The Review of Economics and Statistics. Vol. 69, 1987, pp. 542–547.

[3] Box, G. E. P., G. M. Jenkins, and G. C. Reinsel.Time Series Analysis: Forecasting and Control. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.

[4] Enders, W.Applied Econometric Time Series. Hoboken, NJ: John Wiley & Sons, 1995.

[5] Engle, R. F. “Autoregressive Conditional Heteroskedasticity with Estimates of the Variance of United Kingdom Inflation.”Econometrica. Vol. 50, 1982, pp. 987–1007.

[6] Glosten l R, R . Jagannathan和d . e . Runkle. “On the Relation between the Expected Value and the Volatility of the Nominal Excess Return on Stocks.”The Journal of Finance. Vol. 48, No. 5, 1993, pp. 1779–1801.

[7] Hamilton, J. D.Time Series Analysis. Princeton, NJ: Princeton University Press, 1994.

[8] Nelson, D. B. “Conditional Heteroskedasticity in Asset Returns: A New Approach.”Econometrica. Vol. 59, 1991, pp. 347–370.

Introduced in R2012a