Skip to content

Hodrick–Prescott filter

Understand the finite-sample HP smoothing objective, the role of lambda and endpoints, and how new observations revise a historical trend and introduce look-ahead in backtests.

The Hodrick–Prescott (HP) filter decomposes a time series into a smooth trend and a residual by penalising changes in the trend’s slope. It gives a quant a reproducible way to describe departures from a chosen smooth path. The fitted historical trend usually uses later observations, so treating a retrospective HP chart as a contemporaneous signal can contaminate a trading backtest.

What “smooth” costs

Let y1,…,yTy_1,\ldots,y_T be equally spaced, finite observations, with T≥3T\geq3. In the finite-sample version used here, choose λ≥0\lambda\geq0 and solve

min⁡τ1,…,τT{∑t=1T(yt−τt)2+λ∑t=2T−1(τt+1−2τt+τt−1)2}.\min_{\tau_1,\ldots,\tau_T} \left\{ \sum_{t=1}^{T}(y_t-\tau_t)^2 +\lambda\sum_{t=2}^{T-1}(\tau_{t+1}-2\tau_t+\tau_{t-1})^2 \right\}.
The first sum charges for missing the observations. The second charges for changing the slope: τt+1−2τt+τt−1\tau_{t+1}-2\tau_t+\tau_{t-1} is the change between two successive first differences. A straight, steeply rising line has zero curvature penalty; “smooth” does not mean “flat”. This is the fit-versus-smoothness trade-off in Hodrick and Prescott’s decomposition procedure.

The boundary convention matters. Here every observation has unit weight, only the T−2T-2 second differences entirely inside the sample are penalised, and there are no padded observations or imposed endpoint slopes. The endpoints are estimated jointly with the interior; they are not fixed to the first and last data values.

If KK maps a vector to those second differences, the first-order conditions give

(I+λK⊤K)τ^=y,τ^=(I+λK⊤K)−1y,c^=y−τ^.(I+\lambda K^\top K)\hat\tau=y, \qquad \hat\tau=(I+\lambda K^\top K)^{-1}y, \qquad \hat c=y-\hat\tau.
The inverse expresses the mathematics; a numerical implementation can solve the linear system directly. For nonnegative λ\lambda, the identity term makes the system positive definite and the solution unique. The residual c^\hat c is conventionally called the cycle, but that label alone identifies neither an economic mechanism nor a recurring period.

A five-point pulse, then a revised history

Take the fictional observations 0, 0, 10, 0, 0 index points and set λ=1\lambda=1 solely to make the arithmetic transparent. The three rows of KK place coefficients 1,−2,11,-2,1 on periods 1–3, 2–4 and 3–5 respectively. Solving gives
τ^=(5/125/225/65/25/12),c^=(−5/12−5/235/6−5/2−5/12).\hat\tau= \begin{pmatrix}5/12\\5/2\\25/6\\5/2\\5/12\end{pmatrix}, \qquad \hat c= \begin{pmatrix}-5/12\\-5/2\\35/6\\-5/2\\-5/12\end{pmatrix}.
Only 4.167 of the central observation’s 10 points goes into the fitted trend. The residual at that date is 5.833 points; the zero observations around it have negative residuals because their fitted trends are positive. This is the stated optimisation allocating a pulse between its two components, not evidence that the fictional series has an economic boom and bust.
Now stand at period 4, when the fifth observation is unavailable. With the same λ\lambda and boundary rule, the four-point fit is
τ^(4)=(10/3380/33140/33100/33).\hat\tau^{(4)}= \begin{pmatrix}10/33\\80/33\\140/33\\100/33\end{pmatrix}.
Its last value is 3.030. Appending period 5’s zero changes the estimate for period 4 to 2.500, a revision of −35/66≈−0.530-35/66\approx-0.530 points. None of the first four observations changed.
Fictional observations 0, 0, 10, 0, 0 index points give a five-period HP trend of 0.417, 2.500, 4.167, 2.500, 0.417 at lambda 1. Adding the fifth observation revises the period-4 trend from 3.030 to 2.500.
Fictional observations 0, 0, 10, 0, 0 index points give a five-period HP trend of 0.417, 2.500, 4.167, 2.500, 0.417 at lambda 1. Adding the fifth observation revises the period-4 trend from 3.030 to 2.500.
The full-sample fit smooths the pulse; the zoomed panel reveals a historical revision caused only by extending the sample. The two panels use different vertical scales.
The ordinary full-sample filter is two-sided: an interior trend estimate generally depends on observations on both sides of its date. Near a boundary, the available observations are asymmetric and the effective weights differ. Hamilton’s analysis, §§2–3.2, explains why endpoint estimates and retrospective interior estimates can tell different stories.
Using the five-point period-4 estimate in a decision supposedly made at period 4 introduces look-ahead bias. An expanding-sample implementation can instead fit only the observations available at each decision and retain that fit’s endpoint. It must also preserve the data vintage and choose its parameters using information available then. That produces a different sequence from taking an interior column of the final fit. It removes this particular future-observation leak, while leaving the question of whether the chosen decomposition is economically useful.
The Point-in-Time Data lesson develops transformation cutoffs, historical versions and truncation checks. Its preview is public; the full lesson requires membership.

What changing λ\lambda can—and cannot—settle

At λ=0\lambda=0, the trend equals the data and the residual is zero. As λ\lambda grows, changes in slope become more expensive. In the limit λ→∞\lambda\to\infty, the trend approaches the least-squares straight line through the sample. For our symmetric pulse, that limiting line is the constant 2 index points. Finite positive λ\lambda allows curvature; it does not specify a forecast horizon.
The familiar quarterly macroeconomic convention λ=1600\lambda=1600 is a historical modelling choice, not a general calibration for prices or trading signals. Ravn and Uhlig study how an existing choice can be adjusted when observation frequency changes. Their fourth-power rule aims to approximately preserve the filter’s frequency response; it does not establish that the starting parameter or the HP decomposition is appropriate for a particular dataset. Their time-domain analysis also distinguishes time aggregation from point sampling.
Finally, an apparently oscillating residual is insufficient evidence for a tradable economic cycle. Hamilton shows how HP filtering can create dynamic patterns from a random walk. Nor does a smooth fitted path establish stationarity. A quant using this decomposition should state its economic purpose, sample boundaries, parameter and information cutoff before interpreting the resulting “cycle”.

Sources

Last updated
  • detrending
  • time series
  • smoothing
  • endpoint revision
  • look ahead bias
← Back to the glossaryBack to top ↑