MATLAB中有hpfilter函数(或者在MATLAB的帮助文档内搜索Hodrick)
Syntax
hpfilter(S)
hpfilter(S,smoothing)
T = hpfilter(...)
[T,C] = hpfilter(...)
Description
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.