Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Rotating Sector ETFs Based On 15 Day or 1 Month Performace

I've been doing my research, and messing around with some of the various backtests and algorithm examples already posted on here, but seem to be stumped on getting everything working together and playing nicely.

I'm attempting to build a simple (or rather, should be simple) algorithm that tracks a pre-defined (and expandable/shrinkable) number of ETF holdings, ranks them based on their 30 day or 15 day % change, and invests in them at a 10%, 20%, 30%, 40% balance and rebalances monthly without using an leverage.

My target is to use this for Robinhood so that ideally I no longer have to manage my portfolio by hand. Can anyone point me in the right direction on where to get started since the updated tutorials aren't complete yet?

  • Delman
5 responses

Attached is your strategy coded. Every month, it calculates regression slope for every etf in the list. I used the 9 sectors in this example, but they can be replaced with anything.

The etfs are ranked according to their 250 days regression slope and 1st position gets 40%, 2nd gets 30% and so fourth. Included is a risk management logic using 100/200 day moving average RSI (Taken from another post in this forum).

Best to set context.lev to 0.98 or so. At 1.0 leverage, it sometimes holds fractions of a percent above 1 leverage.

Side note: I tested it holding equal weights for the 9 sectors, rebalanced quarterly and it has a better risk adjusted returns.

Edit: Oops, past 250 days price was used to calculate the regression slope in this backtest. 1 month version below

This version uses 1 month lookback to calculate returns and ranking. My original post used 250 days.

Thank you so much! I appreciate you commenting your code. Should it need much rework to be compatible with the Robinhood framework? I will attempt to integrate the two tonight when I'm home.

Apologies in advance for the double post, but does anyone who has seen this thread have any ideas or opinions on how to potentially optimize this strategy any further?

And once again, thank you Kayden for putting my general thought process into code.

How would you make each position equally weighted based on the desired portfolio size rather than individually picking weights and using the list?