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

The following sample code is to get historical data for VIX from Interactive Brokers if the user has the subscription to VIX at IB.

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

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 is the historical data obtained on Aug 28th 2017

             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  12.09  12.11  11.23  11.77

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