Is there a substitute for VXX on quantopian? (I mean something that tracks VIX).
Is there a substitute for VXX on quantopian? (I mean something that tracks VIX).
If you want the actual VIX data best to import it directly from CBOE. Here's some code that will do that (I didn't write this code but I did modify it to source the data directly from CBOE). I believe CBOE updates this at EOD every day but I don't know the actual timestamps for that. This one does it for VXMT instead but to do the VIX you just need to make a few adjustments:
Once you implement this you can access vix data as data['vix'].price
def rename_col(df):
df = df.tshift(1, freq='b') # do this in minute mode only to prevent look-ahead bias, comment out if daily mode
df = df.rename(columns={'Close': 'price'})
df = df.fillna(method='ffill')
df = df[['price', 'sid']]
log.info(' %s ' % df.head())
return df
def initialize(context):
fetch_csv('http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vxmtdailyprices.csv',
date_column='Date',
date_format='%m/%d/%Y',
symbol='vix',
usecols=['Close'],
pre_func=preview,
post_func=rename_col,
skiprows = 2)
@MattClark So this is for RealTimedata is it? how can I get historical data from CBOE for backtesting. You have any code for it?
and I think you didn't post the whole code 'preview' function is missing. can you please post preview function also? Even I am trying to implement a strategy on VXX. I think this can help me.
Suraj - the above code already loads historical data for backtesting (from 2004 for VIX and 2008 for VXMT). It does not load real-time prices during the day as 1) CBOE does not make that data available for free and 2) even if they did, Quantopian does not support real-time import from external data sources currently. So if this were used in live trading, the most recent data you would have access to would be the prior day's OHLC values for these indices.
The preview function just displays the top few rows of the CSV to aid in debugging. So it can be safely omitted from fetch_csv in this case, but here it is regardless.
def preview(df):
log.info(' %s ' % df.head())
return df