MyNixOS website logo
Description

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) <doi:10.2139/ssrn.6371138>.

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

FunctionMethodKey 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 HybridRobust 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.
Metadata

Version

0.2.1

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows