-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUChp.m
28 lines (28 loc) · 815 Bytes
/
UChp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function cycle = UChp(y, frequency, lambda)
% UChp - Hodrick-Prescott filter estimation
%
% UChp returns the cycle extracted by the HP filter
%
% cycle = UChp(y, frequency, lambda)
%
% Inputs:
% y: a time series.
% frequency: fundamental period, number of observations per year.
% lambda: smoothing constant for estimation (1600 by default)
% Output:
% cycle: HP estimated cycle
%
% Author: Diego J. Pedregal
%
if (nargin < 3)
lambda = 1600;
end
m = UCsetup(y, frequency, 'model', 'irw/none/arma(0,0)');
m.hidden.truePar = [log(1 / lambda) / 2; 0];
m = UCcomponents(m);
if exist('OCTAVE_VERSION', 'builtin')
cycle = y - m.comp(1 : length(y), 1);
else
cycle = y - table2array(m.comp(1 : length(y), 1));
end
end