The goal of treasury is to provide a simple and modern interface to the US treasury XML feed for daily interest rates. The main difference to other packages is that it’s a modern implementation using the httr2 package.
You can install the development version of treasury from GitHub with:
treasury functions are prefixed with tr_
and follow the naming convention of the XML feed.
library(ggplot2)
library(treasury)
yield_curve <- tr_yield_curve(2020)
yield_curve
#> # A tibble: 3,012 × 3
#> date maturity rate
#> <date> <chr> <dbl>
#> 1 2020-01-02 1 month 1.53
#> 2 2020-01-02 2 month 1.55
#> 3 2020-01-02 3 month 1.54
#> 4 2020-01-02 6 month 1.57
#> 5 2020-01-02 1 year 1.56
#> # ℹ 3,007 more rows
subset(yield_curve, maturity == "10 year") |>
ggplot(aes(x = date, y = rate)) +
geom_line() +
labs(
title = "US Treasury Yield Curve 2020 (10 Year Maturity)",
x = NULL, y = NULL
) +
theme_minimal()