Back to Community
Accessing "Current" Vix Data in the Pipeline

There are already several good posts about accessing VIX data via the pipeline and thanks to those and the examples I've gotten it working.

That being said it would appear from multiple posts that Quantopian currently doesn't have access to the "SPOT" VIX data only the OHLCV through the day. This is an issue for me as the strategy that I've created relies on the value of the VIX at the open of the market each day.

Going forward, outside of quantopian, I can scrape the value to live trade through the day. For backtesting though I'd like to "cheat" and do a forward in time look to grab the VIX open from the next day (which would be available in real life when I'm trading).

I "thought" I could simply create a custom factor to look ahead but it appears to be returning "today's" (actually yesterday's) open value. Could someone please point me in the right direction?

class VixOpenFuture(CustomFactor):  
    window_length = 1  
    inputs = [cboe_vix.vix_open]  
    def compute(self, tomorrow, assets, out, value):  
        out[:] = value  
5 responses

Update: Best I can figure is that there is an built in feature of the pipeline that prevents "look ahead"; love to be proven wrong though. The custom factor below displays the same results as if you used "today" in the compute function.

class VixOpenFuture(CustomFactor):  
    import numpy as np  
    tday = np.datetime64('today', 'D') + np.timedelta64(1, 'D')  
    window_length = 1  
    inputs = [cboe_vix.vix_open]  
    def compute(self, tday, assets, out, value):  
        out[:] = value  

In simulation, by design, your algorithm only has access to data before the moment of computation. Data is fed to your algorithm frame by frame as it becomes available. It's designed that way so that you don't develop lookahead bias in your algorithm. I understand that you're trying to introduce lookahead bias, but it's not a natural act for zipline to permit that.

In research you have access to the entire dataset at any one time, so you can do a lookahead if you really intend it.

In backtest simulation, data you bring in through fetcher can be manipulated in the pre-func to induce (or prevent) lookahead. The data that comes in through fetcher is outside of the Quantopian ecosystem, and does not have the same strongly-implemented lookahead protections.

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.

Thanks for the tip Dan. Just missing one piece, can you please advise on how to trim a single row (top row) from the imported CSV? That will automated everything for me.

    fetch_csv('https://csv',  
              symbol='CSVVIX',  
              date_column = 'Date',  
              date_format = '%m/%d/%y',  
              post_func=rename_col)

def rename_col(df):  
    df = df.rename(columns={'VIX Open': 'open'})  
    df = df.rename(columns={'VIX Close': 'close'})  
    df = df.rename(columns={'VIX High': 'high'})  
    df = df.rename(columns={'VIX Low': 'low'})  
    # Correct look-ahead bias in mapping data to times  
    df = df.tshift(0, freq='D')  
    log.info(' \n %s ' % df.head())  
    return df  

You're asking a pandas question at that point, and I'm not as good at that ;) But I think df.drop(df.head(1).index)might work.

Thanks for the help Dan. Posting my final code below:

fetch_csv('http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vixcurrent.csv',  
              symbol='CSVVIX',  
              date_column = 'Date',  
              date_format = '%m/%d/%y',  
              post_func=look_ahead,  
              header = 1)  
def look_ahead(df):  
    # Introduce lookahead in order to access VIX Open on trading days  
    df = df.rename(columns={'VIX Open': 'open'})  
    df = df.rename(columns={'VIX Close': 'close'})  
    df = df.rename(columns={'VIX High': 'high'})  
    df = df.rename(columns={'VIX Low': 'low'})  
    return df