Created
October 29, 2012 04:05
-
-
Save jaredwoodard/3971451 to your computer and use it in GitHub Desktop.
Chart individual VIX futures contracts
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
# 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