Tag Archives: calendar spread

R Code for for charting Daily Crude Oil Futures spread of calendar spread of first two months

This came in from the NYC Contact which could be very very useful for y’all. More to come!

R Code for for charting Daily Crude Oil Futures spread (calendar spread of first two months) .

The chart shows mean reversion and volatility. Extreme contango has happened several times.
Here is the R code:

CL1 = read.csv('http://www.quandl.com/api/v1/datasets/CHRIS/CME_CL1.csv?&trim_start=1983-03-31&trim_end=2014-03-24&sort_order=desc', colClasses=c('Date'='Date'))

CL2 = read.csv('http://www.quandl.com/api/v1/datasets/CHRIS/CME_CL2.csv?&trim_start=1983-03-30&trim_end=2014-03-24&sort_order=desc', colClasses=c('Date'='Date'))

CL_Spread["Date"] = CL1["Date"]

CL_Spread["Settle"] = CL1["Settle"] - CL2["Settle"]

rdate fix(rdate)
plot(CL_Spread$Settle~rdate, type="l",col="blue",axes=F)
box()
axis(1,rdate,format(rdate,"%m-%y"))
axis(2,CL_Spread$Settle)