# Study on the Effectiveness of the Investment Strategy Based on a Classifier with Rules Adapted by Machine Learning

Authors: A. Wiliński; A. Bera; W. Nowicki; P. Błaszyński
Journal: ISRN Artificial Intelligence
 (2014)

---

## Abstract

This paper examines two transactional strategies based on the classifier which opens positions using some rules and closes them using different rules. A rule set contains time-varying parameters that when matched allow making an investment decision. Researches contain the study of variability of these parameters and the relationship between learning period and testing (using the learned parameters). The strategies are evaluated based on the time series of cumulative profit achieved in the test periods. The study was conducted on the most popular currency pair EURUSD (Euro-Dollar) sampled with interval of 1 hour. An important contribution to the theory of algotrading resulting from presented research is specification of the parameter space (quite large, consisting of 11 parameters) that achieves very good results using cross validation.


---

## Body

## 1. Introduction

The aim of this work is to verify the hypothesis of patterns extraction possibility from time series, which could be classified as providing better statistic and more accurate prognosis. Another important objective is confirmation of assumption that financial markets time series have a “memory” of pattern efficiency in a time period following the time series that was used in learning period. This approach is consistent with the classic aim of machine learning shown by Murphy [1], especially to financial markets described by Satchwell [2]. Research intention was also to follow reproducibility principle of other researchers’ studies, as well as by themselves, in other data environments, to make sense of the use of computational intelligence in its reasonable reproducibility [3, 4], in extracting of the regularity from chaos [5, 6].An investment strategy with a relatively high complexity (measured by the number of factors included in the model) was built, derived from a strategies group called strategy of simple rules. In the literature those strategies are considered to be mainly strategies based on moving averages—their intersections and derivatives shown, for example, by Brock et al. [7], Cai et al. [8], and many other authors [9–11]. Of course, the world of algorithms as well as prediction methods using a completely different nature, such as regression [12], multiple regression [13, 14], Fourier and wavelet transforms, and many others [15, 16] is plenteous. These methods are used as a basis for comparison; however the main focus is on mentioned simple rules.This paper proposes strategy, which differs by suggesting different behaviors than the ones proposed when using Bollinger’s Band, which has its foundation in a band built in an unusual way. According to the strategy based on that band, generally it can be assumed that the trend is horizontal and it is recommended to open position to the center of the band, after its cross by the price from the inside. In proposed strategies, another band that is based on maxima of the maxima and minima of the minima of last several candles is used.Considered strategies move away from the principle of opening positions to the center of the band. In one modification, hereinafter referred to as substrategy, position opens into the center of the band, whereas in another one, position opens on the outside. By treating the two considered substrategies as an entirety and as strategies that are mutually retrieving (although a more appropriate word would be complementary) it is assumed that, in the selected trading section, opening positions in opposite directions, of course not at the same time, can be done intentionally and effectively. During the trading, nature of the market (trend, volatility) may change. The market may be in some periods horizontal, in other trended. It is appropriate to seek all opportunities for profit. A similar philosophy is applied by several Krutsinger correspondents [17], who belong to most prominent traders in USA, who advocate unfounded reversal of the direction of opening the positions in case of series of failures.Returning to the issue of complexity of strategy, there are often opinions that the growing complexity of the prediction model is not indicated, because in learning section it leads to overfitting [1, 8, 14]. This results in a greater error in the test sections. The problem of selecting the proper ratio between learning and testing phase is still unsolved for the nonstationary time series [5, 18]. In this situation the right approach seems to be the use of the idea of computational intelligence [3, 6] which helps to compute adequate length of learning and testing period.Therefore in this paper two rather complex strategies (described below) are used, achieving results that are assessed as rewarding. Attention is drawn to the fact that the satisfaction problem belongs to the other sciences and depends on the trader’s individual perception of the relationship between profit and risk, greed and fear [19]. However, the issue of emotions in the trade is not considered here, but only noticed because there is the assumption that trading is done automatically.The tests were deliberately performed in a fragment of the time series of a heavily diversified course, which contains both rising and downward trends as well as horizontal elements (Figure1). This time series consists of 4734 1-hour candles, of the most important and the most fluent currency pair EURUSD from October 22, 2012.Figure 1
Time series EURUSD 1 h.A choice of parameters essential for defining the rules of opening and closing positions is crucial to the effectiveness of the strategy. Parametric space presented in this paper is a result of many trials prior to its final approval.


## 2. Characteristics of Investment Strategies

The objective of the two strategies considered is to make investment decisions about buying or selling—opening long or short position in the market studied—the currency pair EURUSD. The decision is based on the intersection of the current price and one of two barriers of additional indicator, called the ribbon. The band is made of two values calculated at the opening of each candle on the basis of historical data of the market. During the candle, values of the band do not change; therefore, barriers are creating step functions. In case when the current price exceeds any of the barrier values (goes out of the band), a decision to buy or sell is made—the type of decision depends on the variant of the considered strategy—decision for substrategy TewiMiC is different than in case of TewiMiD. Names of the strategies are derived from the name of the project, in which the research was carried out.


### 2.1. Definition of the Band

The values of barriers forming a band are calculated using the maximum and minimum values of the last candle (OHLC: Open, High, Low, Close prices). In the case of the upper band, it is the maximum of the maximal values of then last candles, whereas in the case of the bottom band, it is the minimum of the minimal values of m last candles:
(1)topBorder=max(Hi-n,…,Hi-1),bottomBorder=min(Li-m,…,Li-1).As mentioned earlier, strategy comes in two versions that differ in terms of opening the positions when crossing the band. These differences result from different investor assumption about currently prevailing market trend. In the first case it is believed that the trend has just started and positions need to be opened in accordance with it. In the second case, the play is against the trend. The two considered variants, TewiMiC and TewiMiD, are based on excesses of the lower limit of the band. TewiMiD implies existence of a downward trend, for which when crossing (down) the lower limit of the band, a short position (assuming the price drop) is opened. This is known in the literature and in trading as Sell Stop model.TewiMiC assumes the opposite case; therefore it is needed to open a long position (assuming the price increase). This is Buy Limit model.


### 2.2.  Strategy Parameters

Considered strategies are based on a objects classification (events that meet the conditions contained in the set of rules which depend on the value of certain parameters). Object—the event—is another candle. Rules are logical sentences like “if the price is greater than the upper barrier of the band” and the parameter is, for example, the upper barrier, which is a variable value.These parameters will determine whether the strategy will earn or lose. Appropriate selection of parameter values is therefore a key optimization issue in the use of the strategy. Considered strategies have 11 parameters, which are subject of optimization.p1
is the number of candles, based on which the calculation of the current value of the band barrier is made; for researched time series, value ofp1 generally ranges from 10 to 30;p2
is the number of steps forward, after which the position is closed in case when none other close conditions were met before; this value belongs to range from 3 to 40;p3
is StopLoss condition; usually it remained in range from 0.002 to 0.017 expressed in values of EURUSD, which in researched period stayed in range from 1.2 to 1.4, as can be seen in Figure1;p4
is TakeProfit condition, generally ranged from 0.0015 to 0.009;p5
is band buffer, offset from the barrier of the band defining the actual level of the expected crossing of the price, ranged from −0.002 to 0.003;p6
is maximum number of open positions at the same time, ranged from 3 to 20;p7
is the number of candles that determines average volume value; generally ranged from 2 to 10;p8
is maximum value of the difference between the current value of the volume and the average value calculated on the basis ofp7 candles back, ranged from 150 to 500;p9
is the number of candles on the cumulative profit curve, based on which current drawdown is calculated, ranged from 5 to 25;p10
is the highest acceptable drawdown on the cumulative yield curve; generally ranged from 0.0021 to 0.008;p11
is acceptable amount of the cumulative loss for all currently open positions, ranged from 0.0005 to 0.003.


### 2.3.  Conditions of Opening

As mentioned before, the signal to open the position is the intersection of the current price of the observed value and some barrier (that results from the calculated band). Special parameter called the buffer (p5) has been added, causing the offset of barrier from its actual value. Thus, the condition for opening TewiMIC strategy is
(2)if[(price<bottomBorder(p1)-buffor(p5)),((p5))(currentp6<p6),(Vol-meanVol(p7)<p8)]thenopenpositionlong,
where price is current value for EURUSD, bottomBorder (p1) is value of lower band barrier for parameter p1, here minimum of last p1 minima, buffor (p5) is value of buffer that moves said barrier, current p6 is number of currently opened positions, Vol is current value of volume (in the candle), meanVol (p7) is mean of volume of last p7 candles, and the opening condition for TewiMiD is as follows:
(3)if[(price<bottomBorder(p1)-buffor(p5)),((p5))(currentp6<p6),(Vol-meanVol(p7)>p8)]thenopenpositionshort.As a result of these conditions, long positions, in substrategy TewiMIC, are opened when three conditions are met simultaneously: crossing the bottom barrier reduced by buffer by the current price, the number of open positions is less than the limit (which is the optimized parameterp6), and the difference between the current volume and the average of the volume of the last p7 candle is less than the parameter p8.For TewiMiD strategy, analogously, with significant differences, short positions will be opened and it is advisable that current volume should be greater than the average. As the result of conducted research, authors concluded that volume (number of price changes in observed time frame—here during one hour) was the most important and most sensitive factor of decision model.These conditions can be met in two cases during the period of the current considered candle. They can be met immediately at the opening of the candle; that is, the opening value of the current candle is smaller than the barrier bottomBorder reduced by parameterp5. That condition can be met within the candle, when the current value of the price breaks through the lower barrier.The result of that is that we have two distinctly different opening conditions.


### 2.4.  Conditions of Closing

In both substrategies there are 7 cases of closing the open positions, which results in their complexity—both in terms of logic and calculation. This complexity, however, exhausts all the possible surprises and does not leave any opportunity for the unexpected market behavior. Of course, depending on the values of the parameters, frequency occurrences of closure cases can be very different.Firstly the terms for closing the long positions that were opened by conditions for TewiMiC will be presented.(1)
Opened long position will be closed, if at the close of the candle (i+p2) the position remained open, where i is number of candle, which was opened.(2)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(4)PriceO(i+k)-Price(i)<-SL,wherePriceO(i+k) is the opening value for (i+k)th candle and SL is StopLoss (level of acceptable risk in one trade) in pips.Then the profit (in this case loss) will be calculated as(5)Profit=PriceO(i+k)-Price(i).(3)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(6)(PriceO(i+k)-Price(i))>-SL,(LowPrice(i+k)-Price(i))<-SL.Then the profit (in this case loss) will be calculated as(7)Profit=-SL,where LowPrice(i+k) is a minimum value of (i+k)th candle.(4)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(8)PriceO(i+k)-Price(i)>TP,whereTP is TakeProfit (maximum reward level in single trade) in pips.Then the profit will be calculated as(9)Profit=PriceO(i+k)-Price(i).(5)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(10)(PriceO(i+k)-Price(i))<TP,(HighPrice(i+k)-Price(i))>TP.Then the profit will be calculated as(11)Profit=TP,whereHighPrice(i+k) is the maximum value for (i+k) candle.(6)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(12)PriceO(i+k)>topBorder(i+k).Then the profit will be calculated as(13)Profit=PriceO(i+k)-Price(i).(7)
Position will be closed if inside the next (i+k)th—the candle after ith candle, in which the position was opened, following condition is met:
(14)Price(i+k)>topBorder(i+k).Then the profit will be calculated as(15)Profit=topBorder(i+k)-Price(i).In substrategy TewiMiD conditions will look slightly different.(1)
Opened short position will be closed if at the close of the candle (i+p2)th the position remained open.(2)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(16)Price(i)-PriceO(i+k)<-SL.Then the profit (in this case loss) will be calculated as(17)Profit=-PriceO(i+k)+Price(i).(3)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(18)(-PriceO(i+k)+price(i))>-SL,(-HighPrice(i+k)+Price(i))<-SL.Then the profit (in this case loss) will be calculated as(19)Profit=-SL.(4)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(20)Price(i)-PriceO(i+k)>TP.Then the profit will be calculated as(21)Profit=-PriceO(i+k)+Price(i).(5)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(22)(-PriceO(i+k)+Price(i))<TP,(-LowPrice(i+k)+Price(i))>TP.Then the profit will be calculated as(23)Profit=TP.(6)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(24)PriceO(i+k)>bottomBorder(i+k).Then the profit will be calculated as(25)Profit=-PriceO(i+k)+Price(i).(7)
Position will be closed when inside the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(26)Price(i+k)>bottomBorder(i+k).Then the profit (in this case loss) will be calculated as(27)Profit=-bottomBorder(i+k)+Price(i).Additional conditions that are checked with each closing are the rules containing parameters p9, p10, and p11. These parameters are found in the rules limiting the risk of an unacceptable failure. Moreover, the principle stating that in the case when the opening took place at the beginning of the candle, it is permissible to keep it open until following candle is opened was used. Because of that, it was possible to avoid ambiguity involving the unpredictable sequence of the SL and TP.


## 2.1. Definition of the Band

The values of barriers forming a band are calculated using the maximum and minimum values of the last candle (OHLC: Open, High, Low, Close prices). In the case of the upper band, it is the maximum of the maximal values of then last candles, whereas in the case of the bottom band, it is the minimum of the minimal values of m last candles:
(1)topBorder=max(Hi-n,…,Hi-1),bottomBorder=min(Li-m,…,Li-1).As mentioned earlier, strategy comes in two versions that differ in terms of opening the positions when crossing the band. These differences result from different investor assumption about currently prevailing market trend. In the first case it is believed that the trend has just started and positions need to be opened in accordance with it. In the second case, the play is against the trend. The two considered variants, TewiMiC and TewiMiD, are based on excesses of the lower limit of the band. TewiMiD implies existence of a downward trend, for which when crossing (down) the lower limit of the band, a short position (assuming the price drop) is opened. This is known in the literature and in trading as Sell Stop model.TewiMiC assumes the opposite case; therefore it is needed to open a long position (assuming the price increase). This is Buy Limit model.


## 2.2.  Strategy Parameters

Considered strategies are based on a objects classification (events that meet the conditions contained in the set of rules which depend on the value of certain parameters). Object—the event—is another candle. Rules are logical sentences like “if the price is greater than the upper barrier of the band” and the parameter is, for example, the upper barrier, which is a variable value.These parameters will determine whether the strategy will earn or lose. Appropriate selection of parameter values is therefore a key optimization issue in the use of the strategy. Considered strategies have 11 parameters, which are subject of optimization.p1
is the number of candles, based on which the calculation of the current value of the band barrier is made; for researched time series, value ofp1 generally ranges from 10 to 30;p2
is the number of steps forward, after which the position is closed in case when none other close conditions were met before; this value belongs to range from 3 to 40;p3
is StopLoss condition; usually it remained in range from 0.002 to 0.017 expressed in values of EURUSD, which in researched period stayed in range from 1.2 to 1.4, as can be seen in Figure1;p4
is TakeProfit condition, generally ranged from 0.0015 to 0.009;p5
is band buffer, offset from the barrier of the band defining the actual level of the expected crossing of the price, ranged from −0.002 to 0.003;p6
is maximum number of open positions at the same time, ranged from 3 to 20;p7
is the number of candles that determines average volume value; generally ranged from 2 to 10;p8
is maximum value of the difference between the current value of the volume and the average value calculated on the basis ofp7 candles back, ranged from 150 to 500;p9
is the number of candles on the cumulative profit curve, based on which current drawdown is calculated, ranged from 5 to 25;p10
is the highest acceptable drawdown on the cumulative yield curve; generally ranged from 0.0021 to 0.008;p11
is acceptable amount of the cumulative loss for all currently open positions, ranged from 0.0005 to 0.003.


## 2.3.  Conditions of Opening

As mentioned before, the signal to open the position is the intersection of the current price of the observed value and some barrier (that results from the calculated band). Special parameter called the buffer (p5) has been added, causing the offset of barrier from its actual value. Thus, the condition for opening TewiMIC strategy is
(2)if[(price<bottomBorder(p1)-buffor(p5)),((p5))(currentp6<p6),(Vol-meanVol(p7)<p8)]thenopenpositionlong,
where price is current value for EURUSD, bottomBorder (p1) is value of lower band barrier for parameter p1, here minimum of last p1 minima, buffor (p5) is value of buffer that moves said barrier, current p6 is number of currently opened positions, Vol is current value of volume (in the candle), meanVol (p7) is mean of volume of last p7 candles, and the opening condition for TewiMiD is as follows:
(3)if[(price<bottomBorder(p1)-buffor(p5)),((p5))(currentp6<p6),(Vol-meanVol(p7)>p8)]thenopenpositionshort.As a result of these conditions, long positions, in substrategy TewiMIC, are opened when three conditions are met simultaneously: crossing the bottom barrier reduced by buffer by the current price, the number of open positions is less than the limit (which is the optimized parameterp6), and the difference between the current volume and the average of the volume of the last p7 candle is less than the parameter p8.For TewiMiD strategy, analogously, with significant differences, short positions will be opened and it is advisable that current volume should be greater than the average. As the result of conducted research, authors concluded that volume (number of price changes in observed time frame—here during one hour) was the most important and most sensitive factor of decision model.These conditions can be met in two cases during the period of the current considered candle. They can be met immediately at the opening of the candle; that is, the opening value of the current candle is smaller than the barrier bottomBorder reduced by parameterp5. That condition can be met within the candle, when the current value of the price breaks through the lower barrier.The result of that is that we have two distinctly different opening conditions.


## 2.4.  Conditions of Closing

In both substrategies there are 7 cases of closing the open positions, which results in their complexity—both in terms of logic and calculation. This complexity, however, exhausts all the possible surprises and does not leave any opportunity for the unexpected market behavior. Of course, depending on the values of the parameters, frequency occurrences of closure cases can be very different.Firstly the terms for closing the long positions that were opened by conditions for TewiMiC will be presented.(1)
Opened long position will be closed, if at the close of the candle (i+p2) the position remained open, where i is number of candle, which was opened.(2)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(4)PriceO(i+k)-Price(i)<-SL,wherePriceO(i+k) is the opening value for (i+k)th candle and SL is StopLoss (level of acceptable risk in one trade) in pips.Then the profit (in this case loss) will be calculated as(5)Profit=PriceO(i+k)-Price(i).(3)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(6)(PriceO(i+k)-Price(i))>-SL,(LowPrice(i+k)-Price(i))<-SL.Then the profit (in this case loss) will be calculated as(7)Profit=-SL,where LowPrice(i+k) is a minimum value of (i+k)th candle.(4)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(8)PriceO(i+k)-Price(i)>TP,whereTP is TakeProfit (maximum reward level in single trade) in pips.Then the profit will be calculated as(9)Profit=PriceO(i+k)-Price(i).(5)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(10)(PriceO(i+k)-Price(i))<TP,(HighPrice(i+k)-Price(i))>TP.Then the profit will be calculated as(11)Profit=TP,whereHighPrice(i+k) is the maximum value for (i+k) candle.(6)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(12)PriceO(i+k)>topBorder(i+k).Then the profit will be calculated as(13)Profit=PriceO(i+k)-Price(i).(7)
Position will be closed if inside the next (i+k)th—the candle after ith candle, in which the position was opened, following condition is met:
(14)Price(i+k)>topBorder(i+k).Then the profit will be calculated as(15)Profit=topBorder(i+k)-Price(i).In substrategy TewiMiD conditions will look slightly different.(1)
Opened short position will be closed if at the close of the candle (i+p2)th the position remained open.(2)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(16)Price(i)-PriceO(i+k)<-SL.Then the profit (in this case loss) will be calculated as(17)Profit=-PriceO(i+k)+Price(i).(3)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(18)(-PriceO(i+k)+price(i))>-SL,(-HighPrice(i+k)+Price(i))<-SL.Then the profit (in this case loss) will be calculated as(19)Profit=-SL.(4)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(20)Price(i)-PriceO(i+k)>TP.Then the profit will be calculated as(21)Profit=-PriceO(i+k)+Price(i).(5)
Position will be closed if inside the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(22)(-PriceO(i+k)+Price(i))<TP,(-LowPrice(i+k)+Price(i))>TP.Then the profit will be calculated as(23)Profit=TP.(6)
Position will be closed if at the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(24)PriceO(i+k)>bottomBorder(i+k).Then the profit will be calculated as(25)Profit=-PriceO(i+k)+Price(i).(7)
Position will be closed when inside the opening of the next (i+k)th, the candle after ith candle, in which the position was opened, the following condition is met:
(26)Price(i+k)>bottomBorder(i+k).Then the profit (in this case loss) will be calculated as(27)Profit=-bottomBorder(i+k)+Price(i).Additional conditions that are checked with each closing are the rules containing parameters p9, p10, and p11. These parameters are found in the rules limiting the risk of an unacceptable failure. Moreover, the principle stating that in the case when the opening took place at the beginning of the candle, it is permissible to keep it open until following candle is opened was used. Because of that, it was possible to avoid ambiguity involving the unpredictable sequence of the SL and TP.


## 3. Strategy Analysis

In both strategies a fixed period of learning is assumed (in the presented solution, 1000 one-hour candles), followed by a testing period. Data from learning period were used to find a class of patterns which allowed achieving maximum for the selected criterion, in this study Calmar ratio (which is defined as a final profit to maximum drawdown ratio) was selected. The same patterns were then searched during the test period and the test results were computed for previously unused data space. Of course, these results do not have to already be positive and acceptable and could negatively surprise investors. During the test the maximum rate of net profit (with transaction costs) was considered as a measure of the effectiveness of the investment. The authors believe that these two criteria in evaluating the quality of simulation results are legitimate. In the first phase of the validation, the training period is indicated for moderate and prudent risk management. In the test phase (in terms of actual trading) investor is mainly interested in profit.The main aim of the research was to obtain the most effective investment strategies by dynamic selection of test period duration. Later in this paper concepts of learning period, a fixed-length 1000 candles but with different start in time, were used. Immediately after period of learning there was a variable-length test period. The authors look for the best (by the criteria described above) length of the test period in their research. This most preferred length of the learning period can be understood in two ways. This length can be changed after each learning period adjusted by additional current information feedback about profits or losses in the test period. It may also be the average length of the test window established on the basis of several recent validations.Given that the search space is relatively broad and unknown (it is difficult to estimate how specific combination of parameters would influence strategy’s effectiveness) it is necessary to define its boundaries and then to find a combination of parameters that would maximize strategy’s efficiency. In the first step of the process, a pseudorandom strategy is used to find the boundaries of the parameter space in which may exist the optimal solution. Calmar ratio value was used to assess the adequacy of randomly selected parameter combinations for a given period of learning. It would be possible to use an iterative method that would traverse the search space with certain step. However it would be extremely time consuming method given that the space is 11-dimensional. In the second stage PSO (Particle Swarm Optimization) [20] algorithm, which already has been proved useful in finding optimal strategy parameters [21] and allows to find a satisfying combination of parameters values in relatively short time even in broad search spaces, was used. Search space for PSO algorithm has been defined in previous step. The objective function was to maximizing the Calmar ratio, as it was in the first step. The above tactic was used for each stage of the learning period and then checked “sustainability” of designated sets of parameters for test periods of different lengths—the basic rate of 100 candles and the other in the range of 10–400. Figure 2 shows how the research was conducted. Having historical data for 1000 candles, optimal parameters, for said data, have been found using approach described above. After the parameters search, tests was performed on the current data. The strategy for the learned parameters should be used as long as it will bring satisfactory results on new data. When results were no longer good enough, the next parameters search were performed on next piece of historical data. Thus, the authors aim is to determine the point where those parameters should be recalculated. Additionally, the authors set out to test a new standard of quality prediction. Now, extending the period of testing can produce better results, but more slowly or with local drawdown in comparison to first period, when the classifier “remembers” the nature of the market. This new criteria is profit attributable to one candle of the testing period.Figure 2
Methods of testing carried out to test the variable size window.Figures3(a) and 3(b) show the cumulative profit for the test period equal to 100 candles (hours) for the two examined strategies.Charts of the profit for both strategies with fixed test period size—100 candles.
(a)
Substrategy TewiMiC
(b)
Substrategy TewiMiDIt may be noted that the two policies, for the test period of 100, allow for systematic profit in examined period with only small drawdowns. Profit for the strategy TewiMiC 0.355, for TewiMiD profit is several times smaller and amounts to 0.094. But second strategy has smaller drawdowns. In addition, it is confirmed with the higher Calmar ratio—12.79—where the result for first of these strategies is 10.22. According to the authors, results are excellent, achieved on testing sections, not on the learning periods. On learning periods, of course, significantly better results were achieved with classifier matching. It is also clear that asymmetry results for the two strategies arise from different approaches—the first one is focused on horizontal trend, the other on a downward trend. The results depend on the nature of the market, which is automatically founded by learning strategies. Perhaps at another period of time, for other data these results could be different. In addition to the basic performance of the length of the test period equal to 100, a number of studies were conducted on different lengths of the testing period. There may be more favorable length of test window than arbitrarily selected window length of 100 candles.Results for TewiMiC. Figures 4 and 5 show the results of the strategy TewiMiC. First (Figure 4(a)) shows the effect of test duration on the profit curve in time. To show how long in the test period optimal results are achieved we plotted 2D (twodimensional) chart of final profit for each of the examined sizes. Figure 4(b) shows that the number of candles for achieving high and satisfactory results are attributable to 80–120. The window size 100 reflects quite well expected test section.Earnings accumulated over time, depending on the length of the test period for TewiMIC.
(a)
Results in 3D
(b)
Final resultsCumulative profit for one candle in time depending on the length of the testing period for TewiMiC.
(a)
Results in 3D
(b)
Final resultsDue to the different lengths of studied test periods, more reliable value used when making the decision is earnings per candle (that shows how much can strategy earn in one hour). This is shown in Figures5(a) and 5(b). On this basis, Table 1, it can be concluded that the strategy is most effective for the testing period length between 60 and 110 hours. It can therefore be concluded that the average window of 100 candles well “remembers” the learned classifier parameters. Many times in the classification of patterns, it is important whether patterns are frequent. Part of the dilemma is solved by introducing earnings per candle but also in Table 1 a count of opened market positions in the testing periods is presented.Table 1
Final profits and Calmar ratio for the selected length of the test period for TewiMiC.
Size
Profit
Profit per candle
Calmar
Open positions
Percentage (%)
30
0.0812
0.0027
2.4182
93
10
40
0.0768
0.0019
1.4048
120
9.68
50
0.1176
0.0024
2.4069
134
8.65
60
0.2318
0.0039
5.3914
153
8.23
70
0.2211
0.0032
4.7859
176
8.11
80
0.2359
0.0029
5.1063
196
7.9
90
0.3005
0.0033
8.6589
221
7.92
100
0.3548
0.0035
10.221
245
7.9
110
0.3294
0.003
9.4905
262
7.68
120
0.3172
0.0026
8.6479
283
7.61
150
0.2648
0.0018
4.6295
345
7.42
200
0.2194
0.0011
2.8244
482
7.77
250
0.2091
0.0008
2.2352
574
7.41
300
0.1684
0.0006
1.5345
720
7.74
350
0.1399
0.0004
1.0402
804
7.41
400
0.073
0.0002
0.5074
914
7.37Results for TewiMiD. Figures 6(a) and 6(b) show impact of the length of the test period on the profit curve. In case of TewiMiD strategy it is difficult to determine the optimal interval length of the testing period.Earnings accumulated over time, depending on the length of the test period for TewiMID.
(a)
Results in 3D
(b)
Final resultsIt is possible, however, due to graphs showing earnings per hour (candle) (Figures7(a) and 7(b)), depending on the length of the period and Table 2 listing the final results of the two studies. Similarly to the first strategy, length of this period is between 60 and 90 candles.Table 2
Final profits and Calmar ratio for the selected length of the test period for TewiMiD.
Size
Profit
Profit per candle
Calmar
Open positions
Percentage (%)
30
0.0249
0.0008
4.2953
47
5.05
40
0.0401
0.001
8.012
60
4.84
50
0.0443
0.0009
8.868
66
4.26
60
0.0636
0.0011
13.25
83
4.46
70
0.0771
0.0011
16.0687
95
4.38
80
0.0914
0.0011
19.0396
118
4.76
90
0.0899
0.001
10.5222
130
4.66
100
0.0935
0.0009
12.7934
141
4.55
110
0.0921
0.0008
12.6559
150
4.4
120
0.0949
0.0008
13.0337
159
4.27
130
0.0955
0.0007
13.1243
178
4.42
200
0.1011
0.0005
9.464
263
4.24
250
0.0965
0.0004
9.0392
328
4.23
300
0.1008
0.0003
9.3983
410
4.41
350
0.0924
0.0003
7.2935
467
4.3
400
0.1105
0.0003
8.1655
558
4.5Cumulative profit for one candle in time depending on the length of the testing period for TewiMiD.
(a)
Results in 3D
(b)
Final resultsOf course, the optimal convergence test window length, at least approximately, is a great convenience in design of automatic strategy for algotrading. It should be noted that the authors assume that it is possible to test each strategy separately and it is not required to synchronize.


## 4. Conclusion

Following a review of various lengths dependence validation periods shown in Figures4(a) and 4(b) were obtained. It is fairly obvious that a good fit of the parameters of the test period will continue for some time after the end of the learning. This is due to the assumption that there are trends in the market in different direction. The nature of trends is well explored during the learning process. The authors have found that the use of optimization methods derived from the area of artificial intelligence, including the PSO [20], given good and quickly reached the optimum values of the rules of the classifier, and good results in the initial stages of the test period. Also PSO method proves its effectiveness in similar optimization problems [22, 23]. For longer test periods, it can indeed get good results; however, the effectiveness of the strategy per hour decreases significantly. Obtained results allow concluding that the constant average length of the test window is more efficient and easier to manage than a strategy adaptively changing the length of the period. Strategies properties discovered during the learning period are effective for a short time—for test data period—good lengths for both strategies are about 50 to 120 hours at 1000 hours of learning time. In the real market it usually means from 2 to 5 days. It can be assumed that the re-learning of the parameters of the strategy should be carried out 1-2 times a week. This frequency is quite practical even for manual search of optimal parameters without fully automatic trading.Presented trading strategies (substrategy TewiMiC and TewiMiD) are complementary, since each variant can develop a set of different parameters. Separate sets of parameters are adapted better to the nature of the market during optimization. It allows, for example, trading long positions in the markets with more frequent upward trends. It should be noted that a further optimizations discovered trends that are short-term and during one cycle of validation several changes in these trends can occur. These changes could be of different lengths. Then there is the situation that one of the variants of the strategy takes into account the length of trends for deviating significantly from trends indicated by the second variant. The two strategy variants are part of an investment strategy that allows you to combine the four options of trading strategies. You can join the strategies presented with the strategies associated with the opening of long positions based on condition (order) Buy Stop and short positions in accordance with the model Sell Limit. It is possible to add to the current strategies additional sub strategies associated with opening long positions (based on condition for Buy Stop order) and short positions (in accordance with the Sell Limit model). Interesting, according to the authors, may also be improving the combined strategies through the synthesis of recommendations. An example of such improvement may be combination of four variants, some of which (e.g., 3) indicate the need for the purchase, and some (such as 1) the need to conclude the sale of stock—then the number of transactions that were made results from accumulating all of the variants (in presented case—2 purchases). This implies a lower cost (e.g., 2 times smaller). Transaction costs for certain decisions tests can be omitted, and this reduction significantly affects the efficiency improvement investment strategy. The studies take into account the transaction costs for the pessimistic (above average costs in popular brokers). In practical terms, the strategy has big potential. With traditional software, trading programs (such as Metatrader) do not have the possibility of converting simple strategy parameters during operation. This implies the need for a hybrid solution, consisting, for example, of interprocess communication between the trading software and program developed in universal high-level language (e.g., Matlab, C#). Algotarding future will very likely be increasingly active domain for experts in algorithmization and programming and less and less for economists and econometricians.Authors are aware of the fact that the parametric space is broad and choosing right ones is not a trivial task. It is not obvious that chosen and presented in this paper parameters are the best. There are no obvious sources that would suggest which parameters should be considered in investment strategies. To determine the parameters utilized in presented strategies an iterative computation has been used—after adding parameter the results were assessed and when they were acceptable the following parameter was added to the strategy. Even though selected parameters resulted in high efficiency, it does not mean that one should refrain from searching for better choice of parameters. Presented results can be considered as particularly good and are reproducible by scrupulous reader. Alternative strategies can be compared with presented ones using the same criteria (i.e., Calmar ratio). For many years the authors have been improving following strategy and its implementation in the real market. Current and future research aims to study the influence of the number of parameters—expanding or limiting the parameter space—and adding two additional substrategies based on the same band as aforementioned.



---

*Source: 451849-2014-02-03.xml*