hp_filter function

Decompose a times series via the Hodrick-Prescott filter

Decompose a times series via the Hodrick-Prescott filter

Estimate cyclical and trend component with filter by Hodrick and Prescott (1997). The function is based on the function hpfilter from the archived mFilter-package.

hp_filter(x, lambda)

Arguments

  • x: One column matrix with numeric values.
  • lambda: Numeric value.

Returns

A list. The first element contains the cyclical component and the second element the trend component.

Examples

library(lpirfs) # Decompose the Federal Funds Rate data_set <- as.matrix(interest_rules_var_data$FF) hp_results <- hp_filter(data_set, 1600) # Extract results and save as data.frame hp_cyc <- as.data.frame(hp_results[[1]]) hp_trend <- as.data.frame(hp_results[[2]]) # Make data.frames for plots cyc_df <- data.frame(yy = hp_cyc$V1, xx = seq(as.Date('1955-01-01'), as.Date('2003-01-01') , "quarter")) trend_df <- data.frame(yy = hp_trend$V1, xx = seq(as.Date('1955-01-01'), as.Date('2003-01-01') , "quarter")) # Make plots library(ggplot2) # Plot cyclical part ggplot(data = cyc_df) + geom_line(aes(y = yy, x = xx)) # Plot trend component ggplot(trend_df) + geom_line(aes(y = yy, x = xx))

References

Hodrick, R.J., and Prescott, E. C. (1997). "Postwar U.S. Business Cycles: An Empirical Investigation." Journal of Money, Credit and Banking, 29(1), 1-16.

Ravn, M.O., Uhlig, H. (2002). "On Adjusting the Hodrick-Prescott Filter for the Frequency of Observations." Review of Economics and Statistics, 84(2), 371-376.

Author(s)

Philipp Adämmer

  • Maintainer: Philipp Adämmer
  • License: GPL (>= 2)
  • Last published: 2025-03-18

Useful links