1function o = onesidedhpcycle_(o, lambda, init) % --*-- Unitary tests --*-- 2 3% Extracts the cycle component from a dseries object using a one sided HP filter. 4% 5% INPUTS 6% - o [dseries] Original time series. 7% - lambda [double] scalar, trend smoothness parameter. 8% 9% OUTPUTS 10% - o [dseries] Cycle component of the original time series. 11 12% Copyright (C) 2017 Dynare Team 13% 14% This file is part of Dynare. 15% 16% Dynare is free software: you can redistribute it and/or modify 17% it under the terms of the GNU General Public License as published by 18% the Free Software Foundation, either version 3 of the License, or 19% (at your option) any later version. 20% 21% Dynare is distributed in the hope that it will be useful, 22% but WITHOUT ANY WARRANTY; without even the implied warranty of 23% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24% GNU General Public License for more details. 25% 26% You should have received a copy of the GNU General Public License 27% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 28 29if nargin>1 30 if lambda<=0 31 error('dseries::onesidedhpcycle: Lambda must be a positive integer!') 32 end 33 if nargin>2 34 if ~isequal(init, 'hpfilter') 35 error('dseries::onesidedhpcycle: Unknown option!') 36 end 37 end 38else 39 lambda = []; 40end 41 42for i=1:vobs(o) 43 if isempty(o.ops{i}) 44 if isempty(lambda) 45 if nargin>2 46 o.ops(i) = {sprintf('onesidedhpcycle(%s, [], ''%s'')', o.name{i}, init)}; 47 else 48 o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.name{i})}; 49 end 50 else 51 if nargin>2 52 o.ops(i) = {sprintf('onesidedhpcycle(%s, %s, ''%s'')', o.name{i}, num2str(lambda), init)}; 53 else 54 o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.name{i}, num2str(lambda))}; 55 end 56 end 57 else 58 if isempty(lambda) 59 if nargin>2 60 o.ops(i) = {sprintf('onesidedhpcycle(%s, [], ''%s'')', o.ops{i}, init)}; 61 else 62 o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.ops{i})}; 63 end 64 else 65 if nargin>2 66 o.ops(i) = {sprintf('onesidedhpcycle(%s, %s, ''%s'')', o.ops{i}, num2str(lambda), init)}; 67 else 68 o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.ops{i}, num2str(lambda))}; 69 end 70 end 71 end 72end 73 74if nargin>2 75 trend = o.hptrend(lambda); 76 x0 = trend.data(1:2,:); 77 [~, o.data] = one_sided_hp_filter(o.data, lambda, x0); 78else 79 [~, o.data] = one_sided_hp_filter(o.data, lambda); 80end 81 82return 83 84%@test:1 85e = .2*randn(200,1); 86u = randn(200,1); 87stochastic_trend = cumsum(e); 88deterministic_trend = .1*transpose(1:200); 89x = zeros(200,1); 90for i=2:200 91 x(i) = .75*x(i-1) + e(i); 92end 93y = x + stochastic_trend + deterministic_trend; 94 95try 96 ts0 = dseries(y,'1950Q1'); 97 ts0.onesidedhpcycle_(1600); 98 t(1) = 1; 99catch 100 t(1) = 0; 101end 102 103T = all(t); 104%@eof:1 105 106%@test:2 107e = .2*randn(200,2); 108u = randn(200,2); 109stochastic_trends = cumsum(e); 110deterministic_trends = transpose(1:200)*[.1, -.2]; 111x = zeros(200,2); 112for i=2:200 113 x(i, 1) = .75*x(i-1, 1) + e(i, 1); 114 x(i, 2) = -.10*x(i-1, 2) + e(i, 2); 115end 116y = x + stochastic_trends + deterministic_trends; 117 118try 119 ts0 = dseries(y,'1950Q1'); 120 ts0.onesidedhpcycle_(1600); 121 t(1) = 1; 122catch 123 t(1) = 0; 124end 125 126T = all(t); 127%@eof:2