Machine learning trading algorithm for mean reversion strategy

Machine Learning (journal)
Machine Learning (journal) (Photo credit: Wikipedia)
Machine learning algorithms can get complicated really quickly. I have been fooling around with some small tests and finally decided I would try to implement a forex trading strategy using machine learning, while keeping things as simple as possible (,but not simpler, as Einstein said). So as an exercise and exploration of the possibilities I decided to turn the most simple moving average cross over mean reversion trading strategy into a machine learning trading algorithm. Moving average cross over strategies are fairly commonly used in trading mostly in conjunction with some other technical indicator and a lot of trader discretion. Trader discretion is needed to decide when to trade the strategy and when NOT to trade the strategy all depending on the market conditions.

I have been back testing many strategies and most strategies clearly have profitable periods as well as losing periods. There are always some optimal parameters to be found for any specific period of time. However this does not say anything about the likelihood that these parameters will be optimal in the future. Such testing is always prone to curve fitting, data snooping and the like. So my idea was to use machine learning to figure out when to trade the most basic and commonly used strategies and when not to trade these strategies, without optimizing the parameters of the strategy. This way the strategy can be kept relatively simple and be supported by some fundamental underlying trading principles, while substituting trader discretion with machine learning. By the way, I believe that Machine Learning cannot completely replace trader discretion. It is merely a tool that can help a trader capture many more opportunities. The ML algo itself still needs constant monitoring and sanity checking, which is also discretionary.

So I took a broad cross section of the pairs traded in the currency markets:
eurnzd, eurcad, eurusd, gbpusd, audusd, nzdusd, usdjpy, usdcad, usdchf, eurchf, eurjpy, gbpjpy, gbpchf, eurgbp and euraud.
And I ran a 3 year back test on daily data using a simple mean reversion strategy. Here is a graph of the combined trading on all the pairs.
P&L curve of combined trading basic mean reversion strategy
This is clearly a losing strategy. However, there are periods where the p&l curve is moving north. And some of the p&l curves of the individual pairs have even more clear and extended profitable periods, but you get the idea.

I programmed an algorithm that runs through the data of each pair and decides, by looking back on a certain period, if the coming period should be profitable for trading the strategy. And if so, it would trade the simple strategy. Here is the resulting P&L after stress testing the algo.
P&L curve of combined trading Machine Learning mean reversion strategy
I started out with a slightly different version of this algorithm, that produced much higher results and much higher sharpe. However, it had a maximum draw down of 16%, while the final algo has only a 5.9% maximum draw down. This P&L curve has been stress tested by allowing for sloppy execution by calculating between 10 to 15 pips for spread and slippage on every buy and sell. When I did this to the first version of the algo, the sharpe and the win ratio dropped quickly, while with my final algo the sharpe and win ratio remained more or less the same. Only the amount of trades and profits decreased. So this algo seems more stable, more conservative.

So I have a positive back tested Machine Learning trading algorithm. Yeah! Now what? What are the next steps? Well,

  1. I will program the algo to automatically paper trade. It will generate the orders against a live 100% for sure unseen market data. The orders will not be executed, but will be recorded, hence paper trading.
  2. I will analyse the results, tweak the algo and decide if it is OK consider trading live with real money. 
  3. In the mean time I will have set up a live execution system on a trading api, so I can actually start live trading on a small live account.
  4. I will trade the algo on a "normal" sized account once the trading on the small account produces the expected results.
  5. I will allow the strategy to be followed by other traders.

There is still a lot of work to do before the algo can go live and even more before others can follow it. I am wondering if there is any interest out there in following this strategy based on what I have explained so far. If you are interested, please let me know by writing a comment or sending me an email.
I will be happy to explain more or help you out any way I can.

Comments