# Documentation

### This is machine translation

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

# hpfilter

Hodrick-Prescott filter for trend and cyclical components

## 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.

## Examples

collapse all

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 ```

collapse all

### Algorithms

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

`$\sum _{t=1}^{m}{C}_{t}^{2}+\lambda \sum _{t=2}^{m-1}{\left(\left({T}_{t+1}-{T}_{t}\right)-\left({T}_{t}-{T}_{t-1}\right)\right)}^{2}$`

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).

## References

[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.