Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Rotating Aggressive/Defensive ETF Algorithm v. 1.1

Attached is a template for an algorithm that chooses from a basket of securities each month based on the RSI of the selected benchmark security. Shoutouts to both Kayden Cheung and Marcin Wojcik. This code is basically a cleaned up version of code that they both wrote when helping me with my questions.

If anyone has any ideas on tweaking this or how to make it more robust, please let me know! I'll be attaching some backtests (maybe) when I feel like it.

Enjoy!

6 responses

For the sake of completeness, this is another variation of that I experimented with. It uses only a single portfolio, but with a larger basket of ETFs/stocks, I've noticed that it underperforms the split aggressive/defensive version.

The attached backtest is based on v. 1.1 of the algorithm, set to rebalance weekly instead of monthly, and hold two positions in either Charles Schwab Fundamental Index ETFS or Charles Schwab bonds. The international versions of the Fundamental Index ETFs are included in the attached source code, commented out, if you'd like to test the performance of this algorithm with exposure to the global market.

I've also compiled a list of the Charles Schwab ETFs and attached it below for anyone else who is interested in having a quick basket of stocks to experiment with.

"""
Updated:    September 22, 2016  
"""
##### Bond ETFs #####  
##### Bond ETFs #####  
sid(41715), # Core Bond  
sid(39988), # General U.S. Treasury  
sid(39987), # Inflation Protected Bond  
sid(39986), # Short Term U.S. Treasury

##### Fundamental Index ETFs #####  
##### Domestic Equity ETFs #####  
sid(45282), # Schwab Fundamental U.S. Broad Market Index ETF  
sid(45283), # Schwab Fundamental U.S. Large Company Index ETF  
sid(45284), # Schwab Fundamental U.S. Small Company Index ETF  
##### International Equity ETFs #####  
sid(45287), # Schwab Fundamental Emerging Markets Large Company Index ETF  
sid(45285), # Schwab Fundamental International Large Company Index ETF  
sid(45286), # Schwab Fundamental International Small Company Index ETF

##### Market-Cap Index ETFs #####  
##### Domestic Equity ETFs #####  
sid(42043), # Equity Income  
sid(38900), # Large-Cap Core  
sid(39065), # Large-Cap Growth  
sid(39064), # Large-Cap Value  
sid(40709), # Mid-Cap Core  
sid(38899), # Multi-Cap Core  
sid(40708), # Real Estate  
sid(38902), # Small-Cap Core  
##### International Equity ETFs #####  
sid(39144), # Emerging Markets  
sid(38901), # International Multi-Cap Core  
sid(39143), # International Small/Mid-Cap Growth  

The attached backtest is based on a working version of v. 1.2 of the algorithm, and is set to rebalance monthly, and hold five positions in either a selection of Vanguard Stock ETFs or Vanguard Bond ETFs. I will be following this up with a v. 1.0 backtest with the same selection of ETFs for comparison between split aggressive/defensive and single portfolio as well as attaching a quick list of all Vanguard ETFs for further testing purposes.

Attached is the v. 1.0 version of the Vanguard ETF backtest. Interestingly, this goes against what I saw in earlier tests and has a higher total return and slightly lower maximum drawdown then the split portfolio version. The other metrics are unchanged. A complete list of Vanguard ETFs for testing follows below.

"""
Updated:    September 23, 2016  
"""
##### Bond ETFs #####  
##### Treasury/Agency #####  
sid(22887), # Extended Duration Treasury ETF  
sid(33650), # Intermediate-Term Bond ETF  
sid(38984), # Intermediate-Term Government Bond ETF  
sid(33649), # Long-Term Bond ETF  
sid(38988), # Long-Term Government Bond ETF  
sid(38983), # Mortgage-Backed Securities ETF  
sid(33651), # Short-Term Bond ETF  
sid(38986), # Short-Term Government Bond ETF  
sid(43529), # Short-Term Inflation-Protected Securities ETF  
sid(33652), # Total Bond Market ETF  
##### Investment-Grade #####  
sid(38987), # Intermediate-Term Corporate Bond ETF  
sid(38982), # Long-Term Corporate Bond ETF  
sid(38985), # Short-Term Corporate Bond ETF  
##### Tax-Exempt #####  
sid(49366), # Tax-Exempt Bond ETF

##### Stock ETFs #####  
##### Large-Cap #####  
sid(28364), # Dividend Appreciation ETF  
sid(25910), # Growth ETF  
sid(32888), # High Dividend Yield ETF  
sid(25911), # Large-Cap ETF  
sid(35343), # Mega Cap ETF  
sid(35344), # Mega Cap Growth ETF  
sid(35345), # Mega Cap Value ETF  
sid(40107), # S&P 500 ETF  
sid(22739), # Total Stock Market ETF  
sid(25909), # Value ETF  
##### Mid-Cap #####  
sid(23408), # Extended Market ETF  
sid(25907), # Mid-Cap ETF  
sid(32522), # Mid-Cap Growth ETF  
sid(32521), # Mid-Cap Value ETF  
##### Small-Cap #####  
sid(25899), # Small-Cap ETF  
sid(25900), # Small-Cap Growth ETF  
sid(25901), # Small-Cap Value ETF

##### International ETFs #####  
##### International #####  
sid(44850), # Emerging Markets Government Bond ETF  
sid(33486), # FTSE All-World ex-US ETF  
sid(38272), # FTSE All-World ex-US Small-Cap ETF  
sid(34385), # FTSE Developed Markets ETF  
sid(27102), # FTSE Emerging Markets ETF  
sid(27100), # FTSE Europe ETF  
sid(27101), # FTSE Pacific ETF  
sid(40337), # Global ex-U.S. Real Estate ETF  
sid(49785), # International Dividend Appreciation ETF  
sid(49784), # International High Dividend Yield ETF  
sid(44849), # Total International Bond ETF  
sid(40785), # Total International Stock ETF  
##### Global #####  
sid(36486), # Total World Stock ETF

##### Sector And Specialty ETFs #####  
##### Sector And Specialty ETFs #####  
sid(25902), # Consumer Discretionary ETF  
sid(25903), # Consumer Staples ETF  
sid(26667), # Energy ETF  
sid(25904), # Financials ETF  
sid(25906), # Health Care ETF  
sid(26668), # Industrials ETF  
sid(25905), # Information Technology ETF  
sid(25898), # Materials ETF  
sid(26669), # REIT ETF  
sid(26670), # Telecommunication Services ETF  
sid(25908), # Utilities ETF  

No big updates or anything yet, but I've been working on some minor changes and fixes. Have any of you guys who cloned any of the variations above had any successes? Or failures? Please share your results!

Would anyone be willing to help move this over to use only the pipeline and the Q1500US/Q500US universe of stocks?