July 23, 2015

In my previous article, More DEVX V6 has shown a simulation of the program over 10 stocks over durations of 10 and 20 years. The point was to show that this particular stock trading strategy would easily survive not only over its first 10-year trading interval but also over a 20-year period, and this includes one year as a walk forward.

Over the past weeks, I tried to visualize more improvements to that program. Still, more ways to enhance its long-term performance. After struggling with the matter for a while, I finally figured out how to code some of these new procedures. It took only 10 to 20 minutes to code and debug the routine.

In all, two lines of code were added to a program that already stood at over 2,000 lines. Talk about an incremental improvement. Like in everything else related to strategy design, a new procedure should be able to show its merits in a backtest.

Testing a trading strategy against another is easy. It can be written in payoff matrix notation as Σ(H(strat_B).*ΔP) >? Σ(H(strat_A).*ΔP)? It reads: is the improved strategy B better than strategy A? Using the same stocks over the same time span (20 years) should prove sufficient to show if, at the portfolio level, one strategy is better than the other.

Here are the charts of the 20-year scenario on the same stocks as in the previous article:

 ABT – 20 years


(click to enlarge)

 ALL – 20 years


(click to enlarge)

 BIIB – 20 years


(click to enlarge)

 CVS – 20 years


(click to enlarge) 

 FDX – 20 years 


(click to enlarge) 

 GD – 20 years


(click to enlarge) 

 GILD – 20 years


(click to enlarge) 

 HD – 20 years


(click to enlarge) 

 LMT – 20 years


(click to enlarge) 

 LOW – 20 years


(click to enlarge)

The impact of the two added lines of code can be extracted:

Σ(H(strat_B).*ΔP) – Σ(H(strat_A).*ΔP) = ?

Here is a summary of the above charts in numbers:

 Trade Summary – 20 years

Trade Summary

(click to enlarge)  

The last line in the above table shows the difference between the net liquidating values of the last table in the previous article and this one. This would imply that the 2 added lines of code would be worth more than $250M. Impressive. The added lines were procedural in nature, designed to apply to stocks in general which also explains why all 10 stocks were positively impacted.

Why do a test like this?

To show that, at times, even some limited code changes can have quite an impact on overall portfolio performance. The payoff matrix still has for governing equation:

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

Increasing the feedback loop resulted in an increase in g, which in turn increased overall performance. You won't be able to predict where the improvements will have the most impact or which stock will benefit the most, but improvements will still be seen in most of the metrics. In this case, it meant ending with more cash, more shares, more positions, and more profits.

It took some time to figure out how to do this code modification and much less time to program and debug it (only 2 lines of code, after all). It also demonstrates that anyone can look to improve on his/her strategy design as if there are almost always some improvements to be made as long as they are sufficiently general in nature.

Hope this can be of help to some.

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