Can we replicate the behavior of an experienced FX trader with deep learning?
In February of 2017, I started a 6 month deep learning ‘nano degree’ through Udacity, and as always for me I find that learning sticks and motivation increases when there’s some project to get obsessed about.
So, I’ve been working on trying to use machine learning to replicate the behavior of my friend Rudy, an experienced day trader. Rudy draws all sorts of signals on charts by hand that inform the way he places trades. Could we use deep learning to replicate this part of his trading process? I started collecting labeled data from his trading platform.
My approach started in the familiar way: XGBoost, Random Forests, and then a tour through lots and lots of deep learning architectures. The majority of my time on this project for the first half of 2017 was to study SOTA papers in image recognition and adapt them to the task of looking at a block of statistical information. In the interest of time, most of my work was done in Keras. Not surprisingly, the majority of my work was in feature engineering and munging matrices into shape (there’s a business idea here), actually creating the models was as much as following recipes and thinking critically about those recipes from papers found on arxiv and as retweeted by prominent people in the field.
About mid-way through the year, after lots of hours working with my tutor and my graphics card on my little laptop churning for countless nights, I had achieved a high F1 score of 71% with only 10,000 positive examples (90,000 examples total), using a Conv1D architecture that was a hybrid of a number of papers related to cancer detection. Lots of my work ended up related to anomaly detection and unbalanced datasets, due to the small sample size. Everytime I got more labeled data, my scores went up. Despite making numerous jokes and overtones about how much I wish Rudy would manually create for me 100,000 examples, this was the end of the labeled data I could get, and the accuracy was not good enough to be used for actual trading. Recently, at a Python meetup I was talking to a guy doing a PhD in Machine Learning at Northwestern. When I told him about my F1 score and the number of data points, he said “try adding a few more zeros to that sample size”. Ha.
Then, I found C# code for an indicator that draws similar signals to the ones my friend Rudy draws by hand. Upon coverting to Python, I discovered it could generate similar results but without all the headache related to deploying Keras models in production for day trading (and without trying to get 900,000 more samples.
Down the road, there’s a much better blog post out there with code snippets and a walkthrough and a readable notebook and code. Not today though! The project is still in progress, and my code is now hundreds of Jupyter notebooks and thousands of lines of code. I’ve learned a ton about data science in the process, and developed the itch to find more opportunities to translate breakthroughs in one narrow field to a different field!
Pandas, numpy, sklearn, keras, tensorflow.
The Github with some of my experiments (not well formatted or shared) is here: https://github.com/trevorwelch/deep-learning-FX-experiments