Load libraries
library(mFilter)
library(quantmod)
Import the data
getSymbols("RGDPCHJPA625NUPN",src="FRED")
[1] "RGDPCHJPA625NUPN"
Run the HP filter
hpf <- hpfilter(log(RGDPCHJPA625NUPN),freq = 6.25)
Plot the series
out <- xts(cbind(hpf$x, hpf$trend, hpf$cycle), index(RGDPCHJPA625NUPN))
colnames(out) <- c("x", "trend", "cycle")
par(mfrow = c(2, 1), mar = c(3, 2, 2, 1))
plot(out[,"x"], t= "n", main = paste(hpf$title, "of", hpf$xname))
lines(out[,"trend"], col = "red")
plot(out[,"cycle"], t = "n", main = "Cyclical component (deviations from trend)")
getSymbols("RGDPCHBOA625NUPN",src="FRED")
[1] "RGDPCHBOA625NUPN"
hpf <- hpfilter(log(RGDPCHBOA625NUPN),freq = 6.25)
out <- xts(cbind(hpf$x, hpf$trend, hpf$cycle), index(RGDPCHBOA625NUPN))
colnames(out) <- c("x", "trend", "cycle")
par(mfrow = c(2, 1), mar = c(3, 2, 2, 1))
plot(out[,"x"], t= "n", main = paste(hpf$title, "of", hpf$xname))
lines(out[,"trend"], col = "red")
plot(out[,"cycle"], t = "n", main = "Cyclical component (deviations from trend)")