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.

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 [

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. [

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 [

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 [

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 [

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 (Figure

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.

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.

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 the

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.

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.

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 of

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;

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 Figure

is TakeProfit condition, generally ranged from 0.0015 to 0.009;

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;

is maximum number of open positions at the same time, ranged from 3 to 20;

is the number of candles that determines average volume value; generally ranged from 2 to 10;

is maximum value of the difference between the current value of the volume and the average value calculated on the basis of

is the number of candles on the cumulative profit curve, based on which current drawdown is calculated, ranged from 5 to 25;

is the highest acceptable drawdown on the cumulative yield curve; generally ranged from 0.0021 to 0.008;

is acceptable amount of the cumulative loss for all currently open positions, ranged from 0.0005 to 0.003.

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 (

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 parameter

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 parameter

The result of that is that we have two distinctly different opening conditions.

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.

Opened long position will be closed, if at the close of the candle (

Position will be closed if at the opening of the next (

where

Then the profit (in this case loss) will be calculated as

Position will be closed if inside the next (

Then the profit (in this case loss) will be calculated as

where LowPrice(

Position will be closed if at the opening of the next (

where

Then the profit will be calculated as

Position will be closed if inside the next (

Then the profit will be calculated as

where

Position will be closed if at the opening of the next (

Then the profit will be calculated as

Position will be closed if inside the next (

Then the profit will be calculated as

Opened short position will be closed if at the close of the candle (

Position will be closed if at the opening of the next (

Then the profit (in this case loss) will be calculated as

Position will be closed if inside the next (

Then the profit (in this case loss) will be calculated as

Position will be closed if at the opening of the next (

Then the profit will be calculated as

Position will be closed if inside the next (

Then the profit will be calculated as

Position will be closed if at the opening of the next (

Then the profit will be calculated as

Position will be closed when inside the opening of the next (

Then the profit (in this case loss) will be calculated as

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) [

Methods of testing carried out to test the variable size window.

Figures

Charts of the profit for both strategies with fixed test period size—100 candles.

Substrategy TewiMiC

Substrategy TewiMiD

It 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.

Earnings accumulated over time, depending on the length of the test period for TewiMIC.

Results in 3D

Final results

Cumulative profit for one candle in time depending on the length of the testing period for TewiMiC.

Results in 3D

Final results

Due 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 Figures

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.37 |

Earnings accumulated over time, depending on the length of the test period for TewiMID.

Results in 3D

Final results

It is possible, however, due to graphs showing earnings per hour (candle) (Figures

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.5 |

Cumulative profit for one candle in time depending on the length of the testing period for TewiMiD.

Results in 3D

Final results

Of 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.

Following a review of various lengths dependence validation periods shown in Figures

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.

The authors declare that there is no conflict of interests regarding the publication of this paper.

This work is done within the Project TEWI financed from the Innovative Economy Programme in years 2012 and 2013.