Portfolio Design

Advanced concepts in stock investment portfolio design.  Fundamentals, technical analysis and many other related topics are discussed.

Sector Rotation And Market Timing Combined Part 3 - A New Market Timer

In Sector Rotation And Market Timing Combined Part 1 and Part 2, the Market Wheel was introduced and nine custom series were created. If you have read part 1 and 2, and built the custom series, then you are prepared for Part 3.  If you haven't done so then please go back to Part 1. In Part 3, a new market timer is built based on the sector rotation Market Wheel.

Stock market analysis fueled by Portfolio123.


Sector Rotation Market Timer Theory

In order to make this system a bit easier to visualize, I have drawn the Market Wheel with 9 spokes, each one representing a sector valuation, valuation being represented by Income Yield (Income Available to Common / Market Capitalization). In the ideal case, during a bear market spokes SP5-SP9 are rising, while SP1-SP4 are falling. For the bull market, SP1-SP4 are rising, while SP5-SP9 are falling.

Market Wheel for bull and bear markets showing direction of sector aggregate valuations

Market Wheel for bull and bear markets showing direction of sector aggregate valuations

But conditions are never ideal, the sectors don't behave exactly according to the Market Wheel. So compromises are made, ideals broken, and things are simplified.  To make a long story short, this market timer assumes that if more sectors in the bear camp (Energy, Staples, Healthcare, Utilities, and Financials) have rising aggregate valuations than those sectors in the bull camp (Discretionary, Technology, Industrials, and Materials) then a bear market is in place and you want your money on the sidelines. On the other hand, if their are more sectors with rising aggregate valuation in the bull camp than the bear camp, then a bull market is in place, and you should be fully invested. Remember from Part 1/2 that Energy is thrown into the bear camp and Discretionary into the bull camp because this strategy is anticipatory. The idea is to produce a leading indicator as lagging indicators are of limited use.


In order to detect rising and falling sector aggregates, nine custom series have to be constructed (done in Part 2), representing the aggregate valuation for the nine sectors. The rising / falling algorithm will be implemented within the ranking system. The "rising' formula that will be used is EMA(10,0,GetSeries"....") > SMA(50,0,GetSeries"....").  Note that the custom series is rebalanced weekly, thus the moving averages are processed using weekly time units.  If the result of the formula is TRUE then the sector valuation is considered to be "rising".  If it is FALSE then the sector valuation is considered to be "falling".

In the formula to determine the bull/bear signal, the sector valuations will not be weighted equally.  The central sectors will have a higher weight than the fringe sectors.  The algorithm used will be:

(SP1 + 3*SP2 + 3*SP3 +SP4) / 8 - (SP5 + 3*SP6 + 6*SP7 + 3*SP8 + SP9) / 14 > 0

This algorithm provides natural smoothing to a non-ideal situation, where sectors are not behaving exactly as expected.

System Construction - Custom Universe

Next are the details for constructing the system. Note that I am not going to list out every keystroke and mouse click as I have done in the past as the posts are getting too long, and the reader should be familiar with the Portfolio123 user interface by now.  If you have troubles following along then review some earlier posts such as Build a Market Timer Using High/Low Beta to get up to speed.

The first item on the agenda is the custom universe. An Exchange Traded Fund (ETF) universe with two ETFs (SPY and SHY) should be created as shown below. SPY is the ETF S&P 500 stocks, and SHY is 1-3Y Treasury Bonds ETF. 

Custom universe for stock symbols SPY and SHY

System Construction - Ranking System

Next, the ranking system has to be created.  The basic structure is shown below. As described in Build a Market Timer Using High/Low Beta, There is a conditional node called Def with logic that can never be true i.e. 0=1. The nodes within the TRUE portion of the conditional node will be the definitions for the Market Wheel Spokes (SP1-SP9), and the MT Indicators (where the new market timer will be deposited).

The FALSE portion of the conditional node generates the output decision, either SPY or SHY based on the state of MT Indicators. The formula used is Eval(NodeRank("MT Indicators") > 50, $SPY, $SHY). $SPY is a custom formula for Ticker("SPY") and $SHY is a custom formula for Ticker("SHY").

High level design of the sector rotation / market timer ranking system

The Market Wheel Spokes node provides the definitions for the nine spokes SP1 to SP9.  SP1 detects rising Discretionary sector aggregate value, SP2 detects rising Technology aggregate value, and so on.  As mentioned before, EMA(10, 0, GetSeries("...") > SMA(50, 0, GetSeries("...") is used for determination of "rising".

The nine nodes SP1-SP9 are declared binary.  Market Wheel Spokes is a summation node.  This prevents the Portfolio123 ranking algorithm from rewriting the binary outputs of the spokes.

Stock market analysis fueled by Portfolio123.

Details of the aggregate sector valuation "rising" binary nodes

The last piece of the ranking system puzzle is the definition of the market timer.  The name of the sector rotation timer node is called Income Yield as shown below.  The formula is:

(NodeRank("SP1") + 3*NodeRank("SP2") + 3*NodeRank("SP3") + NodeRank("SP4")) / 8 - (NodeRank("SP5") + 3*NodeRank("SP6") + 6*NodeRank("SP7") + 3*NodeRank("SP8") + NodeRank("SP9")) / 14 >= 0

Market Timer formula:  TRUE is bullish, FALSE is bearish

This completes the design of the ranking system.

System Construction - Simulation

The simulation should be set up as shown below.  Areas of concern are highlighted by red boxes.

General setup for the simulation

Don't forget to add buy rules for updating the nine custom series.  Set the simulation time period for the maximum allowed for your membership level.

Simulation Buy/Sell rules

Once all the simulation settings have been input then let it run. If you have done everything correctly as per this post then you should get results similar to those shown below.

Simulation Backtest Results

Simulation backtest results

Simulation trade statistics

Modifications for simulating the Market Timer with RSP and IEF

As an experiment, try modifying the system to use S&P 500EW (ETF Symbol: RSP) and 10Y Treasury Notes (ETF Symbol: IEF).

Modified custom universe: Tickers SPY and SHY replaced by RSP and IEF

Ranking system modified for RSP and IEF

Simulation backtest results for RSP / IEF

Trade statistics for RSP / IEF

Risk measurement figures for RSP / IEF

Remember that the work presented in this post has the benefit of hindsight and there is no guarantee that the markets will behave in a similar fashion in the future. There is no guarantee of future profitability.

That's it for Part 3.  Part 4 will describe how to use the spokes SP1-SP9 as part of a powerful sector rotation system.