


HP filters a collection of time series.
INPUTS
y [double] T*n matrix of data (n is the number of variables)
s [double] scalar, smoothing parameter.
OUTPUTS
hptrend [double] T*n matrix, trend component of y.
hpcycle [double] T*n matrix, cycle component of y.
SPECIAL REQUIREMENTS

0001 function [hptrend,hpcycle] = sample_hp_filter(y,s) 0002 % HP filters a collection of time series. 0003 % 0004 % INPUTS 0005 % y [double] T*n matrix of data (n is the number of variables) 0006 % s [double] scalar, smoothing parameter. 0007 % 0008 % OUTPUTS 0009 % hptrend [double] T*n matrix, trend component of y. 0010 % hpcycle [double] T*n matrix, cycle component of y. 0011 % 0012 % SPECIAL REQUIREMENTS 0013 % 0014 0015 % Copyright (C) 2010-2011 Dynare Team 0016 % 0017 % This file is part of Dynare. 0018 % 0019 % Dynare is free software: you can redistribute it and/or modify 0020 % it under the terms of the GNU General Public License as published by 0021 % the Free Software Foundation, either version 3 of the License, or 0022 % (at your option) any later version. 0023 % 0024 % Dynare is distributed in the hope that it will be useful, 0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0027 % GNU General Public License for more details. 0028 % 0029 % You should have received a copy of the GNU General Public License 0030 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0031 0032 [T,n] = size(y); 0033 0034 if nargin<2 0035 s = 1600; 0036 end 0037 0038 D = spdiags(repmat([s, -4.0*s, (1 + 6.0*s), -4.0*s, s], T, 1), -2:2, T, T);% Sparse matrix. 0039 D(1,1) = 1.0+s; D(T,T) = D(1,1); 0040 D(1,2) = -2.0*s; D(2,1) = D(1,2); D(T-1,T) = D(1,2); D(T,T-1) = D(1,2); 0041 D(2,2) = 1.0+5.0*s; D(T-1,T-1) = D(2,2); 0042 0043 hptrend = D\y; 0044 hpcycle = y-hptrend;