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

I want to backtest an ETF rotation strategy with the following characteristics:
- Universe (SPY, TLT, QQQ, IEF, IEI)
- Select only the top 3 ETFs based on the ranking below
- Weekly rebalancing

The ranking system is composed of:

  • if (10-day SMA of SP500 EPS) > (40-day SMA of SP500 EPS) AND (SP500 risk premium) > 1%

    • close(0)/close(5) ranked in descending order, accounting for 70% of the weight
    • close(0)/close(120) ranked in descending order, accounting for 15% of the weight
    • Sharpe 1year ranked in descending order, accounting for 15% of the weight
  • otherwise, if (10-day SMA of SP500 EPS) <= (40-day SMA of SP500 EPS) OR (SP500 risk premium) <= 1%

    • StDev of 5 samples of the most recent rolling 2 days returns, accounting for 100% of the weight

Example for IBM of the past 5 samples of the 2-day returns:
Date Close 2-Day Return
07/24/06 75.99 0.67%
07/21/06 74.86
07/20/06 75.48 1.64%
07/19/06 76.07
07/18/06 74.26 0.94%
07/17/06 73.70
07/14/06 73.57 -2.53%
07/13/06 74.24
07/12/06 75.48 -1.55%
07/11/06 76.47
07/10/06 76.67

Calculate the StDev of (0.67, 1.64, 0.94, -2.53, -1.55)

(SP500 risk premium) calculated as (current Sp500 estimated yield) - (10Y T-note Yield)

I do not know how to test this particular ETF strategy and note sure if all the data is available on Quantopian. Do you have any idea?