Download the code and script

AI in Finance – FOREX: Algorithmic Trading

Machine learning allows for the processing of large quantities of data from a variety of sources including unstructured data and social media posts.  Machine learning allows the user to recognise complex patterns that you can’t pick up with regular statistics. Algorithmic trading is the automation of trading, but machine learning allows the trader to perform additional powerful data analytics quickly, on large amounts of data.  This is particularly attractive in the context of trading, where swarms of incoming data must be analysed every second. MATLAB’s powerful environment allows you to prototype machine learning models rapidly and with minimal programming experience.

We provide you with a script template which acts as your gateway to machine learning. You can get started with machine learning immediately by running it as is, or modify it to suit your applications.  We use historical FOREX data of the USDEUR currency pair to train a machine learning model – a decision tree – to generate a buy/sell/hold trading signal. We also use this model to predict in-sample and out-sample returns.  While we used decision trees in this example, it could be extended to other machine learning techniques like deep learning.

While many users could be daunted by the idea of machine learning, MATLAB only needs the following code to train a decision tree:




and this line of code will use the machine learning model to create a trading signal:


















The machine learning template is written in a MATLAB live script.  The power of the live script (file extension. mlx, not the .m of traditional MATLAB scripts) lies in its dynamic nature.  Plots and the results of calculations appear within your code, enabling you to write code faster.  Static text, hyperlinks and equations can be included in the live script, making your code read more like a document than a programming script.

Start right away by running or tinkering with your template live script. In a sum total of 2 lines of code, a decision tree model is created which is used to make stock market decisions   In minimal time, and with minimal prior experience, you too can generate trading signals with machine learning in MATLAB.


What Can I Do Next?

Follow us