Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
dynamic universe

why does the following code throw an

def initialize(context):
context.sidid = 24
context.stock = sid(24)

Will be called on every trade event for the securities you specify.

def handle_data(context, data):
log.debug('-----------------------')
for stock in data.keys():
log.debug(stock)

def before_trading_start(context):
context.sidid = context.sidid + 1
log.debug(context.sidid)
sec = sid(context.sidid) <-- throws exception "The sid(id) method takes one parameter"
update_universe(sec)

3 responses

This code works (see https://www.quantopian.com/posts/how-to-create-a-symbol-from-string ):

import numpy as np

def initialize(context):  
    pass

def before_trading_start(context):  
    sid_list = np.random.randint(1,20000,200)  
    update_universe([sid(s) for s in sid_list])

def handle_data(context, data):  
    num_stocks = len(data)  
    record(num_stocks = num_stocks)  
    for stock in data:  
        order_target_percent(stock,1.0/num_stocks)  

Mysterious why yours does not, but there appears to be a solution. No time now, but if you are still stuck, just keep pinging and it'll get sorted out.

Grant

thanks a lot grant. still getting used to python so probably this was/is just a very stupid mistake on my side. I have to take a closer look at what you are actually doing differently.....

thanks again

thanks a lot grant. i am still trying to get used to python so probably this was/is just a very stupid mistake on my side. I have to take a closer look at what you are actually doing differently.....

thanks again