%% Simulate EGARCH Model Conditional Variances and Responses
% 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.

rng default; % 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)')

% 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')

% The intervals are asymmetric due to positivity constraints on the conditional variance.
% Copyright 2015 The MathWorks, Inc.