Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Creating a Universe of all of the stocks in a single index?

Can I create a universe with all of the S&P 500 for instance without actually having to name all of the SIDs of the constituent securities?

5 responses

Hey James,

There is not a very direct way to create a universe with all securities in an index. If you want a strategy that replicates the index, you can get exposure through an ETF on that index. One way to approximate the universe of the S&P 500 is to use Quantopian's set_universe() function and set the universe to the top x% of stocks by market capitalization. If you have a list in .csv form of the stocks that are in the index, you can perhaps use fetcher to parse the file and add the relevant SIDs to the universe.

Best,
Ryan

James, Ryan,

We have something new that allows this, as well as coding custom universe(s) with external data. We're working up an example to post here for the index. Stay tuned!

thanks,
fawce

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.

Hi James,

Take a look at the example I posted in this thread just now: https://www.quantopian.com/posts/define-custom-universe-via-fetcher-using-the-new-universe-func-callback

If you're working with minutely backtest data we cap you at 200 securities I believe, so you need to pull in the SP500 and then pass only a subset on to handle_data. In the example I posted I winnowed the universe down by selecting just a single sector (financials).

Hope this is helpful, let me know if you have any problems getting this working for you!
Best wishes, Jess

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.

This works perfectly for me, however is there a way for me to get quantopian to ignore the 'date' column if I just want to look at these sids since the beginning of time?

Hi James,

We need the date column to figure out what portion of the csv to pass to the callback, and when to invoke the callback. If you make the value of the date column equal to the first day of your simulation, the universe callback will be called once, and the universe will remain the same for your whole test. Just beware survivorship bias in indices!

thanks,
fawce