Retrieving the VIX term structure in R

[This article was first published on Bommarito Consulting » 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.

  Much of my time lately has gone into analyzing and trading products in the volatility complex.  As a result, I regularly watch the VIX term structure for continuations or deviations from trend.  To make analysis simpler, I’ve written some R code that rips the term structure off the CBOE VIX term structure page and parses it into a table with proper typing.  You can view this code in the embedded gist below:

#@author Bommarito Consulting, LLC; http://bommaritollc.com/
#@date 20121105
# Imports
library(RCurl)
library(XML)
# Set RCurl options
options(RCurlOptions = list(timeout = 10, useragent = "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"))
# Retrieve CBOE VIX term structure page and parse into HTML.
buffer <- getURL("http://www.cboe.com/data/volatilityindexes/volatilityindexes.aspx")
doc <- htmlParse(buffer, asText=T)
# Extract the term structure table.
vixTerm <- readHTMLTable(getNodeSet(doc, "//table[starts-with(@id, 'ctl00_')]")[[1]], header=T, colClasses=c('character', 'character', 'numeric', 'numeric'), as.factor=F)
# Clean up and process dates.
names(vixTerm) <- c("tradeDate", "expirationDate", "value", "month")
vixTerm$tradeDate <- as.POSIXct(vixTerm$tradeDate, format="%m/%d/%Y %I:%M:%S %p")
vixTerm$expirationDate <- as.Date(vixTerm$expirationDate, "%d-%b-%y")

To leave a comment for the author, please follow the link and comment on their blog: Bommarito Consulting » 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)