Back to Community
Defining a universe of SPY and each of the stocks in SPY

How can I define a universe which includes SPY and each of the stocks which makes up the SPY ETF? This is working toward a mean reversion strategy of arbitrage between SPY and its component stocks.

4 responses

I would use the top 500 stocks by Market Cap. It is not perfect, but it will give you an approximation of the SPY.

Is there anything similar that might work for the Russell 2000?

I saw this on wikipedia. " As of 31 March 2017, the weighted average market capitalization for a company in the index is around $2.3 billion; the median market cap is $809 million." You could probably make some type of class factor, and restrict some range in the market cap. The Russell 2000 is the small-cap index. I am not quite sure.


You could use fetch_csv to import index data into your algorithm. This function allows you to import day frequency time series data for both securities and signals. When importing data for securities, the symbols included in your csv file are automatically recognized by the backtester and the data is mapped to their corresponding sid. This way you can use data.current to retrieve the data imported.

The algorithm attached uses fetch_csv to import index constituent data for NASDAQ 100 (I am not sure if the dataset is correct, it is used just as an example). It imports a csv file containing 3 columns: date (required), symbol (required) and event. The date column specifies the date in which the backtester should make the data available. The symbol column is used to map the imported data to the corresponding sid. The event column is used to encode when a security is listed (1) or delisted (-1) from the index. It is worth mentioning that the backtester forward-fills data for missing dates, so this is why the csv file does not need an entry for every single security, for every single date during the backtest.

The ordering logic is simple, the algorithm iterates through the list of securities imported using data.fetcher_assets, filters out delisted securities (event = -1) and divides the available capital evenly amongst the currently listed ones.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 596fa2e718721d4e0ab8fa40
There was a runtime error.

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.