August 27, 2016                                              Updated

The chart below is a simplified model of the SMRS where I've idealized market swings based on the setup premises in the trading program. The strategy's source code is available on the Quantopian platform and referenced at the start of Simple Stock Trading Strategy I. Further test results on some modifications to the program with their explanation can be found in Simple Stock Trading Strategy II. Note: Quantopian shut down in 2020; therefore, the strategy is no longer available.

   #  SMRS  -  Simplified Model

SMRS Model

(click to enlarge)

In the above chart, the yellow-green line plays the role of SPY in the original program. The green sections are for when trading windows are open for business where the program is allowed to buy and sell stocks. The yellow lines are for when one would be in bonds or cash equivalents. At line crossings (white circles), the strategy switches from one to the other.

From the look of the chart, there do not seem to be any structural flaws. It all appears reasonable and logical. Basically, it is a simple decision surrogate system responding to an index moving average crossover. All that is asked from a stock is to be part of the highest momentum stocks from a list of the 3,000 highest capitalization stocks and then be at a higher price than a year ago while the fast-moving average is above the slow one (green line segments). One can buy at any time the green light is on. (More details in Part I and Part II of this article).

The first "flaw" I see in such a design is that it guarantees losses at the closing trade window with its exit of all stocks as its drawdown protective measure. Some might view it as a global and portfolio-level trailing stop loss, but it is more. All the positions in all the stocks that were bought above this exit point will have to declare a loss, all of them, even most of those purchased just the day before. And this will occur at every market cycle top.

Part of the benefits of the upswing are lost since all those losses have to be paid for. If you initiated ten or a thousand+ positions above the exit point, all those positions will suffer a loss. Their only escape would be to not make the list prior to the exit, but by doing so, they would already show they were weaker than the other 2,999 stocks on the list. This does not assure a profitable exit.

Depending on where you want to put this "exit all stocks" point, the overstay bill will be commensurate. I also see all this time wasted waiting for that "exit all and switch" crossing, which comes in more often than it might be needed. The method is subject to many whipsaws in its present design. Each time, paying more and more in commissions just to alleviate one's fear of a possible extended drawdown.

One possible advantage, nonetheless, is that the strategy will not be in stocks during yellow line periods when stock prices, on average, are down, at least lower than the exit all point. There are still drawdowns mind you, but no major portfolio bear market here, no 50% drops in a week kind of thing. The strategy simply won't be in the market when they come, if they come, and as such, represents an interesting protective measure, although an expensive one. The trading method will spare one from that market drop, whether they like it or not.

You don't expect much during the bond periods (yellow segments), but at least this might preserve accumulated capital to a certain extent. There was no need to implement a stop-loss policy on a stock-by-stock basis; the exit of all positions at the line crossing acts as a supersized portfolio-level trailing stop loss. It will exit all positions whether they are profitable or not.

While in stocks, you are bound to catch the upward drift since, in general, stock prices go up when the average is going up. You are bound, as if almost by default, to make some profits in the process, especially in the up-cycle phase of the green line. However, you have a reduced market exposure, being in stocks only during those green segments. Your added return will have to compensate for the reduced exposure by working harder. Notwithstanding, that part of the exposure is not to your advantage.

There was no need to buy anything above the close-all trading window crossing price. Maybe this is where the second flaw resides. All those trades done above the liquidate-all crossing were done while the market was presenting the highest number of positive candidates and trade opportunities. Meaning that those trades were taken when the supply of candidates was at its highest and that their respective prices were at their highest as well. There is buying at all the highest tops that the strategy could find or was allowed to trade. At or near the top, the strategy still acts as a built-in breakout system (even buying up gaps) and then hopes to make a buck on that. May I burst that balloon!

At the bottom of the price curve, where one would be interested in buying, the method offers the least number of potential candidates (most stocks are falling), and the strategy remains in bonds. The stock selection criterion requires that stocks rise above their year-ago price before being considered as a potential trade: p(t) – p(t-252) > 0.

So, from the start, when the trading window opens, one has fewer available candidates. It is when the market's average price rises that more candidates emerge, offering more and more opportunities. Except that from an unspecified upper price point (you will only know it after the fact), all the trades you will have taken were already marked for a loss, even if you didn't know it at the time.

Some might wonder why the original system was not making that much money. May I say it actually was designed to shoot itself in the foot in this way. One might keep some of the underlying principles where there might be some hidden benefits and modify the code to trade better. But, maybe the best thing might be to simply redesign it.

For starters, why not make some structural changes?

First, look at the top of the green line prior to reaching the close trading window point. The trades above that point will all be at a loss when liquidated. Since this closing happens on the fast-moving average crossing the slow one from above, there is an implied delay, meaning that the crossing happens relatively late from a recognizable top. It will depend on the path taken to reach the stop-loss point. The slow-moving average is for 252 trading days, and the delay on that one is 126 days (half the length of the average). Thereby, the signal being taken is based on price information that is 6 months old. One should find ways to eliminate most of the top section of the curve above the exit-all point or move the closing point higher on the curve, reducing potential damage and also doing this without increasing whipsaws.

At the bottom of the price curve, prior to opening the trade window, the same kind of problem as seen at the top is occurring. The section of the curve that has the most available potential for profits is not even touched. One will remain in bonds or cash equivalents until the trade window opens. So, ways should be found to open up that section of the curve. But there too, the open window has a built-in delay, with its triggering mechanism responding to old and stale price data.

My next step, and probably the very first one, will be to improve the stock selection process to present more and better upside opportunities at the bottom of the curve and try to find ways to hold on for longer periods since average prices would be on their way up.

There are more things to do, but I will start to work on these until I have debugged trading procedures before moving on to the next phase. What I expect is that after all the modifications are coded and debugged, nothing of the original program's intent will be kept as very little of the original code will manage to survive the transformation except maybe the general Quantopian structural template for program design. 

Added: August 28th.

The objective is to transform the above chart to operate differently. 

The chart below depicts what could be the ideal configuration (more or less) of such a transformation. Like any model, it is an idealization. 

The backdrop is the same as for the chart above, with the yellow line serving the role of the SPY. The SMA (simple moving average), in this case, is of little use. 

The green and red segments are considered acceptable trading zones, serving as open trading windows. What is left of the visible yellow line are viewed as non-trading zones, necessary barriers for prices to cross to ensure a Δp > 0. Based on the model below, this could be achievable for all the trades should the trading activity be limited to their respective zones.

   #  SMRS  -  NEW Simplified Model

SMRS NEW Model

(click to enlarge)

The main idea is to gain the ability to average in and out of positions within their respective open-for-trading windows. The yellow dots represent incremental buys, while the white ones are for the scaling out of the portfolio's existing inventory. 

In such a schema, all trades can turn out to be positive. Sure, the price could go higher after having sold all the inventory. You would be totally in cash, or cash equivalents, at what could be considered a cycle top. But, wasn't that the main objective of this SMRS trading strategy, as is for many others, to switch to safety, to cash, for when general prices decline? 

This design would greatly alleviate some of the problems presented by the SMRS. It would open up the initial price rise segment at the bottom of the curve. Maybe most importantly, it would stop buying all the way to the top and then some to then declare all those trades taken above the stop loss as losses by executing its global stop loss at the SMA crossing. 

The above chart also helps explain some of the transformations I've done to the program (see previous two parts of this series). 

Such procedures have been discussed in my book on trading mechanics.


Created... August 27, 2016,   © Guy R. Fleury. All rights reserved