Zorro Trader: Trading FOREX with Deepnet

Zorro Trader: Trading FOREX with Deepnet

Zorro Trader comes with several example strategies, some of them quite interesting. I am not talking about the Z strategies, which are supposed to be tradable live, out-of-the box, by anyone. I am talking about the rest of the stuff in the Strategy folder. A few of the files in there have names starting with DeepLearn, and several different terminations and extensions (.c and .r). As we know, C is for Zorro’s Lite-C, and R is for R files. Opening the DeepLearn.c shows the following header, from which I un-commented the DeepNet line:

// Deep Learning Test ///////////////////////////////////////////

//#define DO_SIGNALS  // generate sample set in Train mode
#define DEEPNET
//#define H2O 
//#define MXNET
//#define KERAS

///////////////////////////////////////////////////////////////////////

DeepNet, H2O, MXNET and Keras are all machine learning frameworks. You can use them to implement most of the sci-fi AI stuff you hear about everywhere these days, like neural networks, support vector machines, autoencoders, classifiers, regressors and the like. I used DeepNet and Keras extensively myself, and I know them pretty well (never touched MxNet or H2O). Keras can be a pain to install, as it involves installing Python, specific NVidia drivers, Tensorflow, etc. But DeepNet is very easy to install, as it is an R package with some dependencies. If you follow the manual, you can get it up and running in less than 10 minutes.

So, assuming Zorro and R are configured correctly, we got ourselves a pretty cool Zorro Trader machine learning Strategy. But what does it do, exactly? Well, it’s all in this code:

if((vLong = adviseLong(NEURAL+BALANCED,0,
#endif // please ignore this
		change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))) > Threshold)
		enterLong();
#ifndef DO_SIGNALS //please ignore this
	if((vShort = adviseShort()) > Threshold)
		enterShort();

The Zorro Trader functions adviseLong() and adviseShort() send to DeepNet 8 values (4 change, 4 range) and Zorro receives 2 values (vLong and vShort) back from DeepNet (which runs in R). Change and range are 4 bars price and volatility data, telling DeepNet what the price did and how volatile the market was. It’s like you or I staring at the price action and the ATR indicator (for example) on hourly bars, trying to figure out what will happen during the next 3 hours. vLong and vShort are trading signals. There is a Threshold value defined somewhere else in the script, and set to 0.5.

Zorro Trader enters a long (or short) position depending on the values vLong and vShort, calculated in R, by DeepNet. No need for more detail at this point, but this is the simplest way one could implement a neural network trading strategy in Zorro Trader and R.

It works pretty much like this. Zorro Trader sends data to R, R trains a DeepNet, and then the model is used to predict what Zorro should do: enter a long or a short position. The details are cumbersome, but there’s no need to understand them at this point. The idea is simple: use 4 hours of past data to predict what happens 3 hours from now. If DeepNet thinks the market will go up, we go long. If not, we go short. We just unleashed the power of artificial intelligence on the FOREX market, in just a few lines of code! (that we didn’t even write!)

Can Neural Networks Predict Stock Market Prices?

Well, that’s what we are just about to test. Can DeepNet use data from the past four hours to predict what will happen in the next three hours? Will the price go up, or down? We have to train the system first, so please hit the train button, and enjoy a few minutes of elation and optimism, as any algorithmic trader should when running a back-test! Depending on the performance of your machine, you may enjoy a cup of coffee as well until you hit Zorro’s Test button and wait for the result of your back-test.

Zorro Trader
Walk Forward Analysis of the Neural Network Strategy

And here is the result:

Zorro Trader
Equity curve of the DeepNet Zorro Trader Strategy

This looks pretty nice! It appears that DeepNet has indeed learned something about the stock market, and is able to predict the future with a better than 50/50 chance. And also please note this is a Walk-Forward Optimization test, not a simple back-test that is so much easier to over-fit! That being said, I should now run and start trading this strategy live with Zorro Trader, on the EUR/USD FOREX pair, with the cheapest broker I can find, and wait for the profits to roll-in. If it only were that simple!

Please read my next post on this here: Is The Zorro Trader Neural Network Strategy Tradable?

Comments are closed.