April 20, 2016
After doing the long-term simulation described in my last article. It was time to open the black box and analyze what was inside. What follows is my analysis of the strategy presented in the previous article and I will reference it often. I want to extract what went wrong in that trading script to make it lose when without really trying it should easily have won the day, meaning that it could have ended positive, even if not by much.
Over this 10-stock 20-year testing period, the DOW went up from 4,485.20 to 17,556.41! There were a lot of opportunities to make a buck. The most simple solution would have been to make a bet to the upside from the start and wait. Thereby saving oneself all the aggravation of continuously monitoring and registering losses, letting the portfolio's equity erode, almost trade by trade, for as long as a trader was ready to bear it.
Comparing chart #2 to chart #1 in the previous article should be enough to make the point that the Buy & Hold scenario had a more positive outcome.
The tested strategy should never have been considered a viable solution had the author really done his job. He would surely have noticed the same things I did. It could not survive, it was not that it would break down with time, it was designed so poorly it would be unprofitable from the start, no matter what.
This was not intended or even searched, but this strategy turns out to be a variant to a MACD theme camouflaged in layers of code. I've already covered such a basic scenario in the Stock Trading Strategy Experiment, where it was shown that the MACD had no value and could barely stay afloat over the long term. Whereas in this case, the strategy lost, as if it was all it could do. There are reasons for this, but most of it is centered around a badly designed trading strategy that was made to fail. It had no chance to finish ahead, absolutely none.
To gain a better understanding of the trading script, I started by adding code enabling me to analyze different aspects of the program without changing anything related to the trading methodology. This way I would be able to see better what was going on inside the black box and conserve the program's core, just as the author had designed it.
It is complicated to see what an author has in mind when writing his program when all you consider is the code. A line of code does not give what the intention of the programmer was. It is just an instruction to do stuff which might, or might not, have far-reaching implications or consequences.
I see a trading script as an expression of what a person thinks is a solution to the trading problem and is, therefore, part of his mindset, part of an overall understanding of the trading process. It might be only a part of the author's vision, but it is what he accepted and promoted in his book as a winning method of play. I don't want to criticize the author, but the strategy was put in public view, as such became almost public domain, and open to scrutiny.
I added code to plot the equity line and additional curves to see how the program behaved in time. Then started analyzing what was in the trading procedures for it to lose so miserably. I did not make any code modifications that could affect performance results in any way. All trades occurred at exactly the same dates and exactly the same prices as per the original program.
I centered my investigation on ABT, the first stock in the list. It is sufficiently representative. ABT had a 10% CAGR over the last 20 years compared to the DOW's 7%. So, there was a built-in edge, an upside bias, that could be seen after the fact. Stocks like ABT 20 years ago could have been part of the selectable stocks for someone wishing to build a long-term portfolio. And this made ABT a reasonable candidate for this 20-year test.
There are a few deceptions in the code, see them more as camouflage attempts. One, in particular, stood out early as of immediate concern since it looked ahead (peeked) at future price data to paint the screen. This way one would have the impression, from looking at a price chart, that the author had a pretty good algorithm to detect short-term peaks in price. This can be seen in chart #3 as the blue carets (^) above the price line, and the vs below it. At first sight, it was something that caught my attention, the number of relatively well-placed decision points. I had a let's see how he does it attitude, hoping it might come handy, prove useful and maybe "potentially" profitable. But, it was not the case. There is no value in peeking ahead, the future won't let you do that anyway.
Nonetheless, since these blue caret and v marks are not used in the trading procedures, there is no peeking at future prices to determine what trading decision was to be made today for execution tomorrow in this EOD (end-of-day) trading strategy. That is a relief. At least, there was no cheating there.
Regardless, chart #3 does give a better impression than what actually was. And if the author ever mentioned how well placed his caret tops and v bottoms were, then one should not use the word deception, nor camouflage for that matter. There might be one advantage from the deception, namely, it would be difficult to reverse engineer the trading procedures used to generate the carets shown on the price chart using conventional methods. Peeking to see the price ahead in a simulation does not have the same value as trying to predict what might be a future price. The last mentioned might be realizable going forward, the other not at all.
In order to give the program a chance, I tried different position sizing methods, varying either fixed bets or percent of equity. To no avail, you simply lost, it was only a matter of how fast and how much.
Was left the investigation of the trading procedures themselves. Either the entries, exits or both were badly timed. This would depend on the trading logic and indicators used to trigger the trades.
An early disappointment was to see that after some time, the program stopped trading altogether. It can be seen in report #1 as a disproportionate number of stocks losing about the same dollar amount. After losing about $50k, they just stopped trading. Meaning that if you had let them trade more, they would have lost more. So what is seen in chart #1 is a limiting scenario: each stock looking to lose up to about $50k and then stop trading. Chart #4 has the performance summary report on ABT. You lost less than you should have does not make it a profit. This is not a consolation, it is still a loss. And in this case, an almost assured loss.
The program has what the author called an Awesome Oscillator. It is the histogram labeled AO in the first chart pane below the price in chart #3. However, when you unravel the code, what you find is a simple moving average divergence routine. The equivalent of a MACD to be more precise. Someone looking at the carets on the chart would think that the output of the routine could, in fact, be awesome. But, as said before, that was just camouflage, deception, yet, it is what caught my attention at first as in oh, this could be interesting. It is not the only deception in the program.
All the trading procedures (entries and exits) are contained within 40 lines of code out of the 240 for the program. After having defined a buying zone as the rise of the MACD and its signal line, it checks for the MACD turning up to initiate a buy at stop determined by the high of the day. Since it is an EOD system, this is perfectly admissible. A buy at stop will only be executed the next day if the stop is reached, making it a conditional entry. Another buy at stop will be initiated the day after the MACD crossing zero which is the same decision point as a moving average crossover system. Therefore the system will initiate a buy each time the MACD starts to rise from under zero, and at its zero crossing which usually does not happen at the same time. So no problem at all with entry rules.
The program will do the same for the short side each time the MACD starts to turn down when above zero, it will short at stop, then will do it again at the zero crossing. This too is admissible. They are just entry points. And this way one is assured of a lot of entry points up or down. In fact, there will be entries at every short-term price swing. It will act like an erratic system and if based on the blue carets could have been interesting, except.
What is important, however, is how trades will be managed after entry. Notwithstanding, some questions should have been asked: Why the double entry? And on what basis was it justified, especially in this program? Were the exits rules appropriate? Did they make sense?
The answer to that is not provided. Since the MACD is an oscillator, making an entry at maximum divergence and then again at the zero crossing does not remove the possibility of a profit. In either case, the price only needs to rise (for longs) or fall (for shorts) after entry to make a profit. Therefore, the exit decision time for each trade becomes of importance.
For those that like the mean reversal thing, that is what is attempted here. The program buys or shorts right after the local maximum MACD divergence has been reached in the hope of making a profit when the price will revert to the mean. This, only if it does it before the program exits the trade for other reasons, which it often does.
There is this novice move in the author's program. He does not consider that his trading logic pairs are not mutually exclusive, he allowed them to overlap. Meaning that his trading logic might consider entering a trade but will get out of it on the same day because some other decision point has also been met. And this is why he loses money, at least most of it. A bad strategy design. A bad understanding of what he was really doing. I would say: a novice play, to be polite.
A reason why he lost was not providing his entries with enough time to generate a profit. He used his maximum MACD divergence as a short-term predictive tool. About 80% of his trades lasted less than 5 days, with about half lasting only one day where most of the losses were generated (long or short).
But it is not the only shortcoming. The program gets whipsawed all the time. On many trades, the loss is guaranteed. The exits are controlled by an 8 period EMA offset by -5 which gives the decision point to what the average price was 5 days prior as if this had any predictive powers. Well, it does not, in this case, it just made sure that you would lose often.
Another reason for losses was a poor shorting method. Some two-thirds of the losses were generated by shorts. The overlapping logic occurred there too. A lot of the shorts were for a single day. A lot of the trades were short-circuited. A small sketch on a napkin would have shown this. On this one, the author of that program was shooting himself in the foot, and not realizing it puts him at the novice level at best.
My general impression, after looking at the overall program, I could only reach the conclusion that it was a piece of programming, with limited understanding of what it really did, otherwise, it would have been programmed somewhat differently and better. It is hard for me to pass such a severe judgment on someone else's work, but then again, I consider the author somewhat responsible to those that touched that program and lost money. They weren't buying that book to lose their trading accounts, they had put their trust in that author. And from what I saw, it taints, at least for me, whatever he has to say on trading or whatever other trading strategies he might want to make public. It was a really poor job that could cost unsuspecting users their trading account. Would I recommend such a trading program? Not at all, not even for "educational" purposes.
May I say again, please do the long-term tests required to see if your trading strategies can at least survive over the long haul. After all, it is your money, you don't have to give it away. Well, at least, not that way.
One could say, extract the trading rules and do it by hand, make it a discretionary trading system now that it has been tested. Why would anybody want to do that? To me, that program really shows that debugged is not enough!
Can the program be improved upon? Yes, but, is it worth it? A lot of the code is redundant like the redesign from scratch of the MACD, functions are defined but never used, functions taking up space when a single line of code would have sufficed, not to mention the use of always true conditionals. It would be preferable for someone to design a totally new strategy than trying to salvage this one. I know it is a harsh appraisal, but it is what I see.
Even if I wanted to modify that trading program and make it profitable over the long term, I would probably end up designing something similar to the program in my strategy experiment, and by doing so would obliterate almost every line of code in the analyzed strategy. This to me would be equivalent to it has already been done, why do it again?
May I suggest you look again at the 5-article series: Stock Trading Strategy Experiment, which was designed using, as a base, a MACD. The trading strategy in the experiment was modified to follow a different trading route. It was given for objective to accumulate shares for the long term and trade over the process. And that alone was sufficient not only to survive over the long haul but to also outperform the averages. I think about any trading strategy could be modified in this manner.
In the end, it really is up to you.
Created... April 20, 2016, © Guy R. Fleury. All rights reserved.