LIBOR and Bond Yields

[This article was first published on Exegetic Analytics » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I’ve just been looking at the historical relationship between the London Interbank Offered Rate (LIBOR) and government bond yields. LIBOR data can be found at Quandl and comes in CSV format, so it’s pretty simple to digest. The bond data can be sourced from the US Department of the Treasury. It comes as XML and requires a little more work.

> treasury.xml = xmlParse('data/treasury-yield.xml')
> xml.field = function(name) {
+   xpathSApply(xmlRoot(treasury.xml), paste0('//ns:entry/ns:content//d:', name),
+               function(x) {xmlValue(x)},
+               namespaces = c(ns = 'http://www.w3.org/2005/Atom',
+                              d = 'http://schemas.microsoft.com/ado/2007/08/dataservices'))
+ }
> bonds = data.frame(
+   date = strptime(xml.field('NEW_DATE'), format = '%Y-%m-%dT%H:%M:%S', tz = 'GMT'),
+   yield_1m = as.numeric(xml.field('BC_1MONTH')),
+   yield_6m = as.numeric(xml.field('BC_6MONTH')),
+   yield_1y = as.numeric(xml.field('BC_1YEAR')),
+   yield_5y = as.numeric(xml.field('BC_5YEAR')),
+   yield_10y = as.numeric(xml.field('BC_10YEAR'))
+ )

Once I had a data frame for each time series, the next step was to convert them each to xts objects. With the data in xts format it was a simple matter to enforce temporal overlap and merge the data into a single time series object. The final step in the analysis was to calculate the linear coefficient, or beta, for a least squares fit of LIBOR on bond yield. This was to be done with both a 1 month and a 1 year moving window. Both of these could be achieved quite easily using rollapply() from the zoo package.

Below is the visualisation which I quickly put together on Plotly. Again I am profoundly impressed by just how easy this service is to use and how magnificent the interactive results are.

The post LIBOR and Bond Yields appeared first on Exegetic Analytics.

To leave a comment for the author, please follow the link and comment on their blog: Exegetic Analytics » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)