Home Blog How to optimise the ...

How to optimise the risk/investment ratio using machine learning

FinScience

by Valerio Sabelli

One of the most interesting challenges we can pose to modern tools based on machine learning is that of estimating the risk of an investment. Apart from “anomalous” events (see Elon Musk’s statements on Dogecoin and Signal), it is possible to exploit the potential of artificial intelligence to identify many patterns in the market fluctuations of our assets.

Among the most common applications of the algorithms of machine learning and of the neural networks, the stock market prediction can be carried out following various approaches, among which the supervised one, the unsupervised one or the one based on reinforced learning. In this article, we will discover some of the mechanisms behind most of the tools on the market.

What is the risk/return ratio

The risk/reward ratio, also known as the risk/reward ratio, is an indicator that compares the potential profit (return) of an investment with the related potential loss (risk). Having defined the entry point of a trade as the amount you would initially invest, the comparison is made by dividing two quantities calculated in this way:

  • the risk is the difference between the entry point of the trade and the stop-loss  
  • the yield is the difference between the entry point and the target profit (exit point)

The stop-loss, defined for each investment, is the investor’s lifeline: if the loss on the investment reaches a certain value, the position is closed. This value can be determined in various approaches:

  • on the basis of the achievement of a certain monetary loss in absolute value or percentage with respect to the investment;
  • on the basis of well-known daily candlestick patterns;
  • on the basis of volatility, i.e. setting it at a distance from the entry point based on the Average True Range (ATR) indicator, which takes into account the price trend over recent periods (usually 14 days).

To optimize the relationship risk/return

There have been many articles and studies – based on well-known datasets such as the S&P 500 (Standard and Poor’s) – aimed at outlining what are the best strategies to achieve a risk-free investment.

The definition of the problem is as follows: given a historical series for various stocks, how can we allocate a certain amount to invest each day in order to maximize profit?

The objective is then to develop a strategy to create a portfolio of investments, i.e. an allocation of resources, which will change over time.

One of the approaches that can be applied is reinforcement learning, which aims at defining agents that interact with an environment in order to achieve a certain objective with a trial and error strategy. Classic application examples for these algorithms are motion simulators for ‘virtual dummies’, maze solving and strategy games.

The agent is the entity that makes the choices and receives rewards when interacting with the environment, trying to maximize them each time and minimising the penalties. The task is completed when a certain a priori defined objective is reached.

In our application case, optimization can be identified as a percentage of resource investment on a certain stock. The feedback the agent receives will be positive or negative depending on the market trend for the stock in question.
The agent will modify its strategy from time to time until understanding (usually after many iterations) how to optimize the yield, obviously taking into account what can be the opportune stop-losses in the various attempts that it makes.

Obviously, for this type of training it is necessary an extended dataset that represents the course of the markets on which we will go to operate. Of time in time, the environment will be a different portion of those same data, so as to extrapolate the “generic” rules of those types of stock.

The outcome of this training process will be an agent who, thanks to his experience, will be able to provide us with data-driven forecasts that will allow us to reduce the investment risk.