Extracting Business Cycles from Time Series#
Extracting Business Cycles from Macroeconomic Data#
Introduction#
A central challenge in empirical macroeconomics is separating the trend component of a time series — its long-run growth path — from the cyclical component — the short-run fluctuations around that path. This decomposition is not directly observable: we only see the raw series \(y_t\), which is the sum of both components:
where \(\tau_t\) is the trend and \(c_t\) is the cycle. The cycle is what macroeconomists mean by the “business cycle”: the periodic booms and busts that drive fluctuations in unemployment, investment, and living standards. To study business cycles empirically — to measure their amplitude, duration, and comovement across variables and countries — we need a method for extracting \(c_t\) from \(y_t\).
This notebook develops four widely used methods for doing so, applies each to GDP data from a cross-section of countries, and compares their properties. The methods are:
Log-linear and log-quadratic detrending: fit a deterministic polynomial trend and treat the residual as the cycle.
Hodrick-Prescott (HP) filter: choose a smooth time-varying trend by solving a penalized least squares problem.
Hamilton filter: define the cycle as the unpredictable component of an \(h\)-step-ahead forecast.
Baxter-King (BK) and Christiano-Fitzgerald (CF) band-pass filters: isolate fluctuations within the frequency band associated with business cycles.
Why the Log Transformation?#
Most macroeconomic variables exhibit exponential rather than linear growth. If \(Y_t\) grows at constant rate \(g\) with proportional random deviations:
then the percentage change is \(\Delta Y_t / Y_{t-1} = g + \varepsilon_t\) — a constant plus noise. Taking logarithms, \(y_t = \ln Y_t\) transforms the exponential trend into a linear one:
We should log-transform variables that grow exponentially over time — GDP, consumption, investment, industrial production — but not variables that are already expressed as rates or shares, such as the unemployment rate, the savings rate, or interest rates. All GDP series in this notebook are log-transformed before filtering.
Data#
We download real GDP data for a cross-section of countries from FRED (Federal Reserve Economic Data). We use quarterly, seasonally adjusted real GDP series where available, standardizing each to an index with base year 2015 = 100 to facilitate comparison across countries.
Downloaded United States: 176 quarters (1980Q1–2023Q4)
Downloaded United Kingdom: 163 quarters (1980Q1–2020Q3)
Downloaded Germany: 132 quarters (1991Q1–2023Q4)
Downloaded Japan: 120 quarters (1994Q1–2023Q4)
Downloaded Canada: 176 quarters (1980Q1–2023Q4)
Downloaded Australia: 44 quarters (1980Q1–2023Q1)
Method 1: Log-Linear and Log-Quadratic Detrending#
Theory#
The simplest detrending method fits a deterministic polynomial time trend by OLS and defines the cycle as the residual. For a log-linear trend:
the trend is \(\hat{\tau}_t = \hat{a} + \hat{g}t\) and the cycle is \(\hat{c}_t = y_t - \hat{\tau}_t\). A log-quadratic extension adds a squared term to allow for curvature in the trend:
When is it appropriate? Log-linear detrending is appropriate when the data-generating process has a constant growth rate — that is, when the underlying trend is genuinely linear in logs. For most developed economies’ GDP, this is a reasonable first approximation over long samples, though it may miss structural breaks in trend growth (such as the productivity slowdown after 1973 or the post-GFC slowdown).
Limitations. A deterministic trend assumes that the economy always returns to the same long-run path after a shock — any permanent shift in the level of GDP is attributed to the cycle rather than the trend. If GDP follows a random walk with drift (a stochastic trend), log-linear detrending will produce spuriously persistent cycles.
Method 2: The Hodrick-Prescott Filter#
Theory#
Hodrick and Prescott (1981) propose choosing the trend \(\tau_t\) by solving a penalized least squares problem:
The first term penalizes deviations of the trend from the data — if \(\lambda = 0\), the trend equals the data exactly and the cycle is zero. The second term penalizes changes in the trend’s growth rate — if \(\lambda \to \infty\), the trend growth rate is forced to be constant and the HP filter converges to a log-linear trend. The parameter \(\lambda\) therefore governs the smoothness of the trend: larger \(\lambda\) produces a smoother trend and a more volatile cycle.
The first-order conditions \(\partial f/\partial \tau_t = 0\) for all \(t\) reduce to a linear system \(A\tau = y\), where \(A\) is an \(T \times T\) band matrix determined by \(\lambda\). The solution is:
where \(K\) is the second-difference matrix. This can be solved efficiently using sparse linear algebra, and is implemented in statsmodels.
Choice of \(\lambda\). Convention sets \(\lambda = 1600\) for quarterly data, \(\lambda = 100\) for annual data, and \(\lambda = 14400\) for monthly data. These values are calibrated so that the HP filter approximately isolates fluctuations with periodicities between 6 and 32 quarters — the conventional definition of the business cycle frequency band. However, the choice of \(\lambda\) is contested, and we illustrate the sensitivity of the filter to this choice below.
Known limitations. The HP filter has been criticized on several grounds, most systematically by Hamilton (2017):
It produces spurious dynamic relationships in the filtered series that have no basis in the underlying data-generating process.
The filter performs poorly at the endpoints of the sample: the trend estimate near the beginning and end of the series is unreliable because it has fewer observations on one side to anchor it.
The conventional \(\lambda = 1600\) is far from the value that would be optimal under a formal statistical criterion.
Despite these criticisms, the HP filter remains the most widely used detrending method in macroeconomics and is the benchmark against which most business cycle models are evaluated.
The top figure shows the HP-filtered business cycle for all six countries. Positive values (light shading) indicate booms — output above trend; negative values (dark shading) indicate recessions — output below trend. The global financial crisis (2007–2009) and COVID-19 recession (2020) are clearly visible as troughs across all countries, though their depth and duration vary. The bottom figure illustrates the sensitivity of the HP filter to \(\lambda\): a small \(\lambda\) produces a trend that closely tracks the data, leaving little cyclical variation, while a large \(\lambda\) produces a smooth trend close to the log-linear trend, with a more volatile cycle.
Method 3: The Hamilton Filter#
Theory#
Hamilton (2017) proposes an alternative to the HP filter that avoids its known shortcomings. The key insight is to define the cyclical component as the unpredictable component of the series at a horizon \(h\):
The cycle at time \(t+h\) is the OLS residual \(\hat{\varepsilon}_{t+h}\): the difference between the realized value and the value predicted by the most recent four lags. Hamilton recommends \(h = 8\) quarters (two years) and \(p = 4\) lags for quarterly data — both are multiples of the seasonal frequency, which helps avoid spurious seasonal contamination of the cycle.
Why \(h = 8\)? Hamilton argues that a two-year forecast horizon corresponds naturally to the business cycle concept: we want to identify deviations from what the economy was expected to achieve two years ago, based on information available at that time. This definition is robust to a wide class of data-generating processes, including unit root processes, whereas the HP filter requires stationarity assumptions that may not hold.
Advantages over HP. The Hamilton filter does not produce spurious autocorrelation in the residuals, performs consistently throughout the sample (including at the endpoints), and has a clear statistical interpretation as a forecast error. Its main disadvantage is that it uses \(h + p = 12\) observations to start the regression, losing observations at the beginning of the sample, and its cycle component may include frequencies outside the conventional business cycle band.
Method 4: Band-Pass Filters#
Theory#
Band-pass filters take a spectral perspective on the trend-cycle decomposition. Any time series can be represented as a sum of sinusoidal components with different frequencies. The business cycle corresponds to fluctuations with periodicities between 6 and 32 quarters — following Burns and Mitchell’s empirical work on US business cycles — while lower-frequency components correspond to the trend and higher-frequency components correspond to irregular noise. A band-pass filter removes all components outside the target frequency band, retaining only the business cycle frequencies.
The Baxter-King (BK) filter implements this idea using a symmetric moving average:
where the weights \(a_k\) are chosen to approximate the ideal band-pass filter in the frequency domain. The constraint \(\sum_k a_k = 0\) ensures that any linear trend in the series is eliminated. Following Baxter and King’s recommendations, we use \(P_L = 6\), \(P_H = 32\), and \(K = 12\) for quarterly data. The symmetric moving average means the filter loses \(K = 12\) observations at each end of the sample.
The Christiano-Fitzgerald (CF) filter generalizes the BK filter by using an asymmetric, time-varying moving average that adapts to the full length of the available data. This avoids the endpoint observation loss of the BK filter and generally provides a closer approximation to the ideal band-pass filter, at the cost of somewhat greater complexity.
Both filters are implemented in statsmodels. We present them together and focus on interpreting the output rather than the technical details of the weight construction.
Comparing the Four Methods#
Having computed cycles using all four methods, we now compare them directly. A good filter should: (i) identify the same broad cyclical turning points across methods; (ii) produce cycles that are uncorrelated with the raw series at long horizons (no trend contamination); and (iii) yield cycles that are synchronized across countries during global recessions. We assess each criterion in turn.
Summary of Filter Properties#
The comparison across methods reveals several consistent patterns and some important differences:
Agreement on major turning points. All four methods identify the same broad cyclical turning points — the early 1990s recession, the 2001 dot-com slowdown, the 2008–2009 global financial crisis, and the 2020 COVID recession. This agreement is reassuring: it suggests that the major features of the business cycle are genuine and not artifacts of the filtering method.
Disagreement on cycle amplitude. The methods differ substantially in their estimates of cycle volatility (as shown in the bar chart). The HP filter tends to produce a smoother trend and therefore larger cycles; the Hamilton filter, by conditioning on four quarters of lags, assigns more of the variance to the predictable component and produces a less volatile cycle. The log-linear filter produces the most volatile cycles because it fits the smoothest possible trend.
Endpoint reliability. The HP filter performs poorly near the end of the sample — the trend estimate for the most recent observations relies heavily on the filter’s endpoint correction and is sensitive to data revisions. The Hamilton filter does not have this problem: the regression residuals are well-defined throughout the sample. This matters in real-time analysis, where the most recent observations are exactly the ones of policy interest.
International synchronization. The cross-correlogram confirms that business cycles are highly synchronized internationally, particularly around global events like the GFC and COVID. The UK, Canada, and Australia show the highest contemporaneous correlation with the US cycle; Japan shows a somewhat lower correlation, reflecting structural differences in its business cycle. Both the HP and Hamilton filters tell a broadly similar story about international synchronization, though the Hamilton filter tends to produce slightly lower correlations — consistent with it filtering out some of the common trend component that the HP filter leaves in the cycle.
Conclusion#
Extracting business cycles from macroeconomic data requires choosing among several imperfect methods, each of which imposes different implicit assumptions about the nature of trend and cycle. The main lessons from this notebook are:
Log-transform first: variables that grow exponentially should be log-transformed before filtering to convert the exponential trend into a linear one.
The HP filter is the standard benchmark and is appropriate for most applications. Its main weaknesses are endpoint unreliability and potential spurious dynamics in the filtered series.
The Hamilton filter is a principled alternative that avoids the HP filter’s statistical shortcomings. Its cycle has a clean interpretation as a forecast error at a two-year horizon.
Band-pass filters (BK and CF) are useful when the goal is specifically to isolate fluctuations within the conventional business cycle frequency band. They are less flexible than the other methods but have the cleanest frequency-domain interpretation.
The choice of filter matters for magnitudes but not for qualitative conclusions: major recessions and the broad pattern of international synchronization are robust across all methods.
In practice, the best approach is to apply multiple methods and check whether the conclusions of interest are robust to the choice of filter. A result that holds only under one specific filtering method should be treated with caution.