1450
Back to the Future: performance testing of the trading robot with the help of historical data
77,599,779
We have previously examined the issue of mandatory development stages trading strategy for the stock market. One of the most important steps is the performance testing strategies on historical data - backtesting. Today we'll talk about it exactly.
What is it h4> In simple terms, backtesting is to run the algorithm trading strategies using historical financial data. Algorithm to find these or other stock events ("signals"), will generate orders for the purchase or sale of financial instruments - these operations will have an associated gain or loss.
Source: habrahabr.ru/company/itinvest/blog/238839/
We have previously examined the issue of mandatory development stages trading strategy for the stock market. One of the most important steps is the performance testing strategies on historical data - backtesting. Today we'll talk about it exactly.
What is it h4> In simple terms, backtesting is to run the algorithm trading strategies using historical financial data. Algorithm to find these or other stock events ("signals"), will generate orders for the purchase or sale of financial instruments - these operations will have an associated gain or loss.
The total amount of gain or loss (profit and loss, P & L, PnL) for a predetermined time in the trading strategy will be an indicator of the success or failure of the algorithm.
There are several objectives sought by developers of commercial software using backtesting:
- Filter - Each strategy has certain indicators for prizvoditelnosi and efficiency, which are incorporated into it by the developer. Accordingly, any strategy that does not allow to achieve these goals should be "filtered".
- Simulation - using backtesting developers can test various market models (changing liquidity conditions, transaction costs, speed the processing of orders, delays in channels, etc.) without the risk of losing real money .
- Optimization - using the "run" strategy on historical data can improve its performance in specific market situations.
- Verifying b > - using the test developer can understand if there were no mistakes in the description of the strategy in the code.
Misconceptions about backtesting h4> Renowned expert on stock trading, quant developer and exchange robots Michael Hulls-Moore, convinced that novice developers exchange systems often make mistakes when they are created due to certain misconceptions. In particular, the expert приводит four of these misconceptions:
Waiting equally good results in the future h5> Often, the developer is faced with the temptation to modify the test parameters to obtain more conclusive results.
Thus, if in the case of historical data it is possible to change anything and accurately predict the result, the "combat" mode the robot can work quite as effectively. It is necessary to measure the performance of strategies for different values of the input parameters.
Using "future" data h5> In some cases, the creators of trading strategies include data set assumptions about the future status of the market. In case of errors in the code incorrectly calculating the optimal parameters for the strategy or incorrect use of extreme price values (maximum and minimum), the launch of such a strategy in the real market may fail (this is one of the most frequent reasons why historical data strategies work effectively than in real time).
Incorrect assessment of his psychological stability h5> During the test developer sees the final performance of their algorithm. If at some point in time (say, a year or five years), the system makes a profit, it is tempting to ignore the subsidence of the deposit (of losses), which occurred in the course of this path to success. People think that they can easily survive the loss of 25% of their money (after all, then the robot must recoup).
In practice not all have enough resilience to survive these moments without making rash actions (and if the algorithm allows for the loss of 25% of the money on the history, and the reality of this situation is very likely), which often lead to even greater losses.
What parameters should be considered h4> Developers trading systems must take into account many different parameters that can affect the ultimate financial viability of a particular strategy.
Transaction costs h5> Novice traders often pay attention only to the performance of their algorithm directly on the market, but forget to take into account the associated costs, which could offset the entire income earned. The most obvious costs in this case will be a fee for transactions charged exchanges and brokers (at ITinvest on some tariffs fees roughly correspond to the exchange).
slippage and delays h5> Slippage is the difference in price between the one on which trading robot intended to carry out the transaction, and the one on which it actually took place. For the "delivery" in order kernel exchange trading system takes time. In the case of high-speed trading robots (HFT) in the account every millisecond, for which the price may change slightly, making the deal less favorable (or unfavorable general).
Some financial tools have high volatility (the price changes frequently), so when you work with them you must make allowances for possible slippage.
The impact of liquidity h5> When working with relatively illiquid instruments trader should keep in mind the possible impact that the actions of its trading system will have on the market. If a certain share buy and sell are not many people, the order to buy a significant number of such shares can greatly change their price. To avoid this situation it is necessary to teach a robot to break the deal on a large number of small orders that can not strongly affect the market.
The types of trading orders h5> The operation of a trading strategy is influenced by the fact some of its trading orders developer plans to use for transactions. Most often, traders have resorted to market-orders and limit-orders.
Order market («Market") is performed immediately formed on the market at the moment the price of the financial instrument (stocks, futures , option etc.) Accordingly, if necessary, a major transaction, such as buying a large number of shares, the market order will lead to the fact that several transactions occur at different prices - the market may not be the right number of people willing to sell shares at the same price, then buying all their shares, the robot moves to the next proposed price and so on.
Market orders are aggressive tool - they will always be executed, while the final price of the transaction is unknown to the trader.
Limit Orders type allow the robot to identify the worst price at which it makes sense to conduct the transaction. Such an order may remain unfulfilled (if the market was not wishing to buy or sell at a specified price), or partially filled (did not find enough willing), so that is considered more passive transactions.
Their advantage is undoubtedly the fact that the transaction price is determined in advance. List of current exhibited type Limit orders is called a queue of requests (Order book) and is displayed in a separate window trading terminals.
When testing strategy, it is important to pay attention to her behavior when using market and limit orders. In the case of all requests modeled incorrectly trading strategy may show inferior results when operating in real time, as compared with running on historical data.
Tools for backtesting h4> There are quite a large number of public systems that can be used to test financial strategies:
- MS Excel - familiar to each and every Microsoft Excel can be used for writing automated trading systems. Most brokers will allow you to link this tool to their software products (upload data and generate trading signals using VBA). The downside of such a decision will not be high speed, and plus free and quick implementation of simple strategies. Alternative - Open Office
- Matlab - software environment designed for complex calculations. There are plug-ins for use in stock trading. With it you can create a small script which nevertheless describe quite complex strategies. Minus - system and paid dearly. Alternatives for the Russian market TSlab and StockSharp . Also traders use to create automated trading systems products MetaStock , Wealth-Lab and Omega.
- C ++ / C # - programming languages that are prevalent in the financial world. Gradually gaining popularity of Java and Scala.
- Built-in tools trading terminal in the - in some trading terminals have built-in tools for creating trading robots and backtesting strategies. Corresponding plugin can be installed in the terminal SmartX . To write the robot uses a scripting language TradeScript .
The window for back-testing plugin for creating robots TradeScript terminal SmartX i>
Conclusion h4> backtesting is a key step in developing a trading strategy, without which it is difficult to count on adequate job trading robot in "combat" conditions of the real market. It is important to understand that the successful work strategies on historical data does not guarantee the same results when used in real trade in real time.
In addition to testing on historical data to developers worth checking out the program in real time - it can be done using a special test trading systems that provide exchanges and brokers. With the help of such risk-free systems with virtual money, you can debug the robot reaction to changing market conditions - usually the data in such cases provide stock exchanges (delayed or 'decimated »).
At present, all, thank you for your attention. We will be happy to answer questions in the comments.
Warning! B> In ITinvest a vacancy Developer GUI C #, work is to implement frontent development of software products for trading on the exchange. Details of the link www.itinvest.ru/about/vacancies/programmer-gui-c/.
P.S. If you spot a typo or error - write a personal message and we will promptly fix it.
Links and posts on the topic:
- Successful backtesting of algorithmic trading strategies - Part I
Source: habrahabr.ru/company/itinvest/blog/238839/
Stage of maturation of human
For the protection of airports in the Netherlands have created a robotic birds