Skip to content

@mjbommar /getVixTermStructure.R
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.