Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How can I get the values of VIX and VXV in an algo? To get history on Fetcher call?

Hi,

There doesn't seem to be a sid for vix or vxv. Is there any way to get that? I don't need historical values - I have already backtested the algo. I want to implement it for real trading.

Thanks much for your help in advance!

6 responses

Hi Apratim,

You can use the fetcher function to import any external CSV data to your algorithm. You can use this external data as a signal driving your algorithm or to create your stock universe. We don't have VIX, VXV, and other non-traded index data (yet!) but we'd like to add it in the future.

For previous examples of using VIX data as trade signals see these posts:
https://www.quantopian.com/posts/visualizing-implied-vs-realized-volatility
https://www.quantopian.com/posts/berkshire-class-ratio-as-a-buy-point-indicator
https://www.quantopian.com/posts/tactically-short-gamma-synthetic-via-etfs
https://www.quantopian.com/posts/vix-put-call-ratio
https://www.quantopian.com/posts/system-based-on-easy-volatility-investing-by-tony-cooper-at-double-digit-numerics

Cheers,
Alisa

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!

To, clarify, does this mean fetching VIX, and then running batch_transform to get history?

Or is there a way to feed the fetched data into the newer history function?

# history fn for non-traded indices  
@batch_transform(window_length=200, refresh_period=0)  
def _history(data):  
    return data  

with fetcher, it cant be real time though, I think.

Can I stream data from say quandl to use in my algo in real time? quandl has VIX & other data...

It has to be real time though..

@Monte, you can use the history method directly without needing a batch transform. Batch transform was the first function we created to get a trailing window of data and history was our next iteration. We will be removing batch transform in favor of history. History has faster performance, doesn't require a warm-up period, and returns a pandas dataframe to which you can perform other manipulations. See: https://www.quantopian.com/posts/working-with-history-dataframes

Using your example you can do this:

price_history = history(200, '1d', 'price')  

@Maitreyi, in backtesting your data is fed into the algorithm at the time when its referenced. For example, if you have a row for May 19, it will be passed to your algorithm when the backtest reaches that date to prevent look-ahead bias.

In live trading, we load your fetched file in the early hours before market open. This file cannot be udpated in the middle of the day, or "real-time". It's also important that all historical data in your fetched data be accessible and unchanged because we do not keep a copy of fetched data. If you want to add new data, you should append it to the bottom of the file.

Hey everybody, I've also run into the issue of needing to pull history on fetched data, thought I'd share a workaround.

While you cant get access to future dates within your algo, you can get access to them if you send your imported data to a pre_func via the fetcher. The trick is to do rolling calculations in the pre_func, and append the results to the dataframe as new columns before returning it.

Here's an example, it goes long on the SPY when the 10 day MA of the VIX is below it's 100 day MA, otherwise it shorts it. I import the VIX prices from Quandl and calculate the difference between the rolling means in the pre_func, then append the result as a new column.

I'm sure I don't need to say this, but be careful, this is an easy way to introduce look ahead bias into your algorithm. Be sure to only use rolling/expanding window calculations.

David