November 14th, 2016

For those that have followed this series of articles over the last two months starting with the Payoff Matrix, it is time to show how all of it can be applied in a trading strategy now that the mathematical background has been provided.

The last time I did a portfolio level simulation using the DEVX strategy was last November, not quite a year, but close enough. The one last shown was dated October, using a prior version (DEVX6 dated June 21, 2014) which was more aggressive.

If I did a new test today, the strategy would face almost a whole year of new data that it has never seen before or could know about. It would have no other recourse than to just execute its code as is, meaning the way it was the last time the program was modified. That was November 29, 2015. As if this program has been frozen in time since then. Such a test would have the strategy looking at its future, the same as a walk forward.

All the new data can be classified as out-of-sample, having never been used in the strategy's design since the program was not modified. Not only would it be an out-of-sample test, but it would also be a walk-forward test. The same as if paper trading the strategy for almost a year. Evidently, the only way to do this was to wait for almost a year before running the program again. Which is what is being done now.

Over the past year, only two stocks in the list were run on the November 29 version (LOW and LMT) on two separate occasions (in May and July). See articles: Portfolio Drawdowns and Trading Strategy Survival. In both cases, the points being put forward were: that a trading strategy can survive, that you won't escape drawdowns whatever you do, and that the strategy was scalable to any size, including very, very big. This time, it is at the portfolio level that a test is being run, not just on a couple of stocks.

Here are some of the properties of the DEVX8 program (as of Nov. 29, 2015 edition).

First, and maybe the most unusual feature of this program, it trades following quasi-random-like functions. Meaning that to enter into a trade or exit from it, the actual decision process is transferred to random-like functions. I used multiple biased coins to determine entries and exits when stock prices were in their allowed trading windows.

This implies, as it should, that I could not know in advance when a specific trade would or could occur, how much would be traded, or if it would be positive the next day or not.

Nonetheless, the program was instructed to only sell if it had a profit in hand (Δp > 0). Doing so would make all closed positions profitable: a 100% hit rate on closed positions. Therefore, I do know from the start that all closed positions will be profitable, a procedure hard-coded in the program. This follows n*u*PT. Increasing closed positions will only increase overall profits.

Second, DEVX8 has a long-term vision of things; it is looking for a long-term resolution to n*u*PT to go higher than the average expected performance. Therefore, it transformed the basic 3 portfolio metrics into time functions: n(t)*u(t)*PT(t). To assure: n(t)*u(t)*PT(t) > n*u*PT, it was required to design time functions to control these 3 portfolio metrics. It resulted into the following expression: n(1+f(a))*u(1+f(b))*PT(1+f(c)). To succeed in outperforming the averages, it would be sufficient to have either f(a) > 0, f(b) > 0, or f(c) > 0, or any two or all three at a time greater than zero. Rather a simple problem-solving.

Third but not least, DEVX8 accumulates shares over the long term. That is its primary mission. One of building a long-term portfolio. Except, it starts too small to make huge investment bets in all its stocks due to its limited initial capital.

But, by trading over its share accumulation directive, it can generate profits which can then be used to buy more shares. Creating a positive feedback loop: generating profits, buying more shares, generating more profits, and retaining more shares. A gradual process that will snowball over the years.

And that is what a simulation will show: there is value in trading, and there is value in accumulating shares for the long term, sufficiently to outperform traditional and indexed trading methods.

The above was written before doing the test. The reason is simple. I know the answer to that simulation before doing the test, and I just want to impress. Not only will the trading strategy survive, meaning it will not break down, but it will also prosper as it is designed to do.

So, I will restate that not all trading strategies fail, only those that are poorly designed.

Fourth, DEVX8 is controllable. You can control its degree of trade aggressiveness. This is quite an interesting feature. You can dictate to your trading strategy what you want it to do over the course of its 20-year journey. Just like turning knobs: to accumulate more shares over the period, go for higher profit margins, or distribute more shares near tops. There are 9 such controls in the program.

Fifth, DEVX8 is designed to grow big, really big, ready to manage large portfolios that want to grow much larger, as was shown in some of the backtests. It even has a retirement plan feature already built in.

I have the program write the data I'm interested in on each chart it generates. They are the things I wanted to know without flipping back and forth from test results to charts and back again all the time.

All charts are time-stamped with the program version, stuff I usually do for all my backtests. A kind of proof it was the program that did those things. It is also of great help when I review what a program did in a particular test. You have all you need on one chart.

I'll use the same DEVX8 version used in Trading Strategy Survival and Portfolio Drawdowns.

Following are the tabulated results of this test. I did not push it since when I do, people start saying words like impossible, or it will fail going forward, even if you show that it didn't over the past 20 years. It is like telling me that the flip of a coin won't work tomorrow. I've got news for them.

There is nothing extraordinary or deceptive in what is being presented here. It is just the output of a program. You can not optimize the flip of a coin. And if the program wasn't any good, it would not have survived its 20-year test and would have produced dismal or negative results. It is not the case, as can be seen in the following table:

#1  DEVX8  Nov. 12, 2016, Test  (20.71 years (5,385 trading days)


(click to enlarge)

The same 10 stocks as last year were used which had been selected some 18 months ago as representative portfolio candidates. The test covers 20.71 years (5,385 trading days). Each stock is given a $ 500k initial stake and is allowed to dip into other stock's cash reserves if needed. At times, some margin might be used, but most often, cash reserves can carry the day. Trade units were set at $ 10k, and trades were executed only if there was a sufficient cash reserve.

The portfolio's $ 5 million initial investment generated $ 656.9 million in profits, a 26.6% average portfolio CAGR over the period.

All stocks ended profitably. Some 2,846,229 shares were accumulated over the period, valued at $ 293.9 million. Cash reserves totaled: $ 361.8 million, 55% of equity. Cash does not drop when there is a drawdown, therefore with time, the strategy sees less and less portfolio volatility than the market. The system made 45,313 trades of $ 10k each and sold 27,624 of those positions at a profit. This financed the share accumulation process and the ongoing trading operations.

A number like 45,313 trades does qualify as more than a small sample and becomes representative of some average statistical state even if the trading was randomly performed. It definitely shows that it was not a 50/50 proposition but that there was a positive bias not only in the methodology used but in the market itself.

Each stock had its own signature, and yet, each ended positive, with for minimum CAGR 23.85% and at the high end a CAGR of 29.78%, with an average of 26.60% portfolio CAGR. Impressive results, especially when one considers that the trading interval spans 20.71 years, surviving the era and the financial crisis.

I'll give a rundown on one stock (ABT), a representative of the group, to show how it behaved. This will be followed by the other 9 price charts at the end.

#2  ABT  


(click to enlarge)

One should notice the trade distribution. Trades can occur when trading windows are open, whether it be for buying or selling. The trades are randomly distributed with random-like volumes. Yet, the strategy profits at what seems like every price swing of significance. Of its 4,880 trades, 4,290 are with a profit. Of these, 2,642 have already closed. All orders were market orders for the next trading day. 

#3  ABT - Equity Curve

ABT Equity Curve

(click to enlarge)

From the equity curve, we can see the profit distribution over time. The bottom panel gives the percent profit achieved by each trade. The biggest bell-shaped curve is mostly for closed positions, while the small one on the left is mostly for still open positions. The blue, almost flat line in the top panel represents an ABT buy-and-hold scenario.

#4  ABT - MAE/MFE (Maximum Adverse/Favorable Excursions)


(click to enlarge)

The top panel shows all trades and how far in the red they went. The bright red saying how many of the dark red numbers ended positively. For example, of the 12 trades out of 4,880 that suffered a 45% drawdown, each of them ended with a profit. The chart gives the number of trades that reach a drawdown level in the background and the number that are positive in the foreground. The majority of trades saw less than a 10% drawdown.

The same thing goes in the bottom panel, showing how positive trades got and how many of those are currently negative, meaning below their purchase price. For instance, of the 1,055 trades that reach the 140% profit level, none are at a loss. The same goes for other light blue bars in the foreground with a zero. 

#5  ABT - Summary Performance Report

ABT Performance Report

(click to enlarge)

The performance report reiterates what was printed on the chart (fig. #2). It shows that there are currently 590 positions out of the 4,880 at an average loss of $ 459 (12.09% of trades). It also shows 4,290 trades with an average profit of 97.36% or $ 9,729.54 per trade.

There are risks involved in trading, but there are also rewards. The profit factor, as well as the payoff ratio, are relatively high as seen at the bottom of the chart. Those cannot be viewed as bad numbers. 

#6  ABT - Trade Profit Distribution

ABT Trade Profit Distribution

(click to enlarge)

This is an interesting chart. Each blue dot shows a profitable trade, while the red dots show trades that are in the red, meaning at a loss. With time, blue dots aggregate to the triangular formation to the left. The dots to the right need more time to reach the group as if you were nurturing profits to grow. They might have a hard time in the beginning (seeing some red), but eventually, they grow and migrate to fit somewhere within the group on the left. You don't know where they will end up, but that is not important. What is, is that they get there. 

#7  ABT - Other Numbers

ABT Other Numbers

(click to enlarge)

That is what I use to cross-validate and show some numbers not provided on the charts. Since those numbers are calculated separately, they were helpful in the debugging process. There were numbers I wanted to know, for example, the available cash on hand, how many shares were accumulated over the period, and how much was the value of that inventory.

One peculiar number in the chart is the number of skips. Something I've never seen in traditional trading strategies. The 52,508 is the number of times trades requested an exit due to having met or exceeded their profit objectives and were randomly denied that exit. I wanted to know how many could occur from the Delayed Gratification tests, just out of curiosity. The question should be: are those delays profitable? Oh, yes, they are, on average, and making delaying gratification worthwhile.

Here are the other stock charts in this portfolio, each with its story:

#8  ALL  


(click to enlarge)

#9  BIIB  


(click to enlarge)

#10  CVS  


(click to enlarge)

#11  FDX  


(click to enlarge) 

#12  GD  


(click to enlarge) 

#13  GILD  


(click to enlarge) 

#14  HD  


(click to enlarge) 

#15  LMT


(click to enlarge) 

#16  LOW  


(click to enlarge)

All these charts confirm the tabulated data in chart #1 above. Also, one can see how the trading strategy behaved over the past 15 months. Each of the stocks had trading rules to govern what they could do. A self-defined trade opportunity window was set for buying and selling. It was up to the random-like functions to determine if the opportunity was taken or not, whether it be on the buy side or the sell side.

Two basic trading rules have already been presented. No buying below the initial price in order to avoid weak stocks and bankruptcies. And, sell only with a profit: (Δp > 0). It does appear that those were not bad trading rules.

Having quasi-random-like entries and exits makes the program independent of indicators of all types. It also makes the program immediately responsive to the flip of a coin; therefore, there is no delay or lag due to indicator lookback periods. Also, almost as a corollary, no notion of where the price is going after an entry.

Even if you operate as if almost randomly, it does not exclude making a profit. You will make a profit, not by chance, but by design, which is what this demonstration showed.

DEVX8 is scalable. To show this, it is sufficient to run a test. So, I doubled the trading unit, doubled the initial stake, and ran a test on ABT with the following results:

#17  ABT  - Doubling the Trade Unit and Initial Capital

ABT Double Trade Unit

(click to enlarge)

Just based on the 3 metrics formula: A(t) = A(0) + n*u*PT, if you doubled the trading unit, it will also require doubling the initial stake. The output will be: 2*A(t) = 2*A(0) +n*2*u*PT, which is what you see in chart #17. The same would apply to all the other charts, so no need to show them.

To push further, one could multiply the trading unit by 10, the initial capital by 10, and see the portfolio result multiplied by 10 as well.

One thing not discussed is: what if you add 10 more years? What would happen? Well, it is simple, the portfolio would continue to grow, accumulate more shares, more cash, and more profits. Keeping the same CAGR would result into: $ 5,000,000 * (1+0.2660)^30.71, or you could try: $ 10,000,000 * (1+0.2660)^30.71. It would surely change your tax bracket.

This test corroborates the articles of the past two months, showing the application to a trading system of the principles involved in the making of a long-term portfolio. One made to prosper with the prosperity of a nation. It is the objective of every company to grow and prosper, you just want to go along for the ride, and prosper too. But, you want to do it faster than just average. It is your responsibility, as a strategy designer, to make it so.

Now, for what I want to do next. My goal is to convert DEVX8 to the Quantopian environment. This will require converting the program to Python and finding ways to program the same functions or better in that environment. Already, with the stock trading experiment done on Quantopian, I know I can do better, the tools are there, it is up to me to use them. To give you an idea of what is to come, see the 3-part article: A Simple Stock Trading Strategy – Part IPart II, and Part III.  It should also give you some ideas.

Thanks for reading this far. 

Created... November 14th, 2016,   © Guy R. Fleury. All rights reserved