1function sigma = long_run_variance(data,band)
2% Returns the long run variance of data, a T*m matrix.
3%
4% INPUTS
5%    data      [double]  T*m matrix, where T is the number of observations and m the number of variables.
6%    band      [double]  scalar, the bandwidth parameter.
7%
8% OUTPUTS
9%    sigma     [double]  m*m matrix.
10%
11% SPECIAL REQUIREMENTS
12%    none
13
14% Copyright (C) 2009-2010 Dynare Team
15%
16% This file is part of Dynare.
17%
18% Dynare is free software: you can redistribute it and/or modify
19% it under the terms of the GNU General Public License as published by
20% the Free Software Foundation, either version 3 of the License, or
21% (at your option) any later version.
22%
23% Dynare is distributed in the hope that it will be useful,
24% but WITHOUT ANY WARRANTY; without even the implied warranty of
25% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26% GNU General Public License for more details.
27%
28% You should have received a copy of the GNU General Public License
29% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
30
31verbose = 1;
32
33if nargin<2
34    [T,m] = size(data);
35    band = ceil(T^(1/4));
36    if verbose
37        disp(['Bandwidth parameter is equal to ' num2str(band) '.'])
38    end
39end
40
41gamma = multivariate_sample_autocovariance(data,band);
42sigma = gamma(:,:,1);
43for i=1:band
44    sigma = sigma + bartlett(i,band)*(gamma(:,:,i+1)+transpose(gamma(:,:,i+1)));
45end
46
47function w = bartlett(i,n)
48w = 1 - i / (n+1);