Note: This post is written by the British developer and financial analyst Michael Halls-Moore, who is a professional in the so-called Quantitative trading. From our point of view, the information contained in this topic may be of interest to technical specialists and developers who are interested in the stock market and have the skills to create, for example, successful trading robots, but do not know where to start. Therefore, the topic will be considered in this context, in addition, the text is adapted to Russian realities, and some terms have been translated accordingly. We welcome your comments! (Amendments to the translation is better to send in private messages).
Algorithmic trading is an extremely difficult area of ​​finance, and in order to master the amount of information that will allow you to create your own trading system or get a developer into a financial company or fund, it will take a lot of time. A lot of programming experience is essential for successful work in this market, at least the algorithmic dealer has to be well versed in languages ​​such as C / C ++ (in the financial field, Java is promising) and Python, Matlab and R (
the Russian market is gaining popularity in US TradeScript - approx. Transl. ).
Any high-frequency trading system consists of four main components:
')
- Identification of strategy - that is, the definition of trade strategy, the exploitation of the advantages contained in it and the choice of the frequency of trade.
- Strategy backtesting - obtaining historical data on trades and “running” strategies on them, analyzing results and optimizing weak points.
- The engine is the part that connects to the brokerage trading system ( ITinvest recently launched the new Matrix system - approx. Transl. ), Automatically trades and adapts to changes in the market to reduce costs.
- Risk management - the allocation of capital for trading in the best way, the definition of a sequence of actions in case of unsuccessful circumstances in the market.
Let's start with the first item and talk about how to choose a trading strategy.
Trading strategy
In trading, any action is always preceded by a stage of collecting and studying information. Before choosing a strategy for trading, it is necessary to analyze the initial data such as the amount of funds available, and also consider how well the new strategy is combined with those already used. Individual traders are simply obliged to pay great attention to transaction costs and to try to reduce them in every way, and an optimal trading strategy is chosen accordingly.

Contrary to popular belief that “no fool will share a strategy that makes money,” in fact, in public sources you can find information about strategies that really work. In addition, analysts and scientists sometimes publish the results of their research and financial experiments. There are quite a few blogs on the topic of algorithmic trading in the English language (in Russia, sometimes interesting topics are skipped on the Smart-lab.ru resource), and information about the trading strategies of funds sometimes gets into the press.
Of course, no one will discuss in the public field all aspects and details of setting up a profitable strategy. The key to profitability lies precisely in the understanding of what parameters a strategy should have, as well as its “fine tuning”. Nevertheless, there is almost one hundred percent way to create your own strategy for this “theft” of other people's ideas and their subsequent refinement.
Most strategies can be divided into two large groups - “playing on inefficiencies” and “following the trend.” Strategies of the first type exploit market inefficiencies (for example, the spread in the price of related financial instruments) and the fact that in the short term, the price of assets often returns to its original level. Trend strategies play on the psychology of investors and the actions of funds, trying to “jump” into the train of a new trend and have time to collect profit on this until the movement turns in the opposite direction.
Another important point of algorithmic trading is its frequency. Low Frequency Trading (LFT) implies the possession of a financial instrument for a time that exceeds one trading day. Accordingly, in high-frequency trading (HFT), all operations are “intraday”, that is, within one trading day. There are also so-called ultrahigh-frequency strategies (UHFT), which involve holding an asset for seconds or even milliseconds. A large development in the world and Russian markets has now received high-frequency trading.
After the strategy is chosen, it is necessary to test its effectiveness on historical data. This process is called back testing.
Backtesting
The essence of backtesting is to confirm or disprove the profitability of the chosen strategy running on historical data. Knowledge of the results that the strategy would have shown in the past suggests its effectiveness in the current market situation. Of course, the fact that the strategy has brought a virtual million on historical data does not guarantee success in the real world.
In backtesting, the most important point is the availability of data on past trading sessions, to launch a strategy. These data can be obtained in several ways - often they are provided by brokers and exchanges, but there are also third-party data providers.
It is also important to determine the metrics by which it will be determined how successfully or unsuccessfully the strategy “on history” has worked out. The standard in the industry are the concepts of "maximum drawdown" and
the Sharpe ratio . Maximum drawdown is the maximum loss on a portfolio for a certain period (usually in a year). For low-frequency strategies, the drawdown may be greater than for high-frequency ones, due to some statistical factors. The backtest will show the maximum drawdown of the portfolio that could have taken place in the past, which would give a rough idea of ​​what to expect in this regard when working in the real current market. The Sharpe Ratio is an indicator of the efficiency of the investment portfolio (asset), which is calculated as the ratio of the average risk premium to the average deviation of the portfolio.
After the strategy has been tested and all the identified bottlenecks have been eliminated, the possible drawdown is minimized and the Sharpe ratio is maximum, it’s time to proceed to the development of the trading engine itself.
Trading module
The trading engine is the means by which the list of transactions to be executed in accordance with the trading strategy is transferred to the broker's trading system. The process of generating orders can be half or fully automated, and the mechanism for their execution can be manual, half manual (one-click) or fully automated. For low-frequency strategies, manual or half-manual entry of orders is most often used. For HFT strategies that matter every millisecond, the fully automatic method is mainly used.

The main points to consider when developing a trading system are ensuring reliable and fast connection to the brokerage trading system (usually
via API ) or providing
direct access to the exchange , minimizing costs (including broker and exchange commissions, and possible slippage).
Transaction costs are one of the main things that the HFT trader should think about. They usually consist of three components: commissions of the broker and the exchange (and taxes), slippage (the difference between the price at which the transaction was planned to be made and the price at which it actually passed), and the spread of a specific financial instrument (the difference between the price purchases and sales - bid / ask). Spread is not a permanently fixed value and depends on the current market liquidity.
High transaction costs can make a potentially very profitable strategy with a good Sharpe ratio completely unprofitable and vice versa. With the help of backtesting, it is quite difficult to predict transaction costs correctly; for this, it is usually necessary to obtain historical tick data from the exchange, including information on bid / ask prices.
It is also necessary to remember about the difference between the efficiency of the system in the real world and what it shows on historical data. The difference can be quite substantial, and there are many reasons for this. Software bugs and errors of the trading strategy itself may not appear during backtesting, but play an important role in real work in the market.
Examples of creating trade robots on
TradeScript .
Risk management
The concept of "risk" includes all of the above hazards. The risk consists of technological hazards (for example, a sudden server failure), a broker's risk (company bankruptcy), and indeed everything that could potentially interfere with the intended functioning of the trading system.
Part of the risk management is the process of optimizing capital (its distribution among different strategies). This is a rather complicated process, using a large amount of “mathematics”. The industrial standard describing the ratio of the optimal distribution of capital and obtaining the maximum effect from the work of trading start-ups is
the Kelly criterion .
Another important component of risk management is the definition of a trader’s own psychological portrait. Each person has some traits that may hinder successful trading in the market. In the case of algorithmic trading, the psychological effect plays a smaller role than in the case of “manual” trading in the market, but it is still present - after all, a person who may want to fix a loss too early or be in a hurry to close a position is afraid of an increase in losses.
More information about risk management can be found in
this topic .
findings
Algorithmic trading is a very complex area of ​​human activity, but it is also a very interesting area of ​​finance. In order to have chances to achieve success in this matter, you just need to master programming at a good level. It is necessary to train by creating trade modules independently (trading engines, data analyzers, tools for backtesting strategies), using available resources - after all, it’s about your own money that no one wants to lose.
Related articles: