hpfilter
Hodrick-Prescott filter for trend and cyclical components
Syntax
Description
The hpfilter
function applies the Hodrick-Prescott filter to
separate one or more time series into additive trend and cyclical components.
hpfilter
optionally plots the series and trend component, with
cycles removed. The plot helps you select a smoothing parameter.
In addition to the Hodrick-Prescott filter, Econometrics Toolbox™ supports the Baxter-King (bkfilter
),
Christiano-Fitzgerald (cffilter
), and
Hamilton (hfilter
)
filters.
[
returns tables or timetables containing variables for the trend and cyclical components
from applying the Hodrick-Prescott filter to each variable in the input table or
timetable. To select different variables to filter, use the
TTbl
,CTbl
] = hpfilter(Tbl
)DataVariables
name-value argument. (since R2022a)
[___] = hpfilter(___,
specifies options using one or more name-value arguments in
addition to any of the input argument combinations in previous syntaxes.
Name=Value
)hpfilter
returns the output argument combination for the
corresponding input arguments. For example,
hpfilter(Tbl,Smoothing=100,DataVariables=1:5)
applies the
Hodrick-Prescott filter to the first five variables in the input table
Tbl
and sets the smoothing parameter to
100
. (since R2022a)
hpfilter(___)
plots time series variables in the
input data and their respective trend components, computed by the Hodrick-Prescott filter,
on the same axes.
hpfilter(
plots on the axes specified by ax
,___)ax
instead of
the current axes (gca
). ax
can precede any of the input
argument combinations in the previous syntaxes. (since R2022a)
Examples
Input Arguments
Output Arguments
More About
Tips
Hodrick and Prescott [1] suggest values for the smoothing parameter λ (
Smoothing
) that depend upon the periodicity of the data, and Ravn and Uhlig [3] suggest adjustments to those values. This table contains their suggested smoothing parameter values for several data periodicities.Periodicity Hodrick and Prescott Suggested Smoothing
Ravn and Uhlig Suggested Smoothing
Yearly 100 6.25 Quarterly 1600 1600 Monthly 14400 129600 Supply a vector of smoothing parameters for the
Smoothing
name-value argument to test alternatives. Plot the results to visually compare the alternatives.The default two-sided filter (see
FilterType
) uses future values of the input series to compute outputs at time t. Because the filter is typically applied to historical data, the results can contain anomalous end effects unsuitable for forecasting [4]. The one-sided filter, by contrast, is causal because it uses only current and previous values of the input series. As a result, the one-sided filter does not revise outputs when new data becomes available.
Algorithms
hpfilter
implements the closed-form solution in [2], Appendix A to the original Hodrick-Prescott programming problem [1].
Therefore, hpfilter
requires complete data and removes
NaN
values in the input data by using listwise deletion.
References
[1] 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.