Concept

Hodrick-Prescott Filter

Hodrick-Prescott Filter is a Statistics concept. The Library holds 1 implementation — a working definition you can pull into Quant.

Top Hodrick-Prescott Filter indicator

The top custom implementation, built on the original standard Hodrick-Prescott Filter formula.

1 total

The Hodrick-Prescott Filter implementation below can become a backtested trading strategy, built in plain English with no code.

What is the Hodrick-Prescott Filter?

The Hodrick-Prescott (HP) filter is a trend-extraction method from macroeconometrics, introduced to economics by Robert Hodrick and Edward Prescott for separating business-cycle fluctuations from long-run growth. It chooses the trend that minimizes a two-part objective: the sum of squared gaps between the series and the trend (fit), plus lambda times the sum of squared second differences of the trend (a penalty on changes in its slope). Small lambda lets the trend hug the data; as lambda grows the trend stiffens, approaching a straight line in the limit. Mathematically it is a special case of the earlier Whittaker-Henderson smoother with a second-difference penalty.

On charts the filter splits price into a smooth trend and a cycle residual, and adaptations draw envelopes around the smooth to frame stretch and reversion. The critical caveat for trading is that the standard filter is two-sided: each point's trend value is fitted using data on both sides of it, so values near the right edge revise as new bars arrive. Endpoint distortion is a standard criticism in the economics literature as well, and on a chart it means naive use repaints; one-sided (causal) variants avoid revision at the cost of extra lag.

Lambda is the filter's one real decision. Macroeconomists settled on 1600 for quarterly data, and the Ravn-Uhlig rule scales that convention across observation frequencies by the fourth power of the frequency ratio, giving about 129,600 for monthly series. No such convention exists for market bars, so chart implementations expose lambda as an input. Useful practice is to tune it once until the cycle residual oscillates cleanly around zero at the horizon you trade, then freeze it, since a lambda re-tuned per chart is a curve fit waiting to happen.

The filter also carries serious academic criticism worth knowing. James Hamilton's widely cited 2018 paper argued that the HP filter can manufacture spurious cycles, distorts endpoints and rests on an arbitrary lambda, recommending regression-based alternatives; earlier work by Cogley and Nason raised related concerns about spurious dynamics. For chart use the lesson is proportion: treat the output as a descriptive smooth, implemented causally when traded, for example via the one-sided variant computed with a Kalman filter recursion. LuxAlgo's Whittaker Envelope applies the same penalized-smoothing idea with bands added for reversion framing.

How to identify the Hodrick-Prescott filter on a chart

An HP trend looks like a suspiciously smooth moving average with no lag through the middle of history. The tells are at the edges.

  1. 1Set lambda for your bar frequency and horizon: larger values stiffen the trend toward a line, smaller values let it chase price; tune once on history and freeze it.
  2. 2Plot the trend and its cycle residual, price minus trend; a well-tuned residual oscillates around zero without long one-sided stretches.
  3. 3Watch the right edge as new bars arrive: the last stretch of the trend visibly bends and re-settles, which is the two-sided revision in action.
  4. 4For anything live, switch to a one-sided variant or act only on values old enough to have stabilized, and label the chart accordingly.
  5. 5Standardize the residual with a z-score if you want comparable stretch readings across symbols and volatility regimes.

How it's calculated

Decomposes a series into a smooth trend and a cyclical remainder by penalizing changes in the trend's slope.

yt=τt+cty_t = \tau_t + c_t
Trend: choose τ1,,τT to minimize t=1T(ytτt)2+λ×t=2T1((τt+1τt)(τtτt1))2\text{Trend: choose } \tau_1, \ldots, \tau_T \text{ to minimize } \sum_{t=1}^{T} (y_t - \tau_t)^2 + \lambda \times \sum_{t=2}^{T-1} \left((\tau_{t+1} - \tau_t) - (\tau_t - \tau_{t-1})\right)^2
Cycle:ct=ytτt\text{Cycle:}\quad c_t = y_t - \tau_t
y_t: input series at time t (log price is typical for markets)
τ_t: trend component at time t
c_t: cyclical component at time t
λ: smoothing weight; larger values force a straighter trend (1600 for quarterly data)
T: number of observations in the sample
t: time index

Standard λ values follow the Ravn-Uhlig fourth-power rule: 6.25 annual, 1600 quarterly, 129600 monthly; daily bars need far larger values.

The minimization solves a sparse linear system over the whole sample in one pass.

The filter is two-sided, so recent values revise as new bars arrive; treat the latest stretch as provisional in live use.

How traders use it

  • Trend-cycle decomposition: subtract the HP trend from price to get a detrended oscillator around zero, a simple entry point into signal decomposition and cycle study.
  • Envelope construction: offset bands around the HP trend (by a volatility unit or a fixed percentage) to frame overextension and mean-reversion zones with a smoother midline than a moving average.
  • Higher-timeframe bias reference, provided the two-sided revision is handled honestly: evaluated on confirmed history, replaced with a one-sided variant, or treated as descriptive rather than tradable, in line with repaint-safe engineering.
  • Residual mean-reversion study: the z-scored cycle component becomes a stretch oscillator with entry and exit thresholds, effectively a statistically dressed version of trading distance from a smooth midline.
  • Research benchmark: because the two-sided fit is close to an ideal smooth on past data, it serves as the reference other causal smoothers are judged against when quantifying how much lag and noise they add.

HP filter vs other trend extractors

Linear Regression: A regression line forces one slope across the window; the HP trend bends wherever the penalty allows, following slow curvature a line cannot. Both are in-sample fits whose newest values revise, but the regression's rigidity makes it more transparent.

Kalman Filter: The Kalman filter is causal and never repaints: each estimate uses only past data, at the cost of lag and an explicit model. The standard HP filter is two-sided and revises; its one-sided variant is in fact usually computed with a Kalman-style recursion.

Exponential Smoothing: Exponential smoothing is a one-pass causal filter with lag proportional to its smoothing constant. The HP filter buys its superior in-sample smoothness by using future data at every interior point, which is exactly what a live chart lacks at the right edge.

Concept family

Statistics

46 concepts mapped · 46 in the Library

Hodrick-Prescott Filter FAQ

Why does the Hodrick-Prescott filter repaint on charts?

Because the standard HP filter is a two-sided smoother: every point's trend value is estimated using bars before and after it. At the right edge the future half is missing, so the newest trend values are provisional and shift as bars are added, which moves plotted history. Fixes include one-sided causal variants, evaluating signals only on data old enough to be stable, or using the filter descriptively rather than as a signal source.

What does lambda control in the HP filter?

Lambda is the smoothness weight. It multiplies the penalty on squared changes in the trend's slope, so it decides how much wiggle the trend is allowed: near zero the trend chases price, and as lambda grows toward infinity the trend approaches a straight line. Macroeconomists conventionally use 1600 for quarterly data, but there is no agreed value for market bars, so chart implementations expose lambda as a tuning input.

What lambda should you use on daily or intraday charts?

There is no agreed value. The Ravn-Uhlig frequency-scaling rule extrapolates the quarterly 1600 convention, but its assumptions concern business cycles, not trading horizons. The workable approach is empirical: pick the horizon whose swings you care about, tune lambda until the trend ignores noise below that horizon and the residual cycles cleanly around zero, then freeze the value and treat any later re-tuning as a research change rather than a knob.

What is the one-sided HP filter?

A causal re-computation: each bar's trend value is fitted using only data up to that bar, typically via a Kalman-smoother recursion rather than re-solving the full problem every step. It never revises, so it is honest to trade, and it pays for that honesty with lag and a rougher line. The two-sided filter remains useful for describing history; the one-sided variant is the version that belongs in live logic.

Why do economists warn against the HP filter?

Hamilton's critique makes three points: the filter can generate cycle-like patterns from data that contain none, its endpoint estimates are least reliable exactly where decisions are made, and lambda is arbitrary. Those cautions transfer directly to charts, where the endpoint is the only bar you can trade. Used as a descriptive smooth with the revision understood, it is defensible; used naively as a live signal at the right edge, the criticism applies in full.

How does the HP filter relate to the Whittaker-Henderson smoother?

It is a special case. Whittaker's 1923 actuarial graduation method penalizes squared differences of arbitrary order; choosing second differences and calling the weight lambda gives exactly the HP objective, decades before the economics application. Chart implementations sometimes ship under the Whittaker name, as LuxAlgo's Whittaker Envelope does, with identical math underneath and an envelope layer added on top.

Turn Hodrick-Prescott Filter into a trading strategy.

Take the implementation from this page into Quant, then build on it, backtest it on real data, and keep refining it with AI.