Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Native code to get vix and vix futures data?

Hi,

Is there any way to get the last day's VIX, first month VIX futures, and second month VIX futures at close other than the code below? Thanks!

fetch_csv('https://www.quandl.com/api/v3/datasets/YAHOO/INDEX_VIX.csv',  
    date_column='Date',  
    date_format='%Y-%m-%d',  
    symbol='v',  
    post_func=rename_col0)  
# Pulling front month VIX futures data  
fetch_csv('https://www.quandl.com/api/v1/datasets/CHRIS/CBOE_VX1.csv',  
    date_column='Trade Date',  
    date_format='%Y-%m-%d',  
    symbol='v1',  
    post_func=rename_col1)  
# Pulling second month VIX futures data  
fetch_csv('https://www.quandl.com/api/v1/datasets/CHRIS/CBOE_VX2.csv',  
    date_column='Trade Date',  
    date_format='%Y-%m-%d',  
    symbol='v2',  
    post_func=rename_col1)  
7 responses

Be ultra careful about look ahead bias when using these sorts of data sets. It's easy to use the VIX close in the morning by mistake. One needs to shift the data.

Yes, I did. I develop the algos in Excel and have been doing that for ever. So I am always careful of lookahead bias.

But, no way to get these using using the fetch function just yet, eh?

VIX and some other volatility indicators provided by Quandl are provided natively. Check them out here: https://www.quantopian.com/data?searchq=CBOE

The last one listed has an example algorithm plus each page has it's own "How to" code block.

These data sets are designed to avoid look-ahead bias in terms of how we surface the data through to the backtester but being careful of lookahead bias is still a good idea :)

Thanks
Josh

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Honestly, I couldn't figure out the code as I am a novice in Python. What would really help me out if someone writes a snippet code that just return the values of the closing vix, vix future 1, and vix future 2 for the previous day. I would really appreciate it if someone writes and shares the code. I am sure a lot of people are doing this already. Thanks much in advance!

Hi quantopian team, please is there any update?
More importantly, is there any chance to have intraday VIX data supported in QP without having to use Pipeline or other more complex solutions?
Thanks,
Angel

Not sure about vix futures 1 and 2 months, but you can extract via pipeline VIX and VXV as proxies for futures 1 and 2 month
Here is example of the code taken from this thread https://www.quantopian.com/posts/vix-trading-algorithm-return-150-percent-a-year-over-past-5-years-but-has-50-percent-drawdown-from-2015-meltdown#584637541379940012000213
My understanding, no other simple solutions at the moment, only pipeline ans fetcher... until Q implements futures support

class GetVIX(CustomFactor):  
    window_length = 1  
    def compute(self, today, assets, out, vix):  
        out[:] = vix[-1]

def initialize(context):  
    pipe = Pipeline()  
    attach_pipeline(pipe, 'my_pipeline')  
    pipe.add(GetVIX(inputs=[cboe_vix.vix_close]), 'VixClose')  
    pipe.add(GetVIX(inputs=[cboe_vxv.close]), 'VxvClose')  
    pipe.add(GetVIX(inputs=[cboe_vxd.close]), 'VxdClose')  
    pipe.add(GetVIX(inputs=[cboe_vvix.vvix]), 'VvixClose')

def before_trading_start(context,data):  
    context.output = pipeline_output('my_pipeline')  
    context.vix = context.output["VixClose"].iloc[0]  
    context.vxv = context.output["VxvClose"].iloc[0]  
    context.vxd = context.output["VxdClose"].iloc[0]  
    context.vvix = context.output["VvixClose"].iloc[0]

Many thanks Maxim, much appreciated. I will debug over the next days the vix data we get from pipe with data I get from another source.
If you backtest this algo since end of 2007 the return is quite astronomical. Even if there's a too high DD, still the return seems too nice to be true.
I'll review it and see if we can find a way to smooth it and have less swings. Many thanks for sharing it,
Angel