What is algorithmic trading?

Trading algorismic

Home » Current Events »

What is algorithmic trading?
Authors:

The stock exchange was a market in which investors classically exchanged securities, establishing prices based on the supply and demand that existed at any given time.

This view has changed drastically in recent years when most of the trades that are created in the different markets of the world are launched automatically by robots running algorithms.

Algorithmic trading is the process of using a computer program to generate buy or sell orders based on a set of instructions or predictive models.

The key to algorithmic trading is the lack of human intervention, since the impact of human emotions on decision making is ruled out.The key to algorithmic trading is the lack of human intervention, since the impact of human emotions on decision making is ruled out.

Buy and sell orders can be placed in the market manually (paper trading) or automatically (automated trading).

 

What are these trading algorithms like?

The algorithms used attempt to monetize a certain pattern of behavior that we have detected based on historical information. Therefore, the objective is to have a statistical advantage  when making a decision to buy or sell.

For example, some algorithms focus on looking for the continuity of an uptrend or downtrend, others look for stocks that have moved far away from their median valuation, some look for the classic arbitrages that occur in transitory periods, while others look for divergences between pairs of correlated stocks.

Trading algorithms can be based on  rules  (rates when a certain buy/sell condition is passed) and/or can also be programmed by  Machine Learning  algorithms .

 

Example of a rule-based algorithm, in this case with a short arithmetic mean of 15 sessions and an arithmetic mean of 150 sessions. I would buy when the short average cuts from low to high the long average and sell when making the crossover from high to low.

Example of a rule-based algorithm, in this case with a short arithmetic mean of 15 sessions and an arithmetic mean of 150 sessions. I would buy when the short mean crosses the long mean from low to high and sell when the short mean crosses the long mean from high to low.

 

The design of these algorithms is a complex task that requires an appropriate combination of logical reasoning and creativity. In addition, development usually involves a lengthy trial-and-error phase to arrive at a winning strategy.

Many of these algorithms need to be adaptive and evolve during their lifetime, because when a strategy is very profitable, other agents try to replicate and exploit it and, as a consequence, it can become a losing strategy.

 

Process of creation of a trading algorithm using Machine Learning

The process of creating a trading algorithm using Machine Learning can be broadly divided into the following steps:

  1. Definition of the problem statement
  2. Reading historical data on the price of one or more assets
  3. Data health checks
  4. Configuration of the target variable
  5. Feature engineering
  6. Division of data into two sets: testing and model validation and training
  7. Backtesting of results and analysis of algorithm performance

 

For example, following the same numbering of the steps we would do:

  1. We want to know if we have to buy or sell shares of company X.

  2. Obtindríem les dades històriques de l’empresa X

  3. We would check that there are no jumps in the dates of the data obtained, that there are no duplicates, that there are no meaningless maximums or minimums,

  4. As a “target variable”, for example, we can define that we want to know if the shares of company X will rise by 5% in the next 5 days. As we have the historical data, for each of the days, we can look at what has happened the following 5 days and mark the target variable of that day with a “Buy” or “Do nothing”.

  5. As “features”, for example, I can use technical trend indicators such as the ADX,  an oscillator type such as the  RSI (Relative Strength Index) and  one that tells me the volatility or correlation between two  time averages. Let’s make the corresponding calculations for each of the days to obtain the “features” that should be used to predict our “target variable”.

  6. We will divide the “DataSet” into two sets taking into account the temporality. For example, the data from January 1, 2015 to January 1, 2021,  and we will keep the data for the second period, from January 2, 2021 to January 31, 2022 to validate.

  7. Backtesting of results and analysis of algorithm performance

Once the model is obtained through different Machine Learning algorithms, we would do what is known as the  a “Backtesting”, that is to say, we would test the strategy obtained from making the model in the previous step with the data of the last year, in this way we could check if the algorithm would have won or lost and in what amount.

 

Result of the portfolio value over time using the strategy in the previous graph. Flat stretches indicate that we are out of the market.

 

The fact of obtaining a good trading algorithm for a certain value or a certain set of values is not guaranteed, but it offers a “statistical” advantage when making decisions. 

If you are satisfied with the performance of the backtesting strategy, then the next step would be to start trading in manual mode (paper trading). If this is not the case, you should adjust your strategy to obtain an acceptable performance. And once the results in manual mode are satisfactory, you could start automated trading through an online broker.

Figure  showing the implementation process of an automatic trading strategy, extracted from the book (1).

 

Can these trading algorithms be rented?

Following the explosion in the use of algorithmic programs to invest in the stock market, a whole industry has emerged. While large financial institutions have their own research departments to develop customized software, small investors can also benefit from these models thanks to rental robots.

 

Where can I learn more?

You can consult the example code that generates the strategy of this article in the repository of , Github

On the net you can find a lot of articles, Moocs and videos,  personally I recommend these online courses that at this point are free:

 

References