Hodrick-Prescott (HP) Filter
The Hodrick-Prescott (HP) filter is a mathematical tool commonly used in the analysis of macroeconomic time series. Named after economists Robert J. Hodrick and Edward C. Prescott, the HP filter is designed to separate a time series into two components: a trend component and a cyclical component. This makes it an essential tool for economists and financial analysts who aim to understand the underlying trends in economic data, such as Gross Domestic Product (GDP) or financial market prices, while filtering out short-term fluctuations or “noise.”
Mathematical Formulation
For a series of T equally spaced observations y_t, choose the trend \tau_t that minimizes the sum of squared fitting errors and the penalty for changes in the trend’s slope. The penalty begins at t=2 because a second difference needs three observations.
\widehat{\tau}=\arg\min_{\tau\in\mathbb{R}^{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]With D denoting the second-difference operator, the fitted trend solves the linear system below. Each row of D has the coefficients 1,-2,1 in three successive columns.
(I+\lambda D^\top D)\widehat{\tau}=yHodrick and Prescott used \lambda=1600 for quarterly macroeconomic data. Increase \lambda for a smoother trend. The plot applies the same calculation to daily BTC/USD closes. Original paper
The trend is fitted to the full daily BTC/USD history shown. Recalculating with a new candle can change earlier fitted values.
Loading candle history…
Editable example
The example uses the same illustrative output series as the code samples below. Its cyclical component is y_t-\tau_t.
c_t=y_t-\widehat{\tau}_tEnter consecutive observations in chronological order, one per line. The fit uses the full input series. A smoothing penalty of zero returns the original observations as the trend.
Loading calculator…
Applications in Economics and Finance
The HP filter is widely used in various disciplines of economics and finance, especially for the following purposes:
Business Cycle Analysis
In macroeconomics, economists often use the HP filter to decompose GDP or other economic indicators into trend and cyclical components. This decomposition helps to identify underlying economic trends, assess the business cycle, and make informed policy decisions.
Inflation and Output Gap
Another application is in estimating the output gap, which is the difference between actual output and potential output. The HP filter helps isolate the long-term trend (potential output) from short-term fluctuations (actual output).
Financial Market Analysis
In finance, analysts use the HP filter to smooth out price series of assets, helping to identify long-term trends in stock prices, bond yields, or exchange rates. This can be particularly useful for developing trading strategies based on long-term trends versus short-term movements.
Forecasting
The filter can be used to describe a historical series before fitting a separate forecasting model. For an evaluation at a past date, fit the filter using observations available at that date.
Criticism and Limitations
Despite its popularity, the HP filter faces criticism and has several limitations:
End-Point Bias
One of the major limitations is the end-point bias, where the estimates of the trend component at the end of the sample period are often inaccurate. This makes real-time application challenging because new data can significantly alter previous estimates of the trend.
Choice of \lambda
The selection of the smoothing parameter \lambda is somewhat arbitrary and can significantly influence the results. While common values are used in practice, the validity of these values can be context-specific.
Over-Smoothing
The HP filter can also over-smooth the data, leading to the loss of important cyclical information. In some situations, other filtering techniques or decomposition methods might be more appropriate.
Computational Tools
The HP filter can be implemented in various statistical and computational software, including:
R
In R, the stats package provides a built-in function filter() that can be used to apply the HP filter. The mFilter package also offers specialized functions for implementing the HP filter.
gdp <- c(100, 102, 105, 108, 112, 115, 119, 123, 127, 130, 134)
result <- mFilter::hpfilter(gdp, freq = 1600, type = "lambda")
print(result$trend)
Python
In Python, the statsmodels library includes functions for the HP filter under the filters module.
import numpy as np
gdp = np.array([100, 102, 105, 108, 112, 115, 119, 123, 127, 130, 134], dtype=float)
difference = np.diff(np.eye(gdp.size), n=2, axis=0)
trend = np.linalg.solve(np.eye(gdp.size) + 1600 * difference.T @ difference, gdp)
cycle = gdp - trend
print(trend)
MATLAB
MATLAB also offers straightforward implementations for applying the HP filter.
gdp = [100; 102; 105; 108; 112; 115; 119; 123; 127; 130; 134];
[trend, cycle] = hpfilter(gdp, Smoothing=1600);
disp(trend)
Advanced Variants
Given the limitations of the HP filter, several advanced variants and alternative methods have been developed, including:
Baxter-King Filter
The Baxter-King filter, also known as the band-pass filter, isolates components of time series within a specific frequency band, making it useful for business cycle analysis. Unlike the HP filter, it avoids end-point bias but has its own set of limitations.
Christiano-Fitzgerald Filter
This is another band-pass filter that aims to improve upon the Baxter-King filter by providing more flexible frequency bands and better handling of end-point issues.
Structural Time Series Models
These models, including the Unobserved Components Model (UCM), offer more sophisticated methods to decompose time series into trend, cycle, and seasonal components, often with better statistical properties than the HP filter.
Wavelet Transform
Wavelet methods decompose a time series into components at multiple scales or resolutions, providing a more comprehensive view of underlying trends and cycles.
Conclusion
The Hodrick-Prescott filter remains a widely-used tool for trend and cycle decomposition in economics and finance. Despite its criticisms and limitations, its simplicity and effectiveness in separating short-term fluctuations from long-term trends make it a valuable technique for analysts and policymakers. While alternatives and advanced methods offer improvements in certain aspects, the HP filter continues to be a foundational technique in the toolkit of quantitative analysis.