A sample code to show how to get historical data for VIX

How to Get VIX Historical Data

This sample code demonstrates how to retrieve VIX historical data from Interactive Brokers if you have a VIX subscription at IB. Learn how to use IBridgePy to access volatility index data for your trading strategies.

The function of superSymbol ( ) is to define the security.

EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

data.history ( ) has the same signature as the same function at Quantopian.

def initialize(context):
    context.sec=superSymbol(secType='IND',symbol='VIX',currency='USD',
                            exchange='SMART', primaryExchange='CBOE')
   
def handle_data(context, data):   
    print (data.history(context.sec, ['open', 'high', 'low', 'close'], 5, '1d'))
    end()

The following shows how to get historical VIX data obtained on Aug 28th 2017

Need help building this strategy?

Our Rent-a-Coder team builds custom automated trading programs. From simple scripts to complex multi-account strategies — we handle it all.

             open   high    low  close
2017-08-22  12.60  12.94  11.35  11.35
2017-08-23  11.51  12.59  11.39  12.25
2017-08-24  12.06  12.83  11.55  12.23
2017-08-25  12.20  12.45  11.10  11.28
2017-08-28  11.51  11.77  10.56  10.56
EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

Ready to Automate Your Trading?

Download IBridgePy free or let our coders build your strategy.

Download Free Hire a Coder

8 thoughts on “A sample code to show how to get historical data for VIX”

  1. Hi,

    I ran this example code but got error messages as follow:

    #### Starting to initialize trader ####
    ## ACCOUNT Balance DU413327 ##
    CASH=1006518.29
    portfolio_value=1006518.29
    positions_value=0.0
    ## NO ANY POSITION ##
    ## NO any order ##
    #### Initialize trader COMPLETED ####
    IBridgePy.IBAccountManager: errorId = 1, errorCode = 162, error message: Historical Market Data Service error message:No market data permissions for CBOE IND
    IBridgePy.IBAccountManager::check_timer: request_data failed after 30 seconds
    IBridgePy.IBAccountManager::check_timer: notDone items in self.end_check_list
    historyData reqId=1 IND,VIX,USD,SMART,CBOE status=Submitted waiver=False
    IBridgePy.IBAccountManager::request_data: Re-send request info
    IBridgePy.IBAccountManager: errorId = 2, errorCode = 354, error message: Requested market data is not subscribed.
    IBridgePy.IBAccountManager: errorId = 2, errorCode = 162, error message: Historical Market Data Service error message:No market data permissions for CBOE IND

    1. You can supply historical data in csv files for any frequency to backtester. The basic rule is that users know what kind of historical data are needed in the code and supply them.

Leave a Comment