July 3, 2015

One of the hardest parts of managing a stock portfolio is designing a workable and profitable long-term trading strategy. It needs to be based on sound principles and provide a foundation as to how it will handle an unknown future. Trading automation presents an added dimension to the problem.

One could go live based on some concept or other and see how the conceived trading protocols would fair out over time. This could be a very expensive way to test if an automated trading strategy has merit or not, not to count the amount of time and money that could be wasted with nothing to show for it except for a notice to go back to the drawing board.

A better solution is to do some backtesting where the cost is only the time spent developing a trading script and testing how it would have faired over some past market data. And then decide if the strategy is worth it or not. At least you would have some data to analyze to corroborate the methodology used.

The backtest duration will suddenly become important. A one or two-year backtest on a single stock cannot be considered significant. It's not enough time, not enough stocks to show what markets are capable of. Portfolio management is a long-term endeavor. It's not an overnight operation. Even HFT firms have a long-term vision of things. They intend to survive and prosper for a long time.

While a Buffett-like trading/investing strategy does not require to be backtested even if it could, it has proven itself to be a long-term (50 years) and successful discretionary portfolio management methodology. You automate because you want more than a Buy & Hold and intend to have your computer do all the work and calculations for you.

Automated trading strategies can go from HFT (high-frequency trading) to very slow trading scripts. In the first case, to provide speed of execution to a large number of trades where the profits are measured in pennies per share with trading intervals as short as a few microseconds. In the second case, automation is used more as a procedure accelerator where time is not that critical; the machine is there to make all the calculations and follow its trading script.

But both strategies, at each extreme, should be designed in such a way as to be coherent with their respective time frames. In the very short term level, as in HFT, you are not developing a variation of a Buy & Hold strategy. It would appear as a contradiction in purpose.

Maybe the point to be made is that whatever trading strategy one wants to develop, a total understanding of its purpose and trading environment is required. Everything should be consistent and coherent within the methodology used. HFT and Buy & Hold are not synonyms, not in stock trading anyway.

More Testing

Last month, to answer some questions on stock selection, I performed a backtest on 10 stocks to show the merits of a particular trading script. The selection criterion was that none of the stocks would have been tested before and that they should have been part of a larger pool of selectable stocks 10 years ago.

This would make the test an out-of-sample test using out-of-sample stocks. Stuff the program has never seen before. It would have to confront all new price signatures, all with their own unique paths. No over-optimization or curve fitting was available. Just some code designed to extract what it could, if it could.

Here are the 10 selected stocks, over a 10-year interval, using a $10k trading unit:

ABT – 10 years

ABT 10 years

(click to enlarge)

ALL – 10 years

ALL 10 years

(click to enlarge)

BIIB – 10 years 

BIIB 10 years

(click to enlarge)

CVS – 10 years

CVS 10 years

(click to enlarge)

FDX – 10 years

FDX 10 years

(click to enlarge)

GD – 10 years

GD 10 years

(click to enlarge)

 GILD – 10 years

GILD 10 years

(click to enlarge)

HD – 10 years

HD 10 years

(click to enlarge)

LMT – 10 years

LMT 10 years

(click to enlarge)

LOW – 10 years

LOW 10 years

(click to enlarge) 

After the test, I realized that HD was tested last year, but this should not change or interfere with the reasons for the test. It was sufficient that HD has never been part of any of the strategy's design development phases.

Each of those stocks behaved differently, yet each managed to provide more than excellent returns over the 10-year period, as can be attested by their respective CAGRs. To show that it was not that much work, the alerts for the next Monday were: 2 buys and 1 sell. The alerts are in black at the bottom of the charts. And once those orders are processed, one can be free for the rest of the day, should they desire so.

All were at the $10k trade unit level. For the $5k trade unit, divide the initial capital, the ending profit, and the number of accumulated shares by 2. It should be a good enough and reasonable approximation. The CAGR would, however, stay about the same.

To give a summarized view, I've compiled some of the relevant numbers over this 10-stock portfolio over its 10-year trading interval:

Trade Summary – 10 years

Trade Summary 10 years

(click to enlarge) 

The intention was to show that the stock selection itself might not be that major a problem in a long-term trading strategy. It's the trading methodology that might matter the most. Hopefully, the above test makes that point.

Giving More Time

The previous section tried to show that the trading strategy mattered more than the stock selection. As if any reasonable selection out of a reasonable pool of candidates would have done the job. I hope the above test partly answered that question.

Now the hard part: providing more time.

How about going back 20 years? Do the test using the same program? What then? Shouldn't this all fall apart? Will adding 10 years of unseen price data cause the strategy to break down, as so many think that all trading strategies have to, or will it survive and prosper?

I say that the program will not only survive but will also produce more profits because of the underlying applied trading principles. The methodology was primarily designed with a long-term perspective. Therefore, a 20-year test should show by design if, by default, the strategy could have stood on its own merits or not.

The portfolio behavior can be anticipated from the program's structural design. The 10-year test showed the system tended to accumulate too much in cash reserves, something it should do again. This will put a drag on system performance since all that cash will remain idle. Cash reserves after that 10-year test were about 60% of the portfolio's value, and it was producing nothing at all, while in real life, it could have been put to some productive use. This left only 40% of the portfolio at work.

Therefore, a slowdown in CAGR performance is expected, but good performance money-wise nonetheless. I expect more trading activity: more positions to be taken, more closed positions, more still opened positions, more profits all over, more accumulated shares, and even more accumulated cash, which, in many regards, could also be viewed as a good thing.

Here are the test results, same stocks, same program, but this time 20 years of price data:

ABT – 20 years

ABT 20 years

(click to enlarge) 

ALL – 20 years

ALL 20 years

(click to enlarge)

BIIB – 20 years

BIIB 20 years

(click to enlarge)

CVS – 20 years 

CVS 20 years

(click to enlarge)

FDX – 20 years 

FDX 20 years

(click to enlarge)

GD – 20 years

GD 20 years

(click to enlarge)

GILD – 20 years

GILD 20 years

(click to enlarge)

HD – 20 years

HD 20 years

(click to enlarge)

LMT – 20 years

LMT 20 years

(click to enlarge)

LOW – 20 years

LOW 20 years

(click to enlarge) 

As can be seen in the above charts, the trading strategy did not break down. It continued to prosper, to outperform, producing what was anticipated. It did this not just for a few charts but for all of them, every single one of them. Here is a summary and its numbers:

Trade Summary – 20 years

Trade Summary 20 years

(click to enlarge) 

The above table resumes the trading activity. It has for payoff matrix:

A(t) = A(0) + Σ(H(1 + g)^t.*ΔP).

All the stocks continued to improve profit-wise. It's not a partial victory. It is a total one.

I could not determine beforehand what the output of the test would be except in general terms, as described above. As for the actual numbers in the table, well, that is what came out of the computer program. I find them more than acceptable.

Concluding Observations

The program made 135,347 trades, of which 118,585 were closed at a profit. The 16,752 remaining opened positions already show positive results in over 95% of the positions; meaning that some of the remaining shares show a relatively small average paper loss. 77.5% of the portfolio's value is in cash. As the market makes new highs, shares are converted to cash as a byproduct of the methodology. Again, not a bad thing. Closing all opened positions would result in the net liquidating value at the bottom of the table.

With the considerable amount of cash reserves, it leaves only 22.5% of the portfolio to generate more profits. It's understandable why the CAGR is decreasing as you near the 20-year threshold.

A set of new trading procedures is needed to better use the untapped cash reserves to generate even more profits. For me, it says there's room for improvement...

What you see in those charts can be done by anyone with some understanding and programming skills. It's not something esoteric, some secret sauce, or requiring a Ph.D. All you see are the results of administrative procedures of some kind, some code saying: if this happens, then do this. If not, do that.

It can be the basis for a long-term trading plan, and I think it is an interesting one.


All I can do, and am willing to do, is describe the methodology without providing my code, meaning my own programs. But I don't see a "secret" sauce in what I do. As a matter of fact, it's pretty boring. Even more, I think that there are hundreds upon hundreds of other trading solutions that can lead to the same thing I do or about; some better, some worse. But understand that I can not know any of this before a finish line is reached, portfolio-wise.

The presented test results use a program that is time-stamped as last modified on June 21, 2014. That was over a year ago. Market-wise, it is an old program.

The program was not only doing some out-of-sample tests over 10 and 20 years; it was also doing a walk-forward test with totally unseen data for the added year.

Applying last year to that program is the same as looking at what it would have done with its future, the program having been frozen in time. A walk forward for a whole year on entirely new and unpredictable price data since its last modification.

One should note another implied test that very few will dare do: the walk-backward test. The test of what would a strategy have done going back further in time. The first test covered the last 10 years with the last year its future. On the second test, over the same stocks, the trading interval was increased to 20 years. Ten years of walk-backward tests on stocks that the program has never seen and of which none had served in the design of the trading strategy.

Since no predictions or forecasts are used in that program, it had to survive on its own merits. The code, the trading strategy, is the central and most critical element of this automated trading script.

I describe what I do in one sentence: accumulate shares for the long term and trade over the process. That's it. It's by understanding all the ramifications implied in such a description that one can start building their own (and what I would call improved) trading systems. The emphasis is on: their own systems. This means your systems. I already have mine.

The future has only one take. There are no reruns.

Created... July 3, 2015,    © Guy R. Fleury. All rights reserved.