Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Convert a list of stock symbols to sid - algo

Does anyone have a more elegant solution (than my algo) for converting a list of stock symbols to a list of sids? Please share it with the community.
Check out the code and the log output for this backtest. Thanks!

Log output:

2015-07-06PRINT[19784, 28667, 48486, 9888, 1078, 40284, 28664, 24532, 38286, 845, 44017, 42531, 24884, 5645, 39782, 23850, 12512, 977, 41978, 915, 25642, 26748, 27369, 45558, 48821, 47510, 21371, 1218, 45880, 42461, 33864, 16169, 26749, 1244, 23857, 1195, 1331, 2034, 47830, 39392, 2514, 25643, 12011, 39052, 1297, 17626, 40180, 1722, 32860, 43421, 16448, 17639, 19962, 1655, 46283, 14700, 41820, 48897, 19056, 32325, 35253, 46241, 24834, 46951, 1577, 1874, 15459, 17358, 33053, 10575, 26876, 17643, 1266, 6267, 15274, 28312, 46551, 47414, 32844, 45980, 1270, 1219, 25313, 33776, 17988, 1375, 19788, 1396, 21342, 10578, 19187, 33648, 42455, 22429, 20961, 33297, 1796, 14484, 1686, 47145, 21603, 16333, 24434, 44764, 44779, 32433, 23109, 13810, 39498, 1485, 1234, 41765, 45847, 26305, 1490, 42474, 40299, 12305, 39041, 1521, 8612, 24789, 44453, 21736, 8613, 43215, 10925, 48932, 16453, 27408]  
2015-07-07PRINT[27674, 24891, 20696, 1882, 27251, 26953, 1552, 1480, 46939, 47717, 1585, 33924, 450, 37775, 1703, 1595, 26079, 38971, 42166, 45453, 19364, 25497, 18865, 1753, 49042, 1374, 23428, 26569, 1751, 48026, 1749, 24474, 49016, 38760, 1755, 18403, 14348, 24793, 1636, 26541, 1313, 16343, 11476, 32622, 23667, 34111, 1675, 43460, 46367, 1706, 1974, 15106, 48256, 25646, 27478, 1964, 13007, 34783, 22382, 46307, 45212, 19203, 1696, 39665, 1942, 26191, 27864, 16341, 33284, 40146, 43036, 46678, 39625, 41098, 1884, 46497, 1995, 12023, 32377, 18542, 1308, 13371, 1843, 21374, 28078, 24893, 21481, 8460, 14354, 1926, 16607, 1971, 43503, 26733, 1979, 1984, 18863, 21863, 2015, 42317, 26157, 1999, 45249]  
2015-07-08PRINT[20490, 7101, 46648, 37336, 22889, 662, 46598, 47842, 9681, 253, 31, 47123, 28471, 15622, 53, 52, 677, 24465, 26322, 19185, 15934, 45431, 26486, 27570, 33310, 39313, 84, 32790, 12616, 28077, 26277, 484, 110, 46722, 153, 38880, 47191, 11718, 48925, 47380, 13777, 351, 40992, 13775, 23176, 40294, 3949, 162, 45733, 46645, 3424, 33194, 47684, 15064, 41669, 21104, 46977, 25486, 11085, 508, 27231, 32475, 10897, 46583, 8586, 247, 24777, 46869, 43060, 332, 283, 39522, 33016, 21975, 22189, 22861, 24389, 21103, 27500, 39552, 45415, 38633, 43712, 33052, 659, 44636, 43495, 46597, 46027, 25392, 35040, 39928, 40707, 19672, 41792, 11086, 25710, 19949, 27998, 44687, 553, 397, 19037, 366, 405, 23575, 11232, 27819, 26845, 33949, 18655, 23178, 47193, 22862, 40442, 311, 47935, 14329, 42175, 26324, 25565, 8910, 13500, 430, 22418, 39270, 18380, 48981, 474, 38759]  
2015-07-09PRINT[24829, 41738, 46634, 24855, 17799, 45503, 35028, 45011, 26998, 49034, 41, 69, 47146, 45200, 21724, 42855, 28450, 6276, 11880, 18027, 44677, 35162, 22192, 526, 10417, 14855, 24761, 2105, 36896, 45796, 25398, 48037, 11999, 40622, 10073, 579, 47325, 10089, 617, 47901, 39942, 610, 28378, 44129, 27532, 14863, 624, 49023, 47422, 42445, 8598, 25265, 13320, 21717, 3189, 694, 33892, 969, 932, 1191, 23943, 8785, 957, 26913, 1028, 22198, 20957, 17264, 27383, 41601, 22093, 17479, 9693, 697, 45797, 9094, 27886, 1117, 42551, 18186, 14469, 26643, 14921, 10728, 18843, 19044, 26479, 48304, 21911, 856, 34229, 45428, 21587, 43476, 20973, 23757, 22657, 22472, 26865, 10905, 23846, 10108, 15525, 1129, 35929, 1144, 15775, 11732, 18803, 913, 26496, 44570, 43283, 20462, 24011, 46505, 47352, 26315, 49000, 46647, 25400, 1016, 27108, 41374, 44089, 49024, 42272, 47980, 24822, 10723]  
End of logs.  

Append the sids to a new list context.stocks = [sids(......)] and it's all good and ready to go.

2 responses

Hey Adrian,

Try this little code snippet out..

https://www.quantopian.com/posts/how-to-easily-convert-symbols-to-sids

Disclaimer

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, James!