www.gusucode.com > econ 案例源码程序 matlab代码 > econ/SimulateConditionalVariancesandResponsesGarchSimExample.m

    %% Simulate GARCH Model Conditional Variances and Responses  
% Simulate conditional variance and response paths from a GARCH(1,1) model.   

% Copyright 2015 The MathWorks, Inc.


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

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