Home > matlab > multivariate_sample_autocovariance.m

multivariate_sample_autocovariance

PURPOSE ^

Computes the autocovariance function of multivariate time series.

SYNOPSIS ^

function autocov = multivariate_sample_autocovariance(data,q)

DESCRIPTION ^

 Computes the autocovariance function of multivariate time series.
 

 INPUTS 
   data            [double]       T*m matrix of data.
   q               [integer]      Order of the autocovariance function. 
    
 OUTPUTS 
   autocov         [double]       m*m*(q+1) array, autocovariance function.

 SPECIAL REQUIREMENTS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function autocov = multivariate_sample_autocovariance(data,q)
0002 % Computes the autocovariance function of multivariate time series.
0003 %
0004 %
0005 % INPUTS
0006 %   data            [double]       T*m matrix of data.
0007 %   q               [integer]      Order of the autocovariance function.
0008 %
0009 % OUTPUTS
0010 %   autocov         [double]       m*m*(q+1) array, autocovariance function.
0011 %
0012 % SPECIAL REQUIREMENTS
0013 
0014 % Copyright (C) 2009 Dynare Team
0015 %
0016 % This file is part of Dynare.
0017 %
0018 % Dynare is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % Dynare is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 [T,m] = size(data);
0032 
0033 autocov = zeros(m,m,q+1);
0034 
0035 demeaned_data = data - repmat(mean(data),T,1);
0036 
0037 for i = 0:q
0038     autocov(:,:,i+1) = transpose(demeaned_data(1:T-i,:))*demeaned_data(i+1:T,:);
0039 end
0040 
0041 autocov = autocov/T;

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005