Notebook
In [5]:
from quantopian.research.experimental import continuous_future
from quantopian.research.experimental import history
import pandas as pd
from zipline.utils.calendars import get_calendar
import matplotlib as pl
import numpy as np
from pandas.tseries.offsets import BDay


# Initialize the continous futures contracts
VIX_current = continuous_future('VX',offset=0, roll='calendar', adjustment='mul');
VIX_nextmonth = continuous_future('VX',offset=1, roll='calendar', adjustment='mul');
#SPY_cf = continuous_future('SP',offset=0, roll='calendar', adjustment='mul');

assets = [VIX_current,VIX_nextmonth]

database1 = history(assets, fields=['close_price','contract'], frequency='daily', start='2012-07-02',end='2012-07-12')
database1 = pd.concat([database1.iloc[:,:,0],database1.iloc[:,:,1]],axis=1)
database1
Out[5]:
close_price contract close_price contract
2012-07-02 00:00:00+00:00 18.14 Future(1025201207 [VXN12]) 20.60 Future(1025201208 [VXQ12])
2012-07-03 00:00:00+00:00 17.70 Future(1025201207 [VXN12]) 20.14 Future(1025201208 [VXQ12])
2012-07-04 00:00:00+00:00 NaN Future(1025201207 [VXN12]) NaN Future(1025201208 [VXQ12])
2012-07-05 00:00:00+00:00 18.64 Future(1025201207 [VXN12]) 20.95 Future(1025201208 [VXQ12])
2012-07-06 00:00:00+00:00 18.25 Future(1025201207 [VXN12]) 20.55 Future(1025201208 [VXQ12])
2012-07-09 00:00:00+00:00 18.30 Future(1025201207 [VXN12]) 20.45 Future(1025201208 [VXQ12])
2012-07-10 00:00:00+00:00 19.25 Future(1025201207 [VXN12]) 21.15 Future(1025201208 [VXQ12])
2012-07-11 00:00:00+00:00 18.30 Future(1025201207 [VXN12]) 20.45 Future(1025201208 [VXQ12])
2012-07-12 00:00:00+00:00 18.55 Future(1025201207 [VXN12]) 20.60 Future(1025201208 [VXQ12])
In [7]:
database2 = history(assets, fields=['close_price','contract'], frequency='daily', start='2012-07-02',end='2012-12-12')
database2 = pd.concat([database2.iloc[:,:,0],database2.iloc[:,:,1]],axis=1)
database2
Out[7]:
close_price contract close_price contract
2012-07-02 00:00:00+00:00 30.38 Future(1025201207 [VXN12]) 30.31 Future(1025201208 [VXQ12])
2012-07-03 00:00:00+00:00 29.65 Future(1025201207 [VXN12]) 29.63 Future(1025201208 [VXQ12])
2012-07-04 00:00:00+00:00 NaN Future(1025201207 [VXN12]) NaN Future(1025201208 [VXQ12])
2012-07-05 00:00:00+00:00 31.22 Future(1025201207 [VXN12]) 30.82 Future(1025201208 [VXQ12])
2012-07-06 00:00:00+00:00 30.57 Future(1025201207 [VXN12]) 30.23 Future(1025201208 [VXQ12])
2012-07-09 00:00:00+00:00 30.65 Future(1025201207 [VXN12]) 30.09 Future(1025201208 [VXQ12])
2012-07-10 00:00:00+00:00 32.24 Future(1025201207 [VXN12]) 31.12 Future(1025201208 [VXQ12])
2012-07-11 00:00:00+00:00 30.65 Future(1025201207 [VXN12]) 30.09 Future(1025201208 [VXQ12])
2012-07-12 00:00:00+00:00 31.07 Future(1025201207 [VXN12]) 30.31 Future(1025201208 [VXQ12])
2012-07-13 00:00:00+00:00 29.00 Future(1025201208 [VXQ12]) 29.00 Future(1025201209 [VXU12])
2012-07-16 00:00:00+00:00 28.93 Future(1025201208 [VXQ12]) 28.80 Future(1025201209 [VXU12])
2012-07-17 00:00:00+00:00 27.73 Future(1025201208 [VXQ12]) 27.78 Future(1025201209 [VXU12])
2012-07-18 00:00:00+00:00 27.94 Future(1025201208 [VXQ12]) 27.78 Future(1025201209 [VXU12])
2012-07-19 00:00:00+00:00 27.28 Future(1025201208 [VXQ12]) 27.24 Future(1025201209 [VXU12])
2012-07-20 00:00:00+00:00 28.63 Future(1025201208 [VXQ12]) 28.32 Future(1025201209 [VXU12])
2012-07-23 00:00:00+00:00 31.10 Future(1025201208 [VXQ12]) 30.22 Future(1025201209 [VXU12])
2012-07-24 00:00:00+00:00 32.75 Future(1025201208 [VXQ12]) 31.31 Future(1025201209 [VXU12])
2012-07-25 00:00:00+00:00 31.55 Future(1025201208 [VXQ12]) 30.42 Future(1025201209 [VXU12])
2012-07-26 00:00:00+00:00 28.63 Future(1025201208 [VXQ12]) 28.32 Future(1025201209 [VXU12])
2012-07-27 00:00:00+00:00 27.94 Future(1025201208 [VXQ12]) 27.99 Future(1025201209 [VXU12])
2012-07-30 00:00:00+00:00 29.23 Future(1025201208 [VXQ12]) 28.73 Future(1025201209 [VXU12])
2012-07-31 00:00:00+00:00 29.81 Future(1025201208 [VXQ12]) 29.34 Future(1025201209 [VXU12])
2012-08-01 00:00:00+00:00 29.48 Future(1025201208 [VXQ12]) 28.87 Future(1025201209 [VXU12])
2012-08-02 00:00:00+00:00 28.03 Future(1025201208 [VXQ12]) 27.99 Future(1025201209 [VXU12])
2012-08-03 00:00:00+00:00 25.78 Future(1025201208 [VXQ12]) 26.22 Future(1025201209 [VXU12])
2012-08-06 00:00:00+00:00 25.41 Future(1025201208 [VXQ12]) 25.55 Future(1025201209 [VXU12])
2012-08-07 00:00:00+00:00 26.44 Future(1025201208 [VXQ12]) 26.64 Future(1025201209 [VXU12])
2012-08-08 00:00:00+00:00 25.18 Future(1025201208 [VXQ12]) 25.60 Future(1025201209 [VXU12])
2012-08-09 00:00:00+00:00 24.81 Future(1025201208 [VXQ12]) 25.21 Future(1025201209 [VXU12])
2012-08-10 00:00:00+00:00 24.51 Future(1025201208 [VXQ12]) 25.07 Future(1025201209 [VXU12])
... ... ... ... ...
2012-11-01 00:00:00+00:00 18.14 Future(1025201211 [VXX12]) 19.21 Future(1025201212 [VXZ12])
2012-11-02 00:00:00+00:00 19.05 Future(1025201211 [VXX12]) 20.07 Future(1025201212 [VXZ12])
2012-11-05 00:00:00+00:00 19.42 Future(1025201211 [VXX12]) 20.34 Future(1025201212 [VXZ12])
2012-11-06 00:00:00+00:00 18.30 Future(1025201211 [VXX12]) 19.53 Future(1025201212 [VXZ12])
2012-11-07 00:00:00+00:00 20.18 Future(1025201211 [VXX12]) 20.99 Future(1025201212 [VXZ12])
2012-11-08 00:00:00+00:00 19.86 Future(1025201211 [VXX12]) 20.92 Future(1025201212 [VXZ12])
2012-11-09 00:00:00+00:00 19.91 Future(1025201211 [VXX12]) 21.04 Future(1025201212 [VXZ12])
2012-11-12 00:00:00+00:00 18.30 Future(1025201211 [VXX12]) 19.74 Future(1025201212 [VXZ12])
2012-11-13 00:00:00+00:00 18.14 Future(1025201211 [VXX12]) 19.64 Future(1025201212 [VXZ12])
2012-11-14 00:00:00+00:00 19.00 Future(1025201211 [VXX12]) 20.50 Future(1025201212 [VXZ12])
2012-11-15 00:00:00+00:00 19.27 Future(1025201211 [VXX12]) 20.61 Future(1025201212 [VXZ12])
2012-11-16 00:00:00+00:00 18.20 Future(1025201212 [VXZ12]) 19.85 Future(1025201301 [VXF13])
2012-11-19 00:00:00+00:00 16.60 Future(1025201212 [VXZ12]) 18.70 Future(1025201301 [VXF13])
2012-11-20 00:00:00+00:00 16.35 Future(1025201212 [VXZ12]) 18.05 Future(1025201301 [VXF13])
2012-11-21 00:00:00+00:00 16.45 Future(1025201212 [VXZ12]) 18.30 Future(1025201301 [VXF13])
2012-11-22 00:00:00+00:00 NaN Future(1025201212 [VXZ12]) NaN Future(1025201301 [VXF13])
2012-11-23 00:00:00+00:00 15.85 Future(1025201212 [VXZ12]) 17.70 Future(1025201301 [VXF13])
2012-11-26 00:00:00+00:00 15.60 Future(1025201212 [VXZ12]) 17.35 Future(1025201301 [VXF13])
2012-11-27 00:00:00+00:00 16.14 Future(1025201212 [VXZ12]) 17.80 Future(1025201301 [VXF13])
2012-11-28 00:00:00+00:00 15.50 Future(1025201212 [VXZ12]) 17.30 Future(1025201301 [VXF13])
2012-11-29 00:00:00+00:00 15.20 Future(1025201212 [VXZ12]) 16.95 Future(1025201301 [VXF13])
2012-11-30 00:00:00+00:00 15.55 Future(1025201212 [VXZ12]) 17.10 Future(1025201301 [VXF13])
2012-12-03 00:00:00+00:00 16.35 Future(1025201212 [VXZ12]) 17.64 Future(1025201301 [VXF13])
2012-12-04 00:00:00+00:00 16.50 Future(1025201212 [VXZ12]) 17.75 Future(1025201301 [VXF13])
2012-12-05 00:00:00+00:00 16.05 Future(1025201212 [VXZ12]) 17.35 Future(1025201301 [VXF13])
2012-12-06 00:00:00+00:00 16.38 Future(1025201212 [VXZ12]) 17.62 Future(1025201301 [VXF13])
2012-12-07 00:00:00+00:00 16.00 Future(1025201212 [VXZ12]) 17.20 Future(1025201301 [VXF13])
2012-12-10 00:00:00+00:00 16.00 Future(1025201212 [VXZ12]) 17.05 Future(1025201301 [VXF13])
2012-12-11 00:00:00+00:00 15.55 Future(1025201212 [VXZ12]) 16.50 Future(1025201301 [VXF13])
2012-12-12 00:00:00+00:00 16.14 Future(1025201212 [VXZ12]) 17.10 Future(1025201301 [VXF13])

118 rows × 4 columns