Given a list of SIDs, how do I get the corresponding Symbols?
Given a list of SIDs, how do I get the corresponding Symbols?
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.
@André, that's for the algo environment, not for the research environment ;-)