CommencerCommencer gratuitement

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

Afficher le cours

Instructions

  • Load the quantmod package.
  • Use getSymbols() from quantmod to obtain data on DGS10 from FRED. Be sure to set the auto.assign argument to FALSE. Save this data to t10yr.
  • Subset your t10yr data to the period from January 2006 to September 2016 using the data["date1/date2"] format.
  • Use the pre-written code to plot your t10yr data.

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")
Modifier et exécuter le code