Commit 329606cf authored by Stéphane Adjemian's avatar Stéphane Adjemian

Added option for initialisation of the one sided hp filter.

Can initialise the trend in the one sided HP filter with the trend
estimated with the standard HP filter.
parent 7b98947c
function o = onesidedhpcycle(o, lambda) % --*-- Unitary tests --*-- function o = onesidedhpcycle(o, lambda, init) % --*-- Unitary tests --*--
% Extracts the cycle component from a dseries object using the one sided HP filter. % Extracts the cycle component from a dseries object using the one sided HP filter.
% %
...@@ -28,14 +28,23 @@ function o = onesidedhpcycle(o, lambda) % --*-- Unitary tests --*-- ...@@ -28,14 +28,23 @@ function o = onesidedhpcycle(o, lambda) % --*-- Unitary tests --*--
if nargin>1 if nargin>1
if lambda<=0 if lambda<=0
error(['dseries::onesidedhptrend: Lambda must be a positive integer!']) error(['dseries::onesidedhpcycle: Lambda must be a positive integer!'])
end
if nargin>2
if ~isequal(init, 'hpfilter')
error('dseries::onesidedhpcycle: Unknown option!')
end
end end
else else
lambda = []; lambda = [];
end end
o = copy(o); o = copy(o);
o.onesidedhpcycle_(lambda); if nargin<3
o.onesidedhpcycle_(lambda);
else
o.onesidedhpcycle_(lambda, init);
end
return return
......
function o = onesidedhpcycle_(o, lambda) % --*-- Unitary tests --*-- function o = onesidedhpcycle_(o, lambda, init) % --*-- Unitary tests --*--
% Extracts the cycle component from a dseries object using a one sided HP filter. % Extracts the cycle component from a dseries object using a one sided HP filter.
% %
...@@ -28,7 +28,12 @@ function o = onesidedhpcycle_(o, lambda) % --*-- Unitary tests --*-- ...@@ -28,7 +28,12 @@ function o = onesidedhpcycle_(o, lambda) % --*-- Unitary tests --*--
if nargin>1 if nargin>1
if lambda<=0 if lambda<=0
error(['dseries::onesidedhpcycle: Lambda must be a positive integer!']) error('dseries::onesidedhpcycle: Lambda must be a positive integer!')
end
if nargin>2
if ~isequal(init, 'hpfilter')
error('dseries::onesidedhpcycle: Unknown option!')
end
end end
else else
lambda = []; lambda = [];
...@@ -37,20 +42,42 @@ end ...@@ -37,20 +42,42 @@ end
for i=1:vobs(o) for i=1:vobs(o)
if isempty(o.ops{i}) if isempty(o.ops{i})
if isempty(lambda) if isempty(lambda)
o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.name{i})}; if nargin>2
o.ops(i) = {sprintf('onesidedhpcycle(%s, [], ''%s'')', o.name{i}, init)};
else
o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.name{i})};
end
else else
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.name{i}, num2str(lambda))}; if nargin>2
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s, ''%s'')', o.name{i}, num2str(lambda), init)};
else
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.name{i}, num2str(lambda))};
end
end end
else else
if isempty(lambda) if isempty(lambda)
o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.ops{i})}; if nargin>2
o.ops(i) = {sprintf('onesidedhpcycle(%s, [], ''%s'')', o.ops{i}, init)};
else
o.ops(i) = {sprintf('onesidedhpcycle(%s, [])', o.ops{i})};
end
else else
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.ops{i}, num2str(lambda))}; if nargin>2
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s, ''%s'')', o.ops{i}, num2str(lambda), init)};
else
o.ops(i) = {sprintf('onesidedhpcycle(%s, %s)', o.ops{i}, num2str(lambda))};
end
end end
end end
end end
[~, o.data] = one_sided_hp_filter(o.data, lambda); if nargin>2
trend = o.hptrend(lambda);
x0 = trend.data(1:2,:);
[~, o.data] = one_sided_hp_filter(o.data, lambda, x0);
else
[~, o.data] = one_sided_hp_filter(o.data, lambda);
end
return return
......
function o = onesidedhptrend(o, lambda) % --*-- Unitary tests --*-- function o = onesidedhptrend(o, lambda, init) % --*-- Unitary tests --*--
% Extracts the trend component from a dseries object using the one sided HP filter. % Extracts the trend component from a dseries object using the one sided HP filter.
% %
...@@ -30,12 +30,21 @@ if nargin>1 ...@@ -30,12 +30,21 @@ if nargin>1
if lambda<=0 if lambda<=0
error(['dseries::onesidedhptrend: Lambda must be a positive integer!']) error(['dseries::onesidedhptrend: Lambda must be a positive integer!'])
end end
if nargin>2
if ~isequal(init, 'hpfilter')
error('dseries::onesidedhpcycle: Unknown option!')
end
end
else else
lambda = []; lambda = [];
end end
o = copy(o); o = copy(o);
o.onesidedhptrend_(lambda); if nargin<3
o.onesidedhptrend_(lambda);
else
o.onesidedhptrend_(lambda, init);
end
return return
......
...@@ -30,6 +30,11 @@ if nargin>1 ...@@ -30,6 +30,11 @@ if nargin>1
if lambda<=0 if lambda<=0
error(['dseries::onesidedhptrend: Lambda must be a positive integer!']) error(['dseries::onesidedhptrend: Lambda must be a positive integer!'])
end end
if nargin>2
if ~isequal(init, 'hpfilter')
error('dseries::onesidedhptrend: Unknown option!')
end
end
else else
lambda = []; lambda = [];
end end
...@@ -37,20 +42,42 @@ end ...@@ -37,20 +42,42 @@ end
for i=1:vobs(o) for i=1:vobs(o)
if isempty(o.ops{i}) if isempty(o.ops{i})
if isempty(lambda) if isempty(lambda)
o.ops(i) = {sprintf('onesidedhptrend(%s, [])', o.name{i})}; if nargin>2
o.ops(i) = {sprintf('onesidedhptrend(%s, [], ''%s'')', o.name{i}, init)};
else
o.ops(i) = {sprintf('onesidedhptrend(%s, [])', o.name{i})};
end
else else
o.ops(i) = {sprintf('onesidedhptrend(%s, %s)', o.name{i}, num2str(lambda))}; if nargin>2
o.ops(i) = {sprintf('onesidedhptrend(%s, %s, ''%s'')', o.name{i}, num2str(lambda), init)};
else
o.ops(i) = {sprintf('onesidedhptrend(%s, %s)', o.name{i}, num2str(lambda))};
end
end end
else else
if isempty(lambda) if isempty(lambda)
o.ops(i) = {sprintf('onesidedhptrend(%s, [])', o.ops{i})}; if nargin>2
o.ops(i) = {sprintf('onesidedhptrend(%s, [], ''%s'')', o.ops{i}, init)};
else
o.ops(i) = {sprintf('onesidedhptrend(%s, [])', o.ops{i})};
end
else else
o.ops(i) = {sprintf('onesidedhptrend(%s, %s)', o.ops{i}, num2str(lambda))}; if nargin>2
o.ops(i) = {sprintf('onesidedhptrend(%s, %s, ''%s'')', o.ops{i}, num2str(lambda), init)};
else
o.ops(i) = {sprintf('onesidedhptrend(%s, %s)', o.ops{i}, num2str(lambda))};
end
end end
end end
end end
o.data = one_sided_hp_filter(o.data, lambda); if nargin>2
trend = o.hptrend(lambda);
x0 = trend.data(1:2,:);
o.data = one_sided_hp_filter(o.data, lambda, x0);
else
o.data = one_sided_hp_filter(o.data, lambda);
end
return return
......
...@@ -90,7 +90,7 @@ switch S(1).type ...@@ -90,7 +90,7 @@ switch S(1).type
case 'freq' case 'freq'
% Returns an integer characterizing the data frequency (1, 4, 12 or 52) % Returns an integer characterizing the data frequency (1, 4, 12 or 52)
B = A.dates.freq; B = A.dates.freq;
case {'lag','lag_','lead','lead_','hptrend','hptrend_','hpcycle','hpcycle_','onesidedhptrend','onesidedhptrend_','onesidedhpcycle','onesidedhpcycle_','chain','chain_','detrend','detrend_','exist','mean','std','center','center_'} % Methods with less than two arguments. case {'lag','lag_','lead','lead_','hptrend','hptrend_','hpcycle','hpcycle_','chain','chain_','detrend','detrend_','exist','mean','std','center','center_'} % Methods with less than two arguments.
if length(S)>1 && isequal(S(2).type,'()') if length(S)>1 && isequal(S(2).type,'()')
if isempty(S(2).subs) if isempty(S(2).subs)
B = feval(S(1).subs,A); B = feval(S(1).subs,A);
...@@ -105,7 +105,7 @@ switch S(1).type ...@@ -105,7 +105,7 @@ switch S(1).type
else else
B = feval(S(1).subs,A); B = feval(S(1).subs,A);
end end
case {'cumsum','cumsum_','insert','pop','pop_','cumprod','cumprod_','remove','remove_'} % Methods with less than three argument. case {'cumsum','cumsum_','insert','pop','pop_','cumprod','cumprod_','remove','remove_','onesidedhptrend','onesidedhptrend_','onesidedhpcycle','onesidedhpcycle_'} % Methods with less than three argument.
if length(S)>1 && isequal(S(2).type,'()') if length(S)>1 && isequal(S(2).type,'()')
if isempty(S(2).subs) if isempty(S(2).subs)
B = feval(S(1).subs,A); B = feval(S(1).subs,A);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment