Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created November 5, 2012 12:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mjbommar/4016901 to your computer and use it in GitHub Desktop.
Save mjbommar/4016901 to your computer and use it in GitHub Desktop.
Retrieving the VIX term structure from CBOE in R
#@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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment