Hodrick-Prescott filter for trend and cyclical components
hpfilter( plots the data of the time series variables (columns) of
Y and their respective trend components computed by the Hodrick-Prescott Filter. The smoothing parameter is
1600, which is appropriate for quarterly periodicity.
hpfilter plots all time series and their respective trend components on the same axes.
Plot the cyclical component of the US post-WWII seasonally-adjusted real gross national poroduct (GNP). Specify
smoothing of 1600, which is appropriate for quarterly data.
load Data_GNP gnpDate = dates; realgnp = DataTable.GNPR; [~,c] = hpfilter(realgnp,1600); plot(gnpDate,c) axis tight ylabel('Real GNP cyclical component')
Y— Time series data
Time series data, specified as a numeric vector of length
numObs or a
numSeries numeric matrix.
A vector represents
numObs observations of a single series or variable.
A matrix represents
numObs observations of
Y( is the observed value of series
. Observations within the same row occur simultaneously.
The last element or row contains the latest observation.
If any element of
hpfilter issues an error.
smoothing— Trend component smoothing parameter
Inf| nonnegative numeric scalar | nonnegative numeric vector
Trend component smoothing parameter, specified as a nonnegative numeric scalar or a nonnegative numeric vector of length
numSeries. For a numeric scalar,
smoothing to all series in
Y. For a numeric vector,
smoothing( to series
in the data (
hpfilter does not smooth the trend component of series
. In this case, the following are true:
hpfilter applies the maximum smoothing. In this case, the following are true:
Trend(:, is the linear time trend computed by least squares.
Cyclical(:, is the detrended series.
As the magnitude of the smoothing parameter increases,
Trend approaches the linear time trend.
Appropriate values of the smoothing parameter depend on the periodicity of the data. Although a best practice is to experiment with smoothing values for your data, these smoothing values are recommended :
14400 for monthly data
1600 for quarterly data
100 for yearly data
Trend— Trend component τt
Trend component τt of each series in the data, returned as a numeric vector or matrix with the same dimensions as
Cyclical— Cyclical component ct
Cyclical component ct of each series in the data, returned as a numeric vector or matrix with the same dimensions as
The objective function of the filter is
T is the sample size.
λ is the smoothing parameter (
yt – τt = ct.
The programming problem is to minimize the objective function over τ1,…,τT. The objective penalizes the sum of squares for the cyclical component with the sum of squares of second-order differences for the trend component (trend acceleration penalty). If λ = 0, the minimum of the objective is 0 with τt = yt for all t. As λ increases, the penalty for a flexible trend increases, resulting in an increasingly smoother trend. When λ is arbitrarily large, the trend acceleration approaches 0, resulting in a linear trend.
This figure shows the effects of increasing the smoothing parameter on the trend component for a simulated series.
The filter is equivalent to a cubic spline smoother, where the smoothed component is τt.
For high-frequency series, the Hodrick-Prescott filter can produce anomalous endpoint effects. In this case, do not extrapolate the series using the results of the filter.
 Hodrick, Robert J., and Edward C. Prescott. "Postwar U.S. Business Cycles: An Empirical Investigation." Journal of Money, Credit and Banking 29, no. 1 (February 1997): 1–16. https://doi.org/10.2307/2953682.