Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
List of all S&P 500 stocks

Does anyone know how I can quickly create a Python list of all S&P 500 stock sids?

I want to iterate through a large, broad population of stocks without having to manually write out each sid.

Also, is there anywhere I can reference the entire universe of available stocks in Quantopian and their respective sids?

5 responses

I think the limit for manually defined sids in Quantopian is about 100.

I provided an example using the S&P 100 in another thread on this topic.

https://www.quantopian.com/posts/s-and-p500-constituents

Thanks Dennis.

Am I able to adjust this list while the algorithm is running to avoid survivorship bias (as you mentioned in your post)? Or at least a way to view the securities that are constraining my date range?

Right now, my date range is just over a year.

If you have the proper checks in your code (e.g. if sid in data:) then you can add in the sids that don't have data for your entire date range.

Then when you run the backtest it will tell you that not all sids are available for the date range. You can then turn off date range checking.

If you're in daily mode, you can use set_universe to reference 10% of the entire universe, or roughly 800 stocks. I believe the limit in minute mode is 2% of the entire universe. Not sure if that helps, but that's a way you can work with a lot of data at once.

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.

@Gus, the default DollarVolume universe is essentially random compared to picking the S&P 500.