2016-10-03 21:30:02 +02:00
|
|
|
function acf = dyn_autocorr(y, ar)
|
|
|
|
% function acf = dyn_autocorr(y, ar)
|
2016-05-14 13:23:01 +02:00
|
|
|
% autocorrelation function of y
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% y: time series
|
|
|
|
% ar: # of lags
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% acf: autocorrelation for lags 1 to ar
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2015-16 Dynare Team
|
2016-05-14 13:23:01 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-14 13:23:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
y=y(:);
|
|
|
|
acf = NaN(ar+1,1);
|
|
|
|
acf(1)=1;
|
|
|
|
m = mean(y);
|
|
|
|
sd = std(y,1);
|
2017-05-16 12:42:01 +02:00
|
|
|
for i=1:ar
|
2016-05-14 13:23:01 +02:00
|
|
|
acf(i+1) = (y(i+1:end)-m)'*(y(1:end-i)-m)./((size(y,1))*sd^2);
|
|
|
|
end
|