Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Referencing Index or ETF Membership

I'm new to Quantopian and coding.

Is there a way to limit one's security_list to those stocks that are members of an index (such as the Dow Jones Industrial Average) or stocks contained in an ETF (such as XLF)?

For example, if I wanted to run a backtest for a "Dogs of the Dow" strategy (investing in the 10 highest dividend yields in the DJIA), the script would have to first determine that AAPL belonged to the DJIA only after Mar 2015 and that AT&T bounced into and out of the DJIA on such and such dates. Is there a way that I can lookup and filter DJIA membership as if it were an attribute that belonged to Apple, AT&T, and all other stocks? Attribute may not be the right word.

Similarly, if I wanted to backtest a "Dogs of the XLF" strategy, how would one write a script to determine if and when a given stock was included in that ETF? Any help would be much appreciated, thanks!

Incidentally, I don't care about the dividend yield aspect of this - that was just an illustration.

3 responses

Hi Bestin

Did you ever figure anything out with this? I am looking for the same functionality

I wasn't able to figure it out, unfortunately.

For most market-cap based indices or ETFs, you can create a rough proxy by filtering all stocks by the appropriate characteristic and then limiting the list to the top X-number of stocks. If you wanted to roughly create SPY, you could select all american companies and limit the list to the top 500 companies. For XLF, you could limit all financials to the top 65, say. It's not precise but it would get you pretty close to the same constituents.

I'm still at a loss for indices whose components are more haphazardly chosen, like the DJIA. These don't lend themselves to straightforward filtering and I haven't found a workaround. Let me know if you make any progress. Cheers.

Hi Bestin

I ended up doing something similar to you. I was trying to get members of the S&P SmallCap 600. I started with most of the filters from the 'universe_filters' method that is in a lot of the sample algorithms, then I basically started adding filters to my pipeline based on the selection criteria outlined at http://us.spindices.com/indices/equity/sp-600.

Only had to add a few before I was getting around 600 results back.