Back to Community
Converting SID to SYMBOL in Research

when printing the orders history of an algorithm within Notebooks, is there a way to convert SID to Symbol?

2 responses

Hi Pej,

You can use the symbols function to convert a SID to an Asset object. For example, symbols(24) will return Equity(24 [AAPL]). To get the ticker alone, you can use .symbol -- for example, symbols(24).symbol will return AAPL.

I've attached an example so you can see how this works in practice. Hope this helps!

Loading notebook preview...

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank you Lucy. What I'm trying to do is have the output generated automatically convert the universe of SID's to Symbols. There are approximately 300 SID's which need to be converted and doing each one manually doesn't seem rational. This is the code I'm using:

p = bt.positions[["amount", "cost_basis", "last_sale_price", "sid"]]  
print "date,units,cost basis,last_sale_price,RIC"  
for x in p.itertuples():  
    print x.Index.strftime("%Y-%m-%d")+","+str(x.amount)+","+str(x.cost_basis)+","+str(x.last_sale_price)+","+str(x.sid)