Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I get the VIX data from the pipeline?

I've tried using the example given in the docs but it doesn't seem to be working

9 responses

The value for VIX (in this case) and for any data set providing a single data point per day like CPI or the price of gas is attached to each individual security in the pipeline as a column. This isn't exactly elegant, but it works for now. So every security returned in your pipeline has a value for vix and it is the same for all securities for each day.

Check out this other VIX example which uses a different source for VIX: https://www.quantopian.com/data/quandl/yahoo_index_vix

You can replace yahoo_index_vix with cboe_vix.

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.

Is it possible to do an example of use of vix value? Thanks

Here's a little algo I used to test the data originally:

from quantopian.pipeline import Pipeline  
from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline.data.quandl import yahoo_index_vix as vix

def initialize(context):

    # Create, register and name a pipeline in initialize.  
    pipe = Pipeline()  
    attach_pipeline(pipe, 'example')

    pipe.add(vix.close.latest, 'vix value')


def before_trading_start(context, data):  
    # Pipeline_output returns the constructed dataframe.  
    output = pipeline_output('example')

    # Select the top 200 ranking securities and update your universe.  
    context.my_universe = output.sort('vix value', ascending=False).iloc[:200]  
    update_universe(context.my_universe.index)  
    log.info(context.my_universe.iloc[:1])

def handle_data(context, data):  
    pass  

Wath is the difference betwwen "vix.close.latest" and "vix.close"? If I want all values of vix since 1990, should I use vix.close?

Is this possible with Pipeline nowadays? Last I checked (a few months ago) it only returned the last row.

Alex, to the best of my knowledge you can set a window_length and get multiple days' worth of data. I'd have to test the behavior on going back beyond 2002. I don't know how it would behave off hand.

Hi Winston, this will get you the spread of the 20 day rolling mean for the high and the low. Unfortunately, it is attached to a list of equities!

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline, CustomFactor  
from quantopian.pipeline.data.quandl import yahoo_index_vix  
import pandas as pd

class VixSpread(CustomFactor):  
    inputs = [yahoo_index_vix.high, yahoo_index_vix.low]  
    window_length = 20  

    def compute(self, today, assets, out, high, low):  
        high = high.ravel()  
        low = low.ravel()  
        mean_highs = pd.Series(high).rolling(window=20).mean()  
        mean_lows = pd.Series(low).rolling(window=20).mean()  
        spread = mean_highs.iloc[-1] - mean_lows.iloc[-1]  
        out[:] = spread

def initialize(context):  
    pipe = attach_pipeline(Pipeline(), 'my_pipeline')  
    pipe.add(VixSpread(), 'vix_spread')

def before_trading_start(context, data):  
    df = pipeline_output('my_pipeline')  
    print df.iloc[0].vix_spread  

You should spot check the results to make sure they are right.

Well, it would certainly be easier to have direct access to index data, as with any equity symbol. I take quite a different approach with my product (see attached). AlphaPy Stock Pipeline

I'm going to make a separate post for this, with a complete example of how to get VIX and the other CBOE indices reliably into algos.