Created
November 5, 2012 12:12
-
-
Save mjbommar/4016901 to your computer and use it in GitHub Desktop.
Retrieving the VIX term structure from CBOE in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@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