Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Get VIX value of the current day in backtest

How do I get the VIX value of the current day that I am trading in the handle_data function that is call every minute?

7 responses

Hi David,
You can access yesterday's closing VIX value in your algorithm via this dataset: quantopian.com/data/quandl/cboe_vix

We don't yet provide intra-day values for VIX.

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.

Hi Josh,
My issue is the following, I import the data by doing so:
from quantopian.pipeline.data.quandl import yahoo_index_vix

however I am confuse on how can I access to the current day data in yahoo_index_vix and access it in the handle_data function? (I guess from the previous day value as this would be available to me only one day before trading day)

This is a confusing element of our current implementation with our data partners.

A column is added to your pipeline that represents the VIX value you are using. The value of the column is set for every single stock in the pipeline. So you can get the value for VIX from any row.

In order to access this data in handle_data (or a function that you schedule during the trading day with schedule_function()) you should add the pipeline output to context. Generally, context is meant to store custom data across different functions.

Thanks
Josh

I see, as I am kind of new I was wondering how can I access the actual value of let's say the current trading day for instance how my code will look like if I want to do something like that:
if VIX_YESTERDAY_VALUE < mythreshold_1
buy stock
if VIX_YESTERDAY_VALUE > mythreshold_2
sell stock

Can anyone please just post a code piece demonstrating how to access daily vix data in yahoo_index_vix in algorithm mode (not research mode)? For example, just ploting the daily vix data in the record_var block should be good enough. Thanks.

Here is an example I believe it works

Thanks David, exactly what I am looking for.