This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Using the Hodrick-Prescott Filter to Reproduce Their Original Result

This example shows how to use the Hodrick-Prescott filter to decompose a time series.

The Hodrick-Prescott filter separates a time series into growth and cyclical components with

where is a time series, is the growth component of , and is the cyclical component of for .

The objective function for the Hodrick-Prescott filter has the form

with a smoothing parameter . The programming problem is to minimize the objective over all .

The conceptual basis for this programming problem is that the first sum minimizes the difference between the data and its growth component (which is the cyclical component) and the second sum minimizes the second-order difference of the growth component, which is analogous to minimization of the second derivative of the growth component.

Note that this filter is equivalent to a cubic spline smoother.

Use of the Hodrick-Prescott Filter to Analyze GNP Cyclicality

Using data similar to the data found in Hodrick and Prescott [1], plot the cyclical component of GNP. This result should coincide with the results in the paper. However, since the GNP data here and in the paper are both adjusted for seasonal variations with conversion from nominal to real values, differences can be expected due to differences in the sources for the pair of adjustments. Note that our data comes from the St. Louis Federal Reserve FRED database [2], which was downloaded with the Datafeed Toolbox™.

load Data_GNP

startdate = 1950;	% Date range is from 1947.0 to 2005.5 (quarterly)
enddate = 1979.25;	% Change these two lines to try alternative periods

startindex = find(dates == startdate);
endindex = find(dates == enddate);

gnpdates = dates(startindex:endindex);
gnpraw = log(DataTable.GNPR(startindex:endindex));

We run the filter for different smoothing parameters = 400, 1600, 6400, and . The infinite smoothing parameter just detrends the data.

[gnptrend4, gnpcycle4] = hpfilter(gnpraw,400);
[gnptrend16, gnpcycle16] = hpfilter(gnpraw,1600);
[gnptrend64, gnpcycle64] = hpfilter(gnpraw,6400);
[gnptrendinf, gnpcycleinf] = hpfilter(gnpraw,Inf);

Plot Cyclical GNP and Its Relationship with Long-Term Trend

The following code generates Figure 1 from Hodrick and Prescott [1].

hold all
plot(gnpdates,gnpcycleinf - gnpcycle16,'r');
title('\bfFigure 1 from Hodrick and Prescott');
ylabel('\bfGNP Growth');
legend('Cyclical GNP','Difference');
hold off

The blue line is the cyclical component with smoothing parameter 1600 and the red line is the difference with respect to the detrended cyclical component. The difference is smooth enough to suggest that the choice of smoothing parameter is appropriate.

Statistical Tests on Cyclical GNP

We will now reconstruct Table 1 from Hodrick and Prescott [1]. With the cyclical components, we compute standard deviations, autocorrelations for lags 1 to 10, and perform a Dickey-Fuller unit root test to assess non-stationarity. As in the article, we see that as lambda increases, standard deviations increase, autocorrelations increase over longer lags, and the unit root hypothesis is rejected for all but the detrended case. Together, these results imply that any of the cyclical series with finite smoothing is effectively stationary.

gnpacf4 = autocorr(gnpcycle4,10);
gnpacf16 = autocorr(gnpcycle16,10);
gnpacf64 = autocorr(gnpcycle64,10);
gnpacfinf = autocorr(gnpcycleinf,10);

WarnState = warning('off','econ:adftest:LeftTailStatTooSmall');

[H4, ~, gnptest4] = adftest(gnpcycle4,'model','ARD');
[H16, ~, gnptest16] = adftest(gnpcycle16,'model','ARD');
[H64, ~, gnptest64] = adftest(gnpcycle64,'model','ARD');
[Hinf, ~, gnptestinf] = adftest(gnpcycleinf,'model','ARD');


fprintf(1,'Table 1 from Hodrick and Prescott Reference\n');
Table 1 from Hodrick and Prescott Reference
fprintf(1,'  %10s  %s\n',' ','Smoothing Parameter');
              Smoothing Parameter
fprintf(1,'  %10s  %10s  %10s  %10s  %10s\n',' ','400','1600','6400','Infinity');
                     400        1600        6400    Infinity
fprintf(1,'  %-10s  %10.2f  %10.2f  %10.2f  %10.2f\n','Std. Dev.', ...
  Std. Dev.         1.52        1.75        2.06        3.11
fprintf(1,'  Autocorrelations\n');
for i=2:11
	fprintf(1,'  %10g  %10.2f  %10.2f  %10.2f  %10.2f\n',(i-1), ...
           1        0.74        0.78        0.82        0.92
           2        0.38        0.47        0.57        0.81
           3        0.05        0.17        0.33        0.70
           4       -0.21       -0.07        0.12        0.59
           5       -0.36       -0.24       -0.03        0.50
           6       -0.39       -0.30       -0.10        0.44
           7       -0.35       -0.31       -0.13        0.39
           8       -0.28       -0.29       -0.15        0.35
           9       -0.22       -0.26       -0.15        0.31
          10       -0.19       -0.25       -0.17        0.26
fprintf(1,'  %-10s  %10.2f  %10.2f  %10.2f  %10.2f\n','Unit Root', ...
  Unit Root        -4.35       -4.13       -3.79       -2.28
fprintf(1,'  %-10s  %10d  %10d  %10d  %10d\n','Reject H0',H4,H16,H64,Hinf);
  Reject H0            1           1           1           0


[1] Hodrick, Robert J, and Edward C. Prescott. “Postwar U.S. Business Cycles: An Empirical Investigation.” Journal of Money, Credit, and Banking. Vol. 29, No. 1, February 1997, pp. 1–16.

[2] U.S. Federal Reserve Economic Data (FRED), Federal Reserve Bank of St. Louis,

See Also

Related Topics

Was this topic helpful?