Machine Learning and Stock Trading

Leveraging the power of data and algorithms on the stock market

Maxime Battello
3 min readApr 25, 2022
Photo by Stephen Dawson on Unsplash

This post is intended for people interested in Machine Learning and stock trading. The goal is to provide the reader with a general overview of what Machine Learning is and how it can be used on the stock market.

This is a high-level post, without any code or technical explanations. I intend to go deeper into the technicalities in other posts, stay tuned!

What is Machine Learning? 🤖

Machine Learning (ML) is a branch of Artificial Intelligence that uses algorithms and data to make decisions.

The most straightforward form of ML is called Supervised Learning. In Supervised Machine Learning, a computer “learns” the relation between some input variables (called “features”) and an output variable (called “target”) to make predictions about the future.

For example, the historical performance of a stock such as earnings-per-share, price-to-earnings ratio, or price-to-book ratio could be used as input variables.
And the output variable could be an indicator stating if the stock had a positive return or not (buy/not-buy).

In this scenario, the algorithm will learn from the previous years’ data and will then be able to suggest if a certain stock is likely to have a positive return or not in the future.
I.e. answering the most valuable question for all investors: should we buy this stock or not?

The picture below illustrates this concept.

What are the advantages of ML in Trading? 👍

  • ML models improve their performance through experience and can handle a high amount of data
  • They can figure out very complex relationships that can be difficult for humans to understand
  • They base their decisions on data and not emotions, helping investors to keep their heads straight

What kind of features can be used? 🥗

Historical prices, company fundamentals, weather data, news, Reddit threads…

Pretty much anything can be used in ML. The trickiest part is to be able to translate all this data into something that can be understood by the algorithm.

This is where Data Scientists spend most of their time: preparing data and running analyses to select the best performing set of features.

What can you set as a target for the algorithm? 🎯

To put it simply, there are two main ways to create targets:

  • Regression: predict the actual stock return at the end of a fixed period (next month for example) => [+12%]
  • Classification: will the stock have a return higher than 10% in the coming period (month, quarter)? => [Yes/No]

More complex targets can be built using take-profit or stop-loss thresholds, the Triple Barrier method suggested by de Prado is a very interesting one for example (Advances in Financial Machine Learning, Marcos Lopez de Prado)

Choosing a good target is important and it depends on the data at hand and the overall goal. I use both regression and classification in my strategy (with a more complex setup).

To Conclude 🔚

This was a quick introduction to Machine Learning and its use for stock trading.

Of course, there’s a lot more going on in building a good ML model. In later posts, I intend to go deeper into some of the technical aspects of ML.

This was my first post on Medium, if you have any questions or remarks, drop a comment! 😃

You can also follow me on the trading platform eToro, where I use Machine Learning at the core of my investment strategy.

This post contains an affiliate link to the social trading platform eToro

--

--

Maxime Battello

Data Scientist with a passion for Machine Learning, MLOps, and Trading & Investing