2009-12-31 11:20:32 +01:00
|
|
|
function sigma = long_run_variance(data,band)
|
|
|
|
% Returns the long run variance of data, a T*m matrix.
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% data [double] T*m matrix, where T is the number of observations and m the number of variables.
|
|
|
|
% band [double] scalar, the bandwidth parameter.
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% sigma [double] m*m matrix.
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2009-2010 Dynare Team
|
2009-12-31 11:20:32 +01: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/>.
|
2009-12-31 11:20:32 +01:00
|
|
|
|
|
|
|
verbose = 1;
|
|
|
|
|
|
|
|
if nargin<2
|
|
|
|
[T,m] = size(data);
|
|
|
|
band = ceil(T^(1/4));
|
|
|
|
if verbose
|
|
|
|
disp(['Bandwidth parameter is equal to ' num2str(band) '.'])
|
|
|
|
end
|
|
|
|
end
|
2010-01-05 11:46:10 +01:00
|
|
|
|
2009-12-31 11:20:32 +01:00
|
|
|
gamma = multivariate_sample_autocovariance(data,band);
|
|
|
|
sigma = gamma(:,:,1);
|
|
|
|
for i=1:band
|
|
|
|
sigma = sigma + bartlett(i,band)*(gamma(:,:,i+1)+transpose(gamma(:,:,i+1)));
|
|
|
|
end
|
|
|
|
|
|
|
|
function w = bartlett(i,n)
|
2010-01-05 11:46:10 +01:00
|
|
|
w = 1 - i / (n+1);
|