Feb. 26, 2019
The trading strategy referenced in my last article was the followup to the series of articles: Trading Stocks Generate Its Own Problems Part I – VI (See related files below) where the CVXOPT optimizer was used on randomly generated price series to illustrate how even a small trend could be detected and capitalized on for the benefit of one's stock portfolio.
The series of articles cited above, as well as my last book: Beyond the Efficient Frontier, were centered around this optimizer and on the use of randomly generated prices with trends.
This new article looks at the practical side of using the optimizer in the same way but on real market data. If it can detect some long term trend, it should take advantage of it and return some profits, and retain most of the general behavior illustrated in the book.
This too is a followup of sort. It uses what was presented in the book, the series of articles, and applies it to real market data. I used an existing trading strategy that had been published on the Quantopian website as a foundation for what follows. I limited myself to enhancing the strategy making it do what I wanted it to do. Changed its mission and overall trading philosophy. The modifications made it quite a different program.
Maybe for best understanding, it might be preferable to view some of my posts in the following Quantopian thread. This way you would have the history of how the changes to this trading strategy evolved over time.
The trading strategy was changed one step at a time not only to operate differently but to also have a different mission. I do not see it as over-fitting for the simple reason that I could not make all those changes all at once. You could not have coded it all in one shot either. I looked at it more like exploring the strategies potential and mostly its limits. Trying to find out the how, where and why it could break down.
The CVXOPT optimizer is at the center of this trading strategy. Each modification forced it to reevaluate its overall mission, either by adding more time, or more funds, or requesting that it do more. It tried to maximize what it was given: a few price series going back 14 years. It is a trading interval long enough to show if a stock trading strategy has something in it or not.
The CVXOPT optimizer is not given away money for free. It is designed to find the maximum of quadratic functions, or find the best mix of a set of price series should they exhibit some kind of trend. It only solves a mathematical problem. See the tests using randomly generated price series which showed that you did not need much to have the optimizer extract profits. If real market data had a high enough degree of random-like price movements with an underlying long-term trend, then the optimizer would be able to extract profits from that too.
Finally Read The Program Code
I have finally read the entire trading script. Nice work. My first observation to a friend was: “I would not have dared do those modifications had I started by reading the code”.
Prior to reading the code, I still had another test to make which was to hike the ante to answer the question: will it scale up to that level? So, the initial capital was raised to $50M. For more details on this process, see the Quantopian link above.
The above chart shows the impact of applying the optimizer over an extended period on real market data. The chart is not an illusion, it is just the outcome of the applied program which behaved the same as illustrated in my book or in related articles.
Some observations: a long-term chart gives a sense of perspective. For instance, during the financial crisis the strategy had a -79% drawdown (see the 4th interval, just below the green 58645.22%). It is less than barely noticeable. Notwithstanding, the strategy maintained a part of its positions and was able to recuperate much faster having had those positions in place prior to the recovery. Whereas for the dips on the last two intervals, which just appear as small blips, are in the order of 100 to 200 million in size. However, note that 50M at 58645.22% is 29B to keep some sense of proportion.
At any time you could have quit the game, for whatever reason, and collected what the blue line was saying at that time. A backtest is just a backtest. It is made to show what could have happened if. And once you know that, you can plan, based on the strategy's trade mechanics, for what you want your trading strategy or your set of trading strategies to do. It is always your choice.
Until I add the protective measures, such a strategy as illustrated above needs to be gamed or strategized with others of lower drawdowns. But that has already been covered in prior posts.
Now, back to the drawing board to design those protective measures. The objective will be mainly to reduce drawdowns. Nonetheless, I still want the positive feedback loop to remain in full force.