Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How Can I Implement a ETF Strategy Using Sharpe & Pipeline?

Hi there,

I'm new to Quantopian's Pipeline Feature (and still pretty new with FinTech and Python), so bear with me.
What I'm trying to implement (simple momentum strategy):

  1. Take all ETF's
  2. Rank them by their average returns over the last N periods
  3. Rank them by their average Sharpe-Ratio over the last N periods
  4. Rank them by their average rank form (2) & (3)
  5. Go long on the top ten (Not yet implemented)

Currently, my code is a clone of the example posted by Karin Rubin here, modified as far as I got.

Questions:

  • How can I only work with ETFs in a Pipeline? Do I pass a mask to Factor.rank like Karin did?
  • How can I work with Sharpe in Factors?
  • Can I use the Simple Moving Average on Sharpe? (Because that's essentially what I'm trying to do here)
  • Can I use the Simple Moving Average on realtive returns?
  • Some other more specific questions to my code and the API as comments in the source (please have a look)

While the Documentation was of some help, I couldn't find anything regarding ETFs or Sharpe, so any guidance and help is appreciated.

Thanks a lot,
Claas M.

EDIT: I just noticed I forgot to delete the initial comment in the source. Can be ignored.

4 responses

Is there really no straightforward way to only trade ETFs with a Pipeline or am I missing something?

Claas, did you ever get an answer? I want to build my first pipeline algo, and want to select the the top n ETFs based on volume. Once done apply other filters.

I've never seen an example, but maybe I just missed it. One approach would be to get your hands on a list of all of the ETFs that traded over the time period of interest. Then, you could copy the list into the research platform (or an algo) and work with it. Periodically, you could manually update the list.

If you only use a list of current ETFs, you'll be missing the ones that get delisted over your backtest period.

Yahoo includes inception date for ETFs:

http://finance.yahoo.com/etf/lists/?mod_id=mediaquotesetf&tab=tab6&scol=nasset&stype=desc&rcnt=100

I'm guessing that Yahoo has dropped ETFs that are no longer trading...

The first question is what is your definition of ETF? The SEC provides guidance:

http://www.sec.gov/answers/etf.htm

Also FINRA:

http://www.finra.org/investors/exchange-traded-funds

However, I don't see how to get filings/codes from them (e.g. all listed symbols on a given data classified as ETFs). Presumably there is a public database somewhere that would list securities classified as ETFs, without survivorship bias?