library(dplyr)
# download US treasury 10Y constant-maturity
# yield data and compute a total return series
t10_yield <- get_yields("DGS10")
t10_tr <- total_return(yields = t10_yield, maturity = 10)
head(t10_tr)
# step-by-step calculation
t10_yield <- get_yields("DGS10", format_out = "tibble")
t10_tr <- t10_yield %>%
mutate(convexity = convexity(DGS10, 10),
mod_duration = mod_duration(DGS10, 10),
TR = total_return(DGS10, 10, mod_duration, convexity))
head(t10_tr)
Run the code above in your browser using DataLab