Using SPY as a regime switch

A question that we receive with some regularity is "can I run a backtest that changes strategy based on whether SPY is above or below its 200-day Moving Average?"

The answer is yes. We have a group of backtests that switch between strategies depending on the prevailing regime.  These regime backtests build up on the logic of the Ratio MA backtest and come in 2 varieties:

With these two backtests, when the ratio is above its MA the backtest runs the Regime 1 portfolio / RS strategy (i.e. Risk On).  Conversely, when the ratio is below its MA, the Regime 2 (Risk Off) portfolio is chosen.

If, rather than using a ratio, you want to switch strategy based on whether or not SPY alone is above / below its 200-day MA,  then you can use XZERO as the Regime 2 security.

XZERO is simply a zero return index (i.e. it's a constant), so an MA of the ratio SPY / XZERO is the same as a moving average of SPY itself (see the Parameter Summary comparison at the bottom of this post).

 

Regime RS backtest that uses the SPY 200-day MA to determine the regime

Note:  Moving Averages on ETFreplay are calculated using Total Return.  i.e. the calculation does not just use closing prices but also accounts for the receipt and reinvestment of any dividends and distributions.  The MA is then compared to the Total Return value of the ETF, so that it's like-vs-like; everything is Total Return, not just price.

See:

 

SPY MA Parameter Summary on the left. SPY / XZERO Ratio MA Parameter Summary on the right. The backtest returns are the same.

Follow ETFreplay on Follow etfreplay on Twitter