Robust Trend-Cycle Decomposition for Macroeconomic Time Series

Provides high-performance tools for macroeconomic trend extraction and filtering, specifically designed to solve the end-point problem in real-time. Implements the MacroBoost Hybrid (MBH) filter using penalized P-splines and gradient boosting. Unlike the standard Hodrick-Prescott filter, 'MacroFilters' utilizes component-wise L2-boosting with robust loss functions (Huber) to handle extreme transient shocks (e.g., COVID-19) without inducing spurious trend shifts. The algorithm includes an automated two-layer diagnostic stage for unit roots and structural breaks, optimized via corrected AICc for computational efficiency. Methodology detailed in Kinel (2026) .


MacroFilters

Lifecycle:experimental R-CMD-check CRANstatus DOI

Working Paper Available: The econometric methodology and mathematical proofs underlying this package are distributed via SSRN: Robust Real-Time Macroeconomic Trend Extraction: A Gradient Boosting Approach.

MacroFilters is a unified, high-performance library for extracting trend and cycle components from macroeconomic time series. It combines classical filters (Hodrick-Prescott, Hamilton, Boosted HP) with its flagship algorithm, the MacroBoost Hybrid (MBH) — a gradient-boosting filter with Huber loss that is immune to structural shocks such as COVID-19, financial crises, and wars.

Why MacroFilters instead of mFilter or neverhpfilter?

  • Robustness: mbh_filter() replaces $L_2$ squared-error loss with Huber loss, ensuring extreme exogenous shocks never distort the structural trend.
  • Speed: The HP implementation uses sparse-matrix Cholesky factorisation (Matrix), scaling as O(n) instead of the dense O(n³) used by legacy packages.
  • Input agnosticism: Pass a plain numeric vector, a ts, an xts, or a zoo object — the output always matches the input class seamlessly.

The End-Point Problem: Solved

During extreme black swan events, traditional filters anchored in $L_2$ loss mechanically deform the long-run structural trend to absorb massive, transitory outliers.

As demonstrated with Real US GDP during the 2020 Q2 COVID-19 collapse, the standard HP filter bends towards the shock. The MBH filter isolates the exogenous shock entirely within the cyclical component, preserving absolute trend integrity in real-time.

Furthermore, ex-ante spectral alignment ensures the MBH filter perfectly matches the baseline cyclical volatility of the industry-standard HP filter during normal conditions, unlike the excessively volatile Hamilton filter.

(Plots generated using real-time vintage data from the Federal Reserve Economic Data - FRED).

Installation

# install.packages("devtools")
devtools::install_github("michal0091/MacroFilters")

Quick Start Arsenal

Function Method Key Advantage
hp_filter() Hodrick-Prescott (1997) Sparse O(n) implementation
hamilton_filter() Hamilton (2018) OLS regression, no spurious cycles
bhp_filter() Boosted HP — Phillips & Shi (2021) Iterative fitting with BIC/ADF stopping
mbh_filter() MacroBoost Hybrid Robust to outliers via Huber loss

All functions return a list of class c("macrofilter", "list").

library(MacroFilters)

# Fast, agnostic filtering on any time-series object
hp_result  <- hp_filter(us_gdp_xts)
mbh_result <- mbh_filter(us_gdp_xts)

# Access components directly
mbh_result$trend
mbh_result$cycle

# Add 95% bootstrap confidence bands and plot them
mbh_ci <- mbh_filter(us_gdp_xts, boot_iter = 50L)
autoplot(mbh_ci)            # ggplot: trend, observed series and confidence ribbon

Further Reading

  • vignette("introduction", package = "MacroFilters") — full walkthrough of all four filters and the S3 print/meta interface.
  • vignette("uncertainty_bands", package = "MacroFilters") — confidence bands via block bootstrap and the autoplot() method.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("MacroFilters")

0.2.1 by Michal Kinel, 4 months ago


https://github.com/michal0091/MacroFilters, https://michal0091.github.io/MacroFilters/


Report a bug at https://github.com/michal0091/MacroFilters/issues


Browse source code at https://github.com/cran/MacroFilters


Authors: Michal Kinel [aut, cre] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports data.table, ggplot2, Matrix, mboost, tseries

Suggests knitr, rmarkdown, scales, strucchange, testthat, usethis, xts, zoo


See at CRAN