%% "A property of the Hodrick Prescott filter and its application," Neslihan Sakarya and Robert M. de Jong (2018) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% This file allows you to compare Theorem 1 representation of the HP filter with the HP filter code written by Ivailo Izvorski, the Department of Economics, Yale University. % The link for the code: https://dge.repec.org/codes/izvorski/hpfilter.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% After you run the program, the following results are displayed in the command window: % (2)A (Tx3) table that allows you to compare 3 series (in order) % (i) The cyclical component (c) of a process (y) that we generate. The cyclical component is calculated by using Izvorski's code; [labeled in the table as "c series"] % (ii) The cyclical component of y that is calculated by using Theorem 1 of Sakarya and de Jong (2018) [labeled in the table as "c1 series"] % (iii) The difference between the two cyclical components [labeled in the table as "Difference"] % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Explanation of the codes in this file: % [1] In this program, we first generate a process denoted by y. The HP filter % is going to be applied to y. We offer a selection of y processes such as % a standard normal variable, a linear trend series, a quadratic trend % series, and a deterministic exponential trend series. % % [2] In the next step, we calculate the cyclical component of y, which is % denoted as c. The calculation of c is based on the HP filter code written by Ivailo Izvorski, the Department of Economics, Yale University. % The link for the code: https://dge.repec.org/codes/izvorski/hpfilter.m % % [3] To verify the result of Theorem 1, we create a (Tx1) vector that is denoted as tilde_y. Note that tilde_y corresponds to {\tilde{y}_{Tt}} series in Theorem 1 of Sakarya and de Jong (2018). % % [4] We calculate the trend of tilde_y that is denoted as tilde_tau. Note % that tilde_tau corresponds to % \hat{\tau}_{Tt}(\tilde{y}_{T1},\tilde{y}_{T2},...,\tilde{y}_{TT}) series in Theorem 1 of Sakarya and de Jong (2018). % % [5] Lastly, we calculate the cyclical component of y by using the result of Theorem 1. The cyclical component that is calculated by using the representation in Theorem 1 is denoted as c1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all; close all; clc; T=10; %The number of observations lmb=1600; %The smoothing parameter value %% [1]: Generate a series called y y=randn(T,1); %y is a standard normal random variable. % y=ones(T,1); %y is a linear trend. % y=cumsum(y); % y=ones(T,1); %y is a quadratic trend. % y=cumsum(y).^2; % y=zeros(T,1); %y is a deterministic exponential trend. % % for t=1:T; % y(t)=exp(t); % end %% [2]: Calculate the cyclical component by using the HP filter code written by Ivailo Izvorski [tau,c]=hpfilter(y,lmb); %% [3]: Generate \tilde{y}_{Tt} series by using the formula in Theorem 1 of Sakarya and de Jong (2018) tilde_y=zeros(T,1); for t=3:T-2; tilde_y(t)=y(t+2)-4*y(t+1)+6*y(t)-4*y(t-1)+y(t-2); end tilde_y(1)=y(3)-2*y(2)+y(1); tilde_y(2)=(y(4)-2*y(3)+y(2))-2*(y(3)-2*y(2)+y(1)); tilde_y(T-1)=(y(T-1)-2*y(T-2)+y(T-3))-2*(y(T)-2*y(T-1)+y(T-2)); tilde_y(T)=y(T)-2*y(T-1)+y(T-2); %% [4]: Calculate the trend of \tilde{y}_{Tt} series [tilde_tau,tilde_c]=hpfilter(tilde_y,lmb); %% [5]: Calculate the cyclical component of y by using the representation in Theorem 1 of Sakarya and de Jong (2018) c1=lmb*tilde_tau; %% Result: R=[c, c1, c-c1]; format long disp(' c series c1 series Difference') disp(R)