www.gusucode.com > econ 案例源码程序 matlab代码 > econ/InferConditionalVariances1Example.m
%% Infer Conditional Variances % Infer the conditional variances from an AR(1) and GARCH(1,1) composite model. % Copyright 2015 The MathWorks, Inc. %% % Specify an AR(1) model using known parameters. Set the variance equal % to a |garch| model. Mdl = arima('AR',{0.8,-0.3},'Constant',0); MdlVar = garch('Constant',0.0002,'GARCH',0.6,... 'ARCH',0.2); Mdl.Variance = MdlVar; %% % Simulate response data with 102 observations. rng 'default'; Y = simulate(Mdl,102); %% % Infer conditional variances for the last 100 observations without using % presample data. [Ew,Vw] = infer(Mdl,Y(3:end)); %% % Infer conditional variances for the last 100 observations using the first % two observations as presample data. [E,V] = infer(Mdl,Y(3:end),'Y0',Y(1:2)); %% % Plot the two sets of conditional variances for comparison. Examine the % first few observations to see the slight difference between the series % at the beginning. figure; subplot(2,1,1); plot(Vw,'r','LineWidth',2); hold on; plot(V); legend('Without Presample','With Presample'); title 'Inferred Conditional Variances'; hold off subplot(2,1,2); plot(Vw(1:5),'r','LineWidth',2); hold on; plot(V(1:5)); legend('Without Presample','With Presample'); title 'Beginning of Series'; hold off