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

    %% Simulate GARCH Model Observations and Conditional Variances
% Simulate conditional variance or response paths from a
% fully specified |garch| model object.  That is, simulate from an
% estimated |garch| model or a known |garch| model in which you specify all
% parameter values.  This example follows from <docid:econ_ug.buofsf_-1>.
%%
% Load the |Data_Danish| data set.

% Copyright 2015 The MathWorks, Inc.

load Data_Danish;
nr = DataTable.RN;
%%
% Create a GARCH(1,1) model with an unknown conditional mean offset. Fit the
% model to the annual nominal return series.
Mdl = garch('GARCHLags',1,'ARCHLags',1,'Offset',NaN);
EstMdl = estimate(Mdl,nr);
%%
% Simulate 100 paths of conditional variances and responses for each period
% from the estimated GARCH model.
numObs = numel(nr); % Sample size (T)
numPaths = 100;     % Number of paths to simulate
rng(1);             % For reproducibility
[VSim,YSim] = simulate(EstMdl,numObs,'NumPaths',numPaths);
%%
% |VSim| and |YSim| are |T|-by- |numPaths| matrices.  Rows correspond to
% a sample period, and columns correspond to a simulated path.
%%
% Plot the average and the 97.5% and 2.5% percentiles of the simulated
% paths. Compare the simulation statistics to the original data.
VSimBar = mean(VSim,2);
VSimCI = quantile(VSim,[0.025 0.975],2);
YSimBar = mean(YSim,2);
YSimCI = quantile(YSim,[0.025 0.975],2);

figure;
subplot(2,1,1);
h1 = plot(dates,VSim,'Color',0.8*ones(1,3));
hold on;
h2 = plot(dates,VSimBar,'k--','LineWidth',2);
h3 = plot(dates,VSimCI,'r--','LineWidth',2);
hold off;
title('Simulated Conditional Variances');
ylabel('Cond. var.');
xlabel('Year');

subplot(2,1,2);
h1 = plot(dates,YSim,'Color',0.8*ones(1,3));
hold on;
h2 = plot(dates,YSimBar,'k--','LineWidth',2);
h3 = plot(dates,YSimCI,'r--','LineWidth',2);
hold off;
title('Simulated Nominal Returns');
ylabel('Nominal return (%)');
xlabel('Year');
legend([h1(1) h2 h3(1)],{'Simulated path' 'Mean' 'Confidence bounds'},...
    'FontSize',7,'Location','NorthWest');