www.gusucode.com > econ 案例源码程序 matlab代码 > econ/TestAndPlotTheAutocorrelationFunctionExample.m
%% Plot the Autocorrelation Function of a Time Series % Specify the MA(2) model: % % $$y_t = \varepsilon_t-0.5\varepsilon_{t-1}+0.4\varepsilon_{t-2},$$ % % where $\varepsilon_t$ is Gaussian with mean 0 and variance 1. % Copyright 2015 The MathWorks, Inc. rng(1); % For reproducibility Mdl = arima('MA',{-0.5 0.4},'Constant',0,'Variance',1) %% % Simulate 1000 observations from |Mdl|. y = simulate(Mdl,1000); %% % Compute the ACF. [ACF,lags,bounds] = autocorr(y,[],2); bounds %% % |[]| tells the software to return the default number of lags (20). % |numMA = 2| indicates that the ACF is effectively 0 after the second lag. % |bounds| displays (-0.0843, 0.0843), which are the upper and lower confidence % bounds. %% % Plot the ACF. autocorr(y) %% % The ACF cuts off after the second lag. This behavior indicataes an % MA(2) process.