A 3D view of the US Treasury yield curve

Bond market returns are typically analysed as time series data (where changes in yield are tracked over time) or across maturities (where interest rates on different contract lengths are chained together to produce the yield curve for any given date). For the US government bond market, the St. Louis Fed's FRED database provides data for a whole range of US Treasury Bonds and US Treasury Bills, allowing you to do either of these exercises. Sometimes, however, it can be useful to get a sense of how the shape of the yield curve evolves over time in a 3D graph. Here is how to create one using plotly in R.px.gif

I get data for US Treasury Bond yields from 1 month to 30 years maturity from the St. Louis Fed's FRED database and first plot them in 2D using ggplot2 to see where things stand. I then use plotly to produce a “surface plot”, which is plotly's name for a 3D graph. The result is a dynamic 3D graph which can be rotated, panned, and zoomed right within your browser thanks to WebGL. Click here to give it a try (try different browsers if the graph is not shown).

3D US Treasury yield curve

To see how all of this works in detail, get the script to generate the plots here. Also, have a look at this page at the New York Times to get a sense of what a 3D graph of the yield curve can tell you.

Get the R script here