CMTrates function - grfiv/ustreasuries GitHub Wiki

This function returns an R data.frame with one row per day and columns for the date and the rates for points on the yield curve from 1 month to 30 years; sorted in descending order by date.

The rate data is in "percent" format: 7.82, for instance, indicates 7.82% or 0.0782

See the PrintYieldCurves function page for an example of what you can do with the data.

Data Sample

> Sys.Date()
[1] "2016-02-01"
> library(ustreasuries)
> all_data = CMTrates()
> tail(all_data)
Source: local data frame [6 x 14]

     Id   NEW_DATE BC_1MONTH BC_3MONTH BC_6MONTH BC_1YEAR BC_2YEAR BC_3YEAR
  (dbl)     (date)     (dbl)     (dbl)     (dbl)    (dbl)    (dbl)    (dbl)
1  6521 2016-01-22      0.26      0.31      0.41     0.47     0.88     1.11
2  6522 2016-01-25      0.25      0.31      0.42     0.47     0.88     1.10
3  6523 2016-01-26      0.29      0.31      0.45     0.47     0.85     1.07
4  6524 2016-01-27      0.28      0.32      0.43     0.47     0.84     1.07
5  6525 2016-01-28      0.26      0.35      0.45     0.47     0.83     1.05
6  6526 2016-01-29      0.22      0.33      0.43     0.47     0.76     0.97
Variables not shown: BC_5YEAR (dbl), BC_7YEAR (dbl), BC_10YEAR (dbl), BC_20YEAR
  (dbl), BC_30YEAR (dbl), BC_30YEARDISPLAY (dbl)

Starting Dates

The ending date is always the most-recently-completed business day as you can see in the data sample above: 2016-02-01 was a Monday and 2016-01-29 was the previous Friday.

The start dates for each of the columns do not all start exactly on the first business day of January 1962; rates for dates prior to these are given as NA:

M01 2001-07-31
M03 1982-01-04
M06 1982-01-04
Y01 1962-01-02
Y02 1976-06-01
Y03 1962-01-02
Y05 1962-01-02
Y07 1969-07-01
Y10 1962-01-02
Y20 1993-10-01
Y30 1977-02-15

Furthermore, some random points are missing (NA): for example, the 20-year stopped trading for a while during a fleeting budget surplus.

Code Sample

> library(ustreasuries)
> all_data = CMTrates()
> max_idx  <- which.max(all_data$BC_10YEAR)
> max_rate <- all_data$BC_10YEAR[max_idx]
> max_date <- all_data$NEW_DATE[max_idx]
> 
> min_idx  <- which.min(all_data$BC_10YEAR)
> min_rate <- all_data$BC_10YEAR[min_idx]
> min_date <- all_data$NEW_DATE[min_idx]
> 
> x_label <- paste0("Max: ",max_rate," (",max_date,"), ",
+                   "Min: ",min_rate," (",min_date,")")
> 
> plot(1:nrow(all_data), all_data$BC_10YEAR,
+      xaxt="n", xlab=x_label, ylab='Interest Rates',
+      pch = ".",cex=1.5,
+      main="10-Year US Treasury Yields")
> grid()
> 
> label_vec <- c(1, max_idx, min_idx, nrow(all_data))
> axis(1, at=label_vec, labels=all_data$NEW_DATE[label_vec])
> abline(v=label_vec)

10-Year Yields