📜 ⬆️ ⬇️

Finding inefficiencies: What you need to know about creating strategies for trading on the exchange



There are a lot of publications in blogs, articles and books devoted to optimizing the testing of trading strategies. At the same time, almost no one writes about how to build such a system from scratch. The author of the Financial Hacker blog decided to correct this situation and create a cycle of articles on the topic of developing trading strategies - we present to your attention the main theses of the first material .

The taste and color


In fact, there are two main methods for building online trading strategies. The first is focused on a specific model, the second - on data mining. In the first case, we are dealing with the concept of an inefficient market. The method involves working with the psychology of traders, the economy, the microstructure of the markets, as well as any external phenomena that may affect stock prices. Inefficiency leads to anomalies in the price curve or the emergence of certain patterns of price fluctuations that you can try to predict and use in the trading algorithm. Among the strategies based on a specific model, we can recall the strategy of following the trend, mean reversion, price cycles and clusters, statistical arbitrage and seasonality.
')
There is a problem here - this model is not realistic. This is a simplified image of reality. This model cannot be proven or disproved. Its reliability can be justified only through the impact on the price curve. The applicability of such a model depends on a certain long-term stability of the actions of the anomalies predicted with its help. You can check it only through a high-quality testing algorithm.

Pure data mining works differently. It is used to study patterns of price changes and build on them a specific algorithm. What reasons have caused changes in the market here is not so important. It is important that they continue to operate in the future. This approach has led to the emergence of trading systems using self-learning software. The most popular technique in this case is the method of selection, trial and error, the use of candlestick patterns, regression, autocorrelation, the k-means method, neural networks, the decision tree.

The advantages of data analysis are that you do not need to guess about the state of the market. Disadvantage: all these methods usually reveal a bunch of random patterns and then generate a bunch of useless strategies. Separating random patterns from those that actually influence the state of the market is not an easy task. Currently, it is not known about successful trading systems built solely on data analysis.

Who is smarter: the trader against the market


Obviously, no trading system will work in the absence of any market inefficiencies that could be exploited for profit. But even if inefficiency exists, nothing will come out as long as it cannot be used, and as long as well-armed players do it for you. Therefore, you need to be able to conduct operations better than most market participants.

Here are three main hypotheses regarding market inefficiencies that you have probably heard about:


Few people today still believe in the first hypothesis. Markets do not behave rationally and efficiently. There are plenty of examples. Most often, the value of companies is far from their “real” value. But even in such a situation, you can see some patterns. Markets react quickly and harshly, following rumors and news. But, if the information is less defined and requires minimal interpretation, the reaction rate decreases markedly. Consider a typical example of this market behavior:

Swiss franc case


In September 2011, the Swiss National Bank set the price limit for the Swiss franc. The idea was to protect the tourism industry and exports against the background of an overvalued rate. The limit was set at 1.20 for EUR / CHF (euro / franc).

In general, the price cap is a very rare step and a very significant example of market inefficiency. All this can be immediately transferred to a very profitable, almost risk-free trading system. In a normal situation, a strong market response can be expected when the EUR / CHF pair approaches the value of 1.20. But in practice, the reaction was greatly extended in time.

Of course, Switzerland is a strange place on the map of Europe. Most US trading companies know only what high-quality cheese is made here. Either they did not notice the decision of the National Bank, or the European offices of these companies forgot to report it. The newsletter traveled across the Atlantic for three months, fighting pirates, storms and storms along the way, until finally it reached New York.

So what can you do if you know about the price cap? Only by January 2012, the major players in the market had an idea. And it was not about developing a trading system, just buying up francs to put pressure on the ratio of the EUR / CHF currency pair.



Changes in the price of the pair EUR / CHF in September 2011 - August 2012

The point was that when the price reaches its limit value, the benefit can be obtained by breaking through it. At stake was a lot of money, patience and strength. Since May 2012, the EUR / CHF price has been extremely close to the value of 1.20. But the collapse of the price cap did not happen. During 2012, Switzerland built a mighty $ 200 billion wall to protect its price cap. All attacks were repelled. In January 2013, the raiders retired.



Changes in the price of the pair EUR / CHF in September 2012 - May 2013

Retrieved, making way for the work of algorithmic systems. During the 2012 battle, they were forced to stand aside. Private traders did not have so many means to join the game. In January 2013, the first craftsmen began to use market inefficiencies in their favor. They applied the Grid Trade method — a strategy based on the wave nature of the market, earning on volatility and independent of the price direction. It launched a machine for printing money.

Algorithm "printing machine"


Grid is a very simple system. It places pending and short-term orders at fixed values ​​above and below the current price. Profit is obtained when market deviations. Orders are opened and closed when the price crosses the grid values ​​in either direction. Hypothetically, the degree of gain here approaches 100%, but in practice this level cannot be achieved. Traders typically use a virtual hedging mechanism that opens and closes a position instead of opening a new one in the opposite direction. This increases the total profit and allows you to control losses. So the winning percentage here varies in practice in the region of 60%.

Here is an example of a Zorro script for such a system:

//  ,        bool isFree(var Price,var Grid,bool IsShort) { for(open_trades) { if(TradeIsShort == IsShort && between(TradeEntryLimit,Price-Grid/2,Price+Grid/2)) return false; } return true; } //        EUR/CHF int run() { BarPeriod = 60; Hedge = 5; // activate virtual hedging var Grid = 20*PIP; // set grid distance to 20 pips var Close = priceClose(); // place pending trades at 5 grid lines above and below the Close int i; for(i = Close/Grid - 5; i < Close/Grid + 5; i++) { var Price = i*Grid; // place short trades with profit target below the current price if(Price < Close && isFree(Price,Grid,true)) enterShort(1,Price,0,Grid); // place long trades with profit target above the current price else if(Price > Close && isFree(Price,Grid,false)) enterLong(1,Price,0,Grid); } } 

Grid is a typical model-oriented system. It implies that certain market conditions keep the price in a certain range. For example, the restriction prevents the EUR / CHF pair from dropping below 1.20. But it also cannot rise too high, given the fact that the Swiss National Bank will eventually have to buy back all the francs that they sold in order to maintain a certain value. All these are necessary conditions for the application of the Grid. Without them, this would be a usual roulette, and would fill up the list of irrational trading methods.

Here is an example of applying the method for EUR / CHF from P & L in 2013:



The graph shows significant price fluctuations with significant declines in January and May. But because of the limit, we can predict the maximum losses and just keep enough funds in the account. In this case, annual revenue was 130%, Sharpe ratio - 1.7. Virtually no risk until the price limit is lifted.

News about this strategy was distributed throughout 2013. Not surprisingly, many market participants, private investors, wanted to jump into the departing train. Three years after the decision of the Bank of Switzerland, thousands of such systems were already operating on the market. As a result, the volatility of the EUR / CHF price has steadily decreased.



Volatility is a key condition for the Grid method. The smaller it is, the less income. In order to compensate for its decline, you need to invest more and compress the grid. But we have a natural limit. The size of the grid can not be less than the payment of the transaction. By the fall of 2014, volatility fell to virtually zero. This was accompanied by a significant drop in prices, as if one of the major players (most likely the Swiss National Bank itself) is persistently selling euros and buying francs in anticipation of a major event. For private traders, it's time to get out of the game. The further fate of the Swiss franc is well known. In January 2015, the price limit was lifted.

For a couple of minutes, the EUR / CHF price has slipped to values ​​substantially below 1.20. Unlike the situation that occurred four years ago, the market reacted instantly. Many have suffered. The most interesting thing is that the “real” ratio of the pair, based on the relative purchasing power of each currency, all this time was kept at 1.50.

findings


Source: https://habr.com/ru/post/279321/


All Articles