Back to Community
S&C V32.1 pg36 Outperform the Market with Sector ETFs

I implemented the algorithm from Stocks and Commodities Magazine V32.1 page 36 by Todd and Steven Winkler.

Algorithm:
Select worst 3 performing ETF sectors at end of year as measured by Returns over last year
Hold them 1 year
Repeat

Modifications from paper:
If trading starts outside of last day of December buy lowest ranked
Rebalance portfolio on a daily basis because Quantopian doesn't have GTC orders
- It means that if orders aren't filled on day placed they are cancelled leaving an under positioned portfolio
- It keeps leverage at about 1 but it generates more trades (which QT includes commissions and slippage for)

There is also an option to re-rank on a monthly basis. This did not work as well in my backtesting.

I couldn't verify all the backtests from the paper because Quantopian only has historical data to about 2002. However the basic premise of the paper is confirmed and the backtest produces better returns than just holding SPY.

This algorithm however is not for the faint of heart because 50%+ drawdowns can occur.

Cheers,
John

Clone Algorithm
52
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58c30f741cb56b623c9f284a
There was a runtime error.
5 responses

John ,

Interesting findings.
BTW
Calculation of returns over last year require not 252 but 253 data points.
So line 131 should be:

window_length=253,

Vladimir,

Thanks for the comment.

It is correct that I don't use exact number of trading days per year to compute Returns but over the period of the backtest the average trading days were 251.7 per year.

Do you have a reference on why 253 should be used?

Thanks,
John

John,

Rounded 251.7 is 252.
To calculate 1 day return you need today's price and yesterday's price .
To calculate 252 days return you need today's price and price 252 days ago.
Total bars in data window to calculate 252 days return should be 253.

Thanks.

Attached is cleaned up code with:
- Rebalance on leverage too high
- Separate ranking from trading (fixes exit position bug on large portfolios)
- Allow orders to fill for 15 days in January (large portfolio)
- Tries to avoid very small orders on rebalancing
- Returns with 253 day window

Clone Algorithm
52
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58cad81e1b629b1bad4d0969
There was a runtime error.