April 1, 2021

This is a follow-up to my last article Basic Stock Portfolio Math. Trying to provide a different look at the inner workings of the In & Out stock trading strategy, which is freely available on QuantConnect, where you can modify it at will. The intent is to show how this strategy is making its money. It should prove interesting. The strategy is composed of only a few parts: a stock selection process, a trend definition section, and a trade execution method. Nothing very complicated.

I examined and tested the 5 published versions of In & Out and some of their variations. Basically, viewing them as templates where the math of the game could provide ways to raise performance almost at will. The strategies still have some weaknesses, but they can be corrected or at least alleviated.

The Scheduled Rebalancing

I concentrated on the fixed-time scheduled rebalancing versions (daily, weekly, or monthly). The ones using Schedule.On(DateRules,TimeRules). My preference was for a 100-stock portfolio using daily rebalancing with its somewhat erratic flusher.

Why put emphasis on this? Because it plays a major role in trade execution. It fixes the times when trades are executed. Rebalancing becomes an administrative decision, independent of market conditions or the state of the program but still a major part of the method of play.

The Trading Signal

One central theme in these strategies is the single composite signal declaring the trend as up or down. It is used as a bond-switcher, a safe haven move for when markets might not look positive.

When the trend is declared up, stocks, ETFs, or a mix are purchased and held till the trend (signal) reverses. At which time, all stocks are sold and bonds are bought as downside protection. Bonds are sold, and stocks are repurchased when the trend switches positive again. You are supposed to be in the market when prices are going up. Otherwise, you are on the sidelines in bonds. Sounds reasonable.

One would conclude that the strategies are highly dependent on the worthiness of the signal. If its accuracy is high, we could advance "overfitting" and be wary. If it was so-so, meaning close to 50/50, then we could claim some randomness, say no better than flipping a coin. And if the signal was wrong most of the time, the "overfitting" contention would fade, as well as the claims to randomness. Only a backtest can answer the question: how good is this signal?

The Flipper or Switcher

On the version I tested the most, I had about 70 flips from stocks to bonds and back. There was no need for more than 10 such flushes. This made the signal wrong some 85% of the time, and yet, the strategy was making money. You could still raise the stakes higher and profit even more. The big question was: where and how did this strategy make its money?

Why 70 flips if only 10 or less were sufficient? Should I improve the signal to make it more accurate? After digging into it more and changing the perspective of what the signal was doing while flipping all over, you come to the understanding that it is not just the flipping that is at play. How can a strategy with 85% of its decisions being wrong make any money? It is simple: it is saved by the side effects of its rebalancing!

Here is what happens. When long, stocks are rebalanced daily to a preset weight (1/j), where j is the number of stocks in the portfolio. Almost every day, partial trades are made. Partial sales are executed on rising stocks while shares are added to declining ones in order to rebalance weights to w_i = 1/j = 0.01 for the 100-stock portfolio.

The chart below shows a one-day price change on a hypothetical portfolio ordered by return from lowest to highest. Day in and day out, the numbers would change, the scale would change, the center of gravity would change, and the order of the stocks would change, but the chart would have the same form (some stocks going up and others going down) even if most moved by only a small amount.

Price Variations From Period to Period
Price variations

In the real world, the curve might be even more pronounced but still have the same shape. Most price variations are near zero, and some with higher prices change at both extremes. Only the stocks above the zero line see some of their shares sold. The partial sales will return the weights to 0.01. The hit rate will be close to 100% since only the stocks that rose could have partial sales. Resulting profits will accumulate in the trading account as the market continues to rise. More profits are taken in maintaining a high win rate on those executed partial trades. At this point, no shares are intended to be sold below the zero line.

The Trade Count

Each time the rebalance is done, the winning trade count increases, and the losing trade count stays about the same. We can see that the hit rate is becoming positively lopsided. It is only at the flushing time when the trend flips that all shares are sold. Shares already at a profit go to increase the winning count, and now the losses are recognized, which adds to the losing count. All this is realized by the rebalancing and the erratic flushing based on the signal flipping all over the place.

At first glance, there appears to be no reason for flipping some 70 times. Sure, the flipping does catch all the significant moments where getting out of the market reduced potential drawdowns. But, it was done at a cost. Each time you flipped for nothing (following what might have been just a dip in the market), you lost some of the accumulated paper profits since the signal was late to tell you the market had turned. And would lose on the potential recovery because the signal is again late to the party. So, the question comes right back: where is this trading strategy making its money? And how can it do it for years on end?

No Defined Stop-Loss

The strategy has no explicitly defined stop-loss. In reality, there are two strategies at play here. One for when the signal is long and one for when the strategy switches to bonds. The portfolio is flushed at every transition. And there lies its portfolio level stop-loss. It acts as a trailing stop-loss on declining stocks and a stop-profit on rising ones.

Time for losses to accumulate is not provided, most of the time it is cut short due to the flushing process. We can see from such a structure that the win rate will be high, not because the system predicted price movements or followed the trend, but due to the mechanics of the rebalancing itself. The rebalancing does not care how or why the price moved or in which direction; it just executes with whatever it is given. It simply returns the weights to 1/j.

The Flusher as a Feature

The strategy has a rebalancer, a switcher, and a flusher. The "flipping" becomes a "feature" that brings with it added costs and higher profits but also serves as downside protection. At each flushing, a new portfolio is built based on the highest momentum stocks at that time. The advantage of the flusher is in getting rid of stocks that continuously decline after having been selected for their high momentum. This can be seen in the average win rate compared to the lower figure for the average loss rate. The losing positions are flushed before they can do more harm.

There was no need for a stop-loss because the flusher was doing that job, even if it was wrong most of the time. The strategy is winning because its signal is erratic, so erratic in fact that it will flip 60 times out of 70 without real justification other than it flipped. This forces the strategy to build 35 new portfolios based on its selection process, which will only depend on the opportunity set available at the time.

Winning By Default, With No Fault of Your Own

The strategy kinds of make money by no fault of its own or your own for that matter. You have a situation where being wrong most of the time turns out to be good. You could consider the strategy as overly cautious, but it makes money, and that is the whole purpose of an automated trading strategy, isn't it? So, add the needed protection to your preferred version for when both the market in general and bonds will be falling, and then you may let it be a winner too.


April 1, 2021, © Guy R. Fleury. All rights reserved.