Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Use if sid() with vairable security id

I am trying to look up the symbol if a security by security ID and it keeps giving me this error:

Error The sid(id) method takes one parameter.

The code is just:

sid(mlh_sid)  

In this case, mlh_sid is the security's sid which is stored in an array.

The sid() function seems to have no issue with me using the drop-down white box in the IDE to select a specific security, however. It just doesn't seem to like me passing it the sid in a variable. Is there any particular reason this doesn't work?

3 responses

Guess, I should have looked for that one before posting. Seems my answer is here:

https://www.quantopian.com/posts/sid-error

Which, by the way, seems like an antiquated "feature" in light of the new pipeline stuff. At this point I would consider it a bug. I'm actually trying to keep track of my purchased securities by reason and storing the sid to do so. This means I cannot place an order to sell them without looking up the symbol by calling sid(). The "best practices" guide suggested we do everything by sid since the ticker symbol can go away and suddenly represent a different company entirely.

Here's an example that may help:

def initialize(context):  
    pass

def before_trading_start(context,data):  
    sid_list = [24,8229,16841]  
    update_universe([sid(s) for s in sid_list])

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

I solved the issue a different way. I switched to using pd.Series to store my data instead of a Python list, and used the Equity object as the index.