%% Simulate and Filter
% This example illustrates the relationship between simulate and filter.
% Specify a GJR(1,1) model with Gaussian innovations.

Mdl = gjr('Constant',0.005,'GARCH',0.8,'ARCH',0.1,...
    'Leverage',0.05);

%
% Simulate the model via Monte Carlo simulation. Then, standardize the simulated innovations and filter.

rng(1); % For reproducibility
[v,e] = simulate(Mdl,100,'E0',0,'V0',0.05);
Z = e./sqrt(v);
[V,E] = filter(Mdl,Z,'Z0',0,'V0',0.05);

%
% Confirm that the outputs of simulate and filter are identical.

sum(abs(v - V))

% The logical value 1 confirms the two outputs are identical.
% Copyright 2015 The MathWorks, Inc.