library(tsbox)
suppressMessages(library(quantmod))
suppressMessages(library(ggplot2))
ts_fred <- function(..., class = "data.frame") {
symb <- c(...)
dta.env <- new.env()
suppressMessages(getSymbols(symb, env = dta.env, src = "FRED"))
z <- data.table::rbindlist(lapply(as.list(dta.env), ts_dt), idcol = "id")
tsbox:::as_class(class)(z)
}
dta <- ts_fred(
'IRLTLT01CHM156N',
'IRLTLT01JPM156N',
'IRLTLT01AUM156N',
'DGS10',
'T10YIE',
'T20YIEM',
'T30YIEM',
'DEXSZUS',
'DEXJPUS',
'DEXUSAL',
'RNCHBIS'
)
dta_m <- ts_frequency(dta, to = "month", aggregate = "mean", na.rm = TRUE)
p <- ts_ggplot(
ts_pick(
dta_m,
`10y bond yields Switzerland` = 'IRLTLT01CHM156N',
`10y bond yields US` = 'DGS10',
`10y inflation expectations US` = 'T10YIE'
),
title = "Bond yields and inflation expecations"
)
p + scale_color_tsbox() + theme_bw()
Created on 2018-05-17 by the reprex package (v0.2.0).