public
Last active

Retrieving the VIX term structure from CBOE in R

  • Download Gist
getVixTermStructure.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#@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")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.