Hodrick-Prescott filter for trend and cyclical components
T = hpfilter(...)
[T,C] = hpfilter(...)
hpfilter(S) uses a Hodrick-Prescott filter and a default smoothing parameter of 1600 to separate the columns of S into trend and cyclical components. S is an m-by-n matrix with m samples from n time series. A plot displays each time series together with its trend (the time series with the cyclic component removed).
hpfilter(S,smoothing) applies the smoothing parameter smoothing to the columns of S. If smoothing is a scalar, hpfilter applies it to all columns. If S has n columns and smoothing is a conformable vector (n-by-1 or 1-by-n), hpfilter applies the vector components of smoothing to the corresponding columns of S.
If the smoothing parameter is 0, no smoothing takes place. As the smoothing parameter increases in value, the smoothed series becomes more linear. A smoothing parameter of Inf produces a linear trend component.
Appropriate values of the smoothing parameter depend upon the periodicity of the data. The following reference suggests the following values:
Yearly — 100
Quarterly — 1600
Monthly — 14400
T = hpfilter(...) returns the trend components of the columns of S in T, without plotting.
[T,C] = hpfilter(...) returns the cyclical components of the columns of S in C, without plotting.
Plot the cyclical component of the U.S. post-WWII seasonally-adjusted real GNP. In hpfilter, specify that smoothing is 1600, which is appropriate for quarterly data.
load Data_GNP gnpDate = dates; realgnp = DataTable.GNPR; [~,c] = hpfilter(realgnp,1600); plot(gnpDate,c) axis tight
The Hodrick-Prescott filter separates a time series yt into a trend component Tt and a cyclical component Ct such that yt = Tt + Ct. It is equivalent to a cubic spline smoother, with the smoothed portion in Tt.
The objective function for the filter has the form
where m is the number of samples and λ is the smoothing parameter. The programming problem is to minimize the objective over all T1, ..., Tm. The first sum minimizes the difference between the time series and its trend component (which is its cyclical component). The second sum minimizes the second-order difference of the trend component (which is analogous to minimization of the second derivative of the trend component).