Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to map SID into Symbol in the Research environment?
API

Given a list of SIDs, how do I get the corresponding Symbols?

8 responses

ANSWER: Make sure you're passing in an int to symbols(), not a float :-)

Given an integer constant literal N (not a variable or expression), sid(N) returns a Security object. That object has a field called symbol. For example,

print sid(24)  

should print 'AAPL', if I remember the Apple Inc. number correctly.

That object also has a field called security_name. I like to write things like

context.stocks=symbols ('VTI',  'VOO') # or =[sid(THIS), sid(THAT)]  
prop={sec: 1.0/len(context.stocks) for sec in context.stocks} # equal proportions  
for sec in context. stocks:  
    log.info("Trading {}℅ of sid({}) # {} ({})".format(prop[sec]*100,  
             sec.sid, sec.security_name, sec.symbol)  

where THIS and THAT are Quantopian security ID numbers of VTI and VOO, respectively.

See [https://www.quantopian.com/help][1] and click "Security object" on the left margin.

[1][https://www.quantopian.com/help]

@André, that's for the algo environment, not for the research environment ;-)

Doesn't the research environment use the same Security class?

In any case, you can put the above code in your initialize function, with the ticker symbols you want, pass in handle_data, "backtest" it (in daily mode, over a short date range), and look at the logs.

have you get the answer?

Is there an answer here?
Is it possible to get the sid function into the Research Environment?

Hi Zachary, Andre, and franky:

In the Research Environment:
symbols('AAPL').sid returns the integer 24
symbols(24).symbol returns u'AAPL'
symbols? returns the docstring describing additional parameters