Plotting US Treasury yields
Since corporate bonds are riskier than US Treasuries, the risk-free rate is the baseline rate we would expect corporate bonds to yield. However, US Treasury yields are not constant and could change substantially through time. We can see this by plotting the US Treasury yield data over a long period.
In this exercise, you will use the quantmod() package to obtain and plot 10-Year US Treasury yield data from the Federal Reserve Electronic Database (FRED) from January 2006 to September 2016.
The getSymbols() command in quantmod allows you to access the FRED database by specifying the Symbols argument (in this case, to "DGS10" for 10-Year US Treasury Bonds). You'll also need to set the src argument equal to "FRED", and set auto.assign to FALSE.
Cet exercice fait partie du cours
Bond Valuation and Analysis in R
Instructions
- Load the
quantmodpackage. - Use
getSymbols()fromquantmodto obtain data onDGS10fromFRED. Be sure to set theauto.assignargument toFALSE. Save this data tot10yr. - Subset your
t10yrdata to the period from January 2006 to September 2016 using thedata["date1/date2"]format. - Use the pre-written code to plot your
t10yrdata.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Load quantmod package
# Obtain Treasury yield data
t10yr <- getSymbols(Symbols = "___", src = "___", auto.assign = ___)
# Subset data
t10yr <-
# Plot yields
plot(x = index(t10yr),
y = t10yr$DGS10,
xlab = "Date",
ylab = "Yield (%)",
type = "l",
col = "red",
main = "10-Year US Treasury Yields")