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

Description Usage Arguments Value Author(s) References Examples

View source: R/RcppExports.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 March 24, 2021, 1:10 a.m.