hp_filter: Decompose a times series via the Hodrick-Prescott filter

View source: R/RcppExports.R

hp_filterR Documentation

Decompose a times series via the Hodrick-Prescott filter

Description

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.

Usage

hp_filter(x, lambda)

Arguments

x

One column matrix with numeric values.

lambda

Numeric value.

Value

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

Author(s)

Philipp Adämmer

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.

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))



lpirfs documentation built on July 9, 2023, 6:35 p.m.