Skip to content

Instantly share code, notes, and snippets.

@jaredwoodard
Created October 29, 2012 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaredwoodard/3971451 to your computer and use it in GitHub Desktop.
Save jaredwoodard/3971451 to your computer and use it in GitHub Desktop.
Chart individual VIX futures contracts
# this is code for charting individual VIX futures contracts. You need to know the contract letter and year
# http://cfe.cboe.com/Publish/ScheduledTask/MktData/datahouse/CFE_Z12_VX.csv
library(quantmod)
mth <- 'X'
yr <- 12
n <- 10 # number of periods for calculating historical volatility in the chart
url <- paste0("http://cfe.cboe.com/Publish/ScheduledTask/MktData/datahouse/CFE_",mth,yr,"_VX.csv")
x <- read.csv(url,header=FALSE, stringsAsFactors=F)
colnames(x) <- c(x[1,])
x <- x[-1,]
x$"Trade Date" <- as.Date(x$'Trade Date', format='%m/%d/%Y')
x[,2:11] <- data.frame(sapply(x[,2:11],as.numeric),stringsAsFactors=F)
x <- xts(x[,2:11], order.by=x$"Trade Date", frequency='d')
chartSeries(x$Close, subset='last 3 months',theme=chartTheme("white"),name=paste0("VX",mth,yr," Futures"))
addTA(volatility(last(x$Close,'4 months'),n=n,calc="close",N=252),legend=paste0(n,"-day HV"))
last(volatility(last(x$Close,'4 months'),n=n,calc="close",N=252))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment