Sei sulla pagina 1di 9

Mathematical and Computer Modelling 46 (2007) 189197 www.elsevier.

com/locate/mcm

Improving technical trading systems by using a new MATLAB-based genetic algorithm procedure
Stephanos Papadamou a, , George Stephanides b
a Department of Economics, University of Thessaly, Argonauton and Filelinon, Volos, Greece b Department of Applied Informatics, University of Macedonia Economic and Social Sciences, Egnatias 156, Thessaloniki 54006, Greece

Received 18 May 2006; accepted 15 December 2006

Abstract Recent studies in nancial markets suggest that technical analysis can be a very useful tool in predicting the trend. Trading systems are widely used for market assessment; however, parameter optimization of these systems has attracted little interest. In this paper, to explore the potential power of digital trading, we present a new MATLAB tool based on genetic algorithms; the tool specializes in parameter optimization of technical rules. It uses the power of genetic algorithms to generate fast and efcient solutions in real trading terms. Our tool was tested extensively on historical data of a UBS fund investing in emerging stock markets through our specic technical system. Results show that our proposed GATradeTool outperforms commonly used, non-adaptive, software tools with respect to the stability of return and time saving over the whole sample period. However, we provided evidence of a possible population size effect in quality of solutions. c 2007 Elsevier Ltd. All rights reserved.
Keywords: Financial markets; Prediction; Genetic algorithms; Investment; Technical rules

1. Introduction Todays traders and investment analysts require fast and efcient tools in a ruthless nancial market. Battles in trading are now mainly waged at computer speed. The development of new software technology and the appearance of new software environments (e.g. MATLAB) provide the basis for solving difcult nancial problems in real time. MATLABs vast built-in mathematical and nancial functionality, the fact that it is both an interpreted and compiled programming language and its platform independence make it well suited for nancial application development. Evidence on the returns earned by technical rules, including momentum strategies (e.g. [1416,16,25,20]), moving average rules and other trading systems [6,2,9,24] can support the importance of technical analysis. However, the majority of these studies have ignored the issue of parameter optimization, leaving them open to criticism of data snooping and the possibility of survivorship bias [7,17,8]. Traditionally researchers used ad hoc specication of trading rules. They use a default popular conguration or randomly try out a few different parameters and select the best with criteria based on return mainly.
Corresponding author.

E-mail addresses: stpapada@econ.uth.gr (S. Papadamou), steph@uom.gr (G. Stephanides). 0895-7177/$ - see front matter c 2007 Elsevier Ltd. All rights reserved. doi:10.1016/j.mcm.2006.12.033

190

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

Papadamou and Stephanides [23], implemented a new MATLAB-based toolbox for computer aided technical trading that has included a procedure for parameter optimization problems. However, the weak point of their optimization procedure is time: the objective function (e.g. prot) isnt a simple squared error function but a complicated one (each optimization iteration goes through the data, generates trading signals, calculates prots, etc.). When the data sets are large and you would like to reoptimize your system often and you need a solution as soon as possible, then trying out all possible solutions to get the best one would be a very tedious task. Genetic algorithms (GAs) are better suited since they perform random searches in a structured manner and converge very fast on populations of near optimal solutions. The GA will give you a set (population) of good solutions. Analysts are interested in getting a few good solutions as fast as possible rather than the globally best solution. The globally best solution does exist, but it is highly unlikely that it will continue to be the best one. The aim of this study is to show how genetic algorithms, a class of algorithms in evolutionary computation, can be employed to improve the performance and the efciency of computerized trading systems. It is not the purpose here to provide theoretical or empirical justication for the technical analysis. We demonstrate our approach in a particular forecasting task based on emerging stock markets. This paper is organized as follows. Previous work is presented in Section 2. The data set and our methodology are described in Section 3. The empirical results are discussed in Section 4. Conclusions follows Section 5. 2. Previous work There is a large body of GA work in the computer science and engineering elds but little work has been done concerning business related areas. Latterly, there has been a growing interest in GA use in nancial economics, but so far there has been little research concerning automated trading. To our knowledge the rst published paper linking genetic algorithms to investments was from Bauer and Liepins [4]. Bauer [5] in his book Genetic Algorithms and Investment strategies offered practical guidance concerning how GAs might be used to develop attractive trading strategies based on fundamental information. These techniques can be easily extended to include other types of information such as technical and macroeconomic data as well as past prices. According to Allen and Karjalainen [1], genetic algorithm is an appropriate method to discover technical trading rules. Fern andez-Rodr guez et al. [11] by adopting genetic algorithms optimization in a simple trading rule provide evidence for successful use of GAs from the Madrid Stock Exchange. Some other interested studies are those by Mahfoud and Mani [18] that presented a new genetic-algorithm-based system and applied it to the task of predicting the future performances of individual stocks; by Neely et al. [21] and by Oussaidene et al. [22] that applied genetic programming to foreign exchange forecasting and reported some success. One of the complications in GA optimization is that the user must dene a set of parameters such as the crossover rate, population size and mutation rate. According to De Jong [10] who studied genetic algorithms in function optimization good GA performance requires high crossover probability (inversely proportional to population size) and a moderate population size. Goldberg [12] and Markellos [19] suggest that a set of parameters that works well across many problems is a crossover parameter = 0.6, population size = 30 and mutation parameter = 0.0333. Bauer [4] performed a series of simulations on nancial optimization problems and conrmed the validity of Goldbergs suggestions. In the present study we will perform a limited simulation study by testing various parameter congurations for the chosen trading system. We will also provide evidence for the GA proposed by comparing our tool with other software tools. 3. Methodology Our methodology is conducted in several steps. First, we have to implement our trading system based on technical analysis. In developing a trading system, you need to determine when to enter and when to exit the market. If the trader is in the market the binary variable Ft is equal to one otherwise is zero. As position traders we base the majority of our entry and exit decisions on daily charts by constructing a trend following indicator (Dimbeta). This indicator calculates the deviation of current prices from its moving average of 1 length. The indicators used in our trading system can be formalized as below:

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

191

Dimbetat =

Closet MovAvt (Close, 1 ) MovAvt (Close, 1 )

(1)

where Closet is the closing price of the fund at time t and function MovAv calculates the simple moving average of the variable Close with time length 1 . MovAvt (Close, 1 ) = 1 1
1 1 i =0

Closet i ,

t = 1 , 1 + 1, . . . , N .

(2)

Our trading system consists of two indicators, the Dimbeta indicator and the Moving Average of Dimbeta given by the following equation: MovAvt (Dimbeta, 2 ) = 1 2
2 1 i =0

Dimbetat i ,

t = 2 , 2 + 1, . . . , N .

(3)

If MovAvt (Dimbeta, 2 ) cross upward the Dimbetat then enter long into the market (i.e. buy signal). If MovAvt (Dimbeta, 2 ) cross downward Dimbetat then close the long position in the market (i.e. sell signal). Second, we have to optimize our trading strategy. It is well known that maximizing objective functions such as prot or wealth can optimize trading systems. The most natural objective function for a risk-insensitive trader is prot. In our software tool we consider multiplicative prots. Multiplicative prots are appropriate when a xed fraction of accumulated wealth > 0 is invested in each long trade. In our software no short sales are allowed and the leverage factor is set xed at = 1, the wealth at time T is given by the following formula:
T

W( T ) = Wo
t =1

(1 + Ft 1 rt ) {1 | Ft Ft 1 |}

(4)

where rt = (Closet /Closet 1 ) 1 is the return realized for the period ending at time t , are the transaction costs and Ft is the binary dummy variable indicating a long position or not (i.e. 1 or 0). The prot is given by subtracting from the nal wealth the initial wealth, PT = W(T ) W0 . Optimizing a system involves performing multiple tests while varying one or more parameters (1 , 2 ) within the trading rules. The number of tests can quickly grow enormous (Metastock has a maximum of 32 000 tests). In the FinTradeTool [23], there is no limit, however, on the time processing depending on the computer system used. In this paper we investigate the possibility of solving the optimization problem by using genetic algorithms. Genetic algorithms (GAs) that were developed by Holland [13] constitute a class of search, adaptation and optimization techniques based on the principles of natural evolution. Genetic algorithms lend themselves well to optimization problems since they are known to exhibit robustness and can offer signicant advantages in solution methodology and optimization performance. GAs differ from other optimization and search procedures in some ways. First, they work with a coding of the parameter set, not the parameters themselves. Therefore GAs can easily handle the binary variables. Second, GAs search from a population of points, not a single point. Therefore GAs can provide a set of globally optimal solutions. Finally, GAs use only objective function information, not derivatives or other auxiliary knowledge. Therefore GAs can deal with the non-continuous and non-differentiable functions that are actually existed in a practical optimization problem. 4. Proposed GATradeTool In GATradeTool, a genetic algorithm operates on a population of candidate solutions encoded (1 , 2 ). Each decision variable in the parameter set is encoded as a binary string and all are concatenated to form a chromosome. Chromosome representation is a two-element vector containing 1 , 2 parameters in bunary genetic coding. The precision of binary representation is eight bits per parameter (i.e. [1 0 0 1 0 1 1 1 ; 1 0 0 1 0 1 1 1]). It begins with a randomly constructed population of initial guesses. These solution candidates are evaluated in terms of our

192 Table 1 Population size effect

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

5 Dimbeta/MADimbeta Completion time Max return Min return Avg return St. dev. of returns Max ret./St. dev 53/197 4.68 88.83% 40.00% 59.72% 29.08% 3.05

10 71/141 9.00 95.35% 0.34% 68.25% 33.03% 2.89

20 72/135 17.57 121.09% 53.00% 69.74% 36.97% 3.28

30 138/206 26.66 126.39% 87.52% 76.07% 42.33% 2.99

40 203/202 36.97 108.87% 15.26% 71.77% 39.09% 2.79

60 77/129 56.10 116.84% 30.68% 82.31% 35.78% 3.27

80 76/130 74.20 124.57% 52.13% 77.23% 37.64% 3.31

100 74/131 94.40 120.57% 96.00% 80.22% 42.71% 2.82

objective function (Eq. (4)). In order to obtain optimality each chromosome exchanges information by using operators (i.e. arithmetic crossover1 ) borrowed from natural genetics to produce a better solution. The objective function (Eq. (4)) is used to measure how individuals have performed in the problem domain. In our case, the most tted individuals will have the highest numerical value of the associated objective function. The tness function transforms the raw objective function values into non-negative gures of merit for each individual. The tool supports the offsetting and scaling method of Goldberg [12] and the linear-ranking algorithm of Baker [3]. Our selection technique employs a roulette wheel mechanism to probabilistically select individuals based on their performance. A real-valued interval Sum is determined as the sum of the row tness values over all the individuals in the current population. Individuals are then mapped one to one into contiguous intervals in the range [0, Sum]. The size of each individual interval corresponds to the tness value of the associated individual. To select an individual a random number is generated in the interval [0, Sum] and the individual whose segment spans the random number is selected. This process is repeated until the desired number of individuals has been selected [26]. These candidates were allowed to participate in an arithmetic crossover, the procedure that recombines promising candidates in order to create the next generation. These steps were repeated until a well-dened criterion is satised. Because the GA is a stochastic search method, it is difcult to formally specify convergence criteria. As the tness of population may remain static for a number of generations before a superior individual is found, the application of conventional termination criteria becomes problematic. As a result we proposed the achievement of a specic number of iterations as the termination criterion. Our genetic algorithm can be presented in the following frame: Frame 1 Steps In GA 1. Create randomly the initial population P (0); set i = 0 2. Repeat (a) Evaluate the tness of each individual in P (i ) using tness function (b) Select parents from P (i ) using roulette wheel selection mechanism (c) Generate new generation P (i + 1) using genetic operators 3. Until i < N ; where N is maximum generation set by users generating members of the next generation. General mechanisms (referred to as genetic operators, e.g. reproduction, crossover) are used to combine or change the selected candidate solutions to generate offspring, which will form the population in the next generation.

1 Arithmetic single-point crossover, involves randomly cutting two strings at the same randomly determined string position and then swapping the tail portions. Crossover extends the search for new solutions in far-reaching directions.

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

193

5. Empirical results In this section, we apply our methodology in a UBS mutual fund investing in emerging stock markets.2 The data analyzed consists of 2800 observations on daily closing prices of that fund for the period 1/5/9825/6/04. The optimization period is dened between 1/5/98 to 25/6/03. The optimized system was evaluated through the extended period 25/6/0325/6/04. The optimization problem is set as to determine the optimal lengths of Dimbeta indicator and its moving average for the simple Dimbeta model that will maximize prots. Firstly, the effect of different GA parameter congurations will be studied. More specically we are interested to measure the effect of the population size and the crossover parameter in the performance of the genetic algorithm based optimization procedure. Based on Goldbergs [12] and Bauers [4] recommendations, the population size should be equal to 30 and the crossover rate should be 0.6 (default values). The number of iterations was set to 300 for all simulations. Second, we compared the solutions of optimization problem conducted by different software tools in order to measure the validity of the GATradeTool proposed. Table 1 provides the GA optimization results for different sizes of populations. The rst row of the table shows the best parameters for the Dimbeta indicator and the moving average of Dimbeta. In order to measure the effect of population size in the best solution we examine a series of different statistics. The solution with the maximum and minimum return, the average return, the standard deviation of these solutions, the time needed for convergence of the algorithm, and an efciency index calculated by dividing max return solution by the standard deviation of solutions. By looking in Table 1 we can say that as long as you increase the population size the best and the average solutions are higher. However, after a population size of 30 the performance decreased. In order to take into consideration the computational costs involved since increase in population size, we calculate the time needed for solving the problem. Low population size leads to low performance and low completion time. According to the efciency index the best solution is that given by the population size 20. In order to establish a base performance of the algorithm, 30 trials of the GA were performed, with a different random starting population for each trial. Fig. 1a, shows how performance improved over time by plotting average maximum tness as percentage of the optimal value versus the generation number. We rst captured the maximum tness value for each of the 30 trials; this is done for every generation and every trial. We then averaged the maximum tness values and divided that number by the optimal tness value, which was obtained by enumerative search (FinTrade tool, [23]); this gave us the average maximum tness as a percentage of the optimum value per generation. As can be seen in Fig. 1a, the average maximum tness of the rst generation is about 74% of the optimal value. However, by the ftieth generation, the algorithm has usually found at least one solution that was within 90% of the optimal value. After the ftieth generation, the solution could reach 98% of the optimal value. With performance measures from our base settings as a reference point, we examined the possible variations in the basic procedure. We studied the effect of changes in population size and crossover rate. For each different parameter
2 The structure of this fund and its major position at 25/6/2004 are depicted in the following gure.

194

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

Fig. 1a. Base parameter settings: percentage of optimal.

Fig. 1b. Crossover 0.40: percent of optimal.

Fig. 1c. Crossover 0.80: percent of optimal.

setting, we performed 30 trials of the algorithm and then compared the graphs of average maximum tness with those obtained for the base setting. First, we tried crossover rates 0.4 and 0.8. The results are shown in Figs. 1b and 1c, which are similar to Fig. 1a. As a result crossover parameters do not affect the optimal solution to a critical degree. However, the results are different when we alter the population size. According to Figs. 1d and 1e, with a small population size we had poorer results than with a large population. When we selected 80 as population size we achieved high returns in early generations. By looking at Table 2 you can compare the results of optimization of our trading system by using three different software tools. The rst row gives the result for the GATradeTool against the Metastock and the FinTradeTool [23]. Our proposed software tool (GATradeTool) can solve the optimization problem very fast without any specic restrictions about the number of total tests. The maximum number of tests that can be performed in Metastock software is 32 000. The FinTradeTool needs much more time in order to nd the optimal solution. The solution provided by the GATradeTool, is close to the optimal solution of the FinTradeTool. The trading systems with the optimum parameters that have been found in period 1/5/9825/6/03 were tested in the evaluation period 25/6/0325/6/04. The performance of our trading system has been increased in all software tools. However, the cost of time has to be considered very seriously (column 4).

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

195

Fig. 1d. Population 80: percent of optimal.

Fig. 1e. Population 20: percent of optimal. Table 2 Comparison of three different software tools Software tool Optimized parameters (Dimbeta. MovAv (DimBeta)) (72.135) (75.129) (60.111) Total tests Completion time (min) Optimization period return (1/5/9825/6/03) (%) 121.1 126.4 116.9 Evaluation period return (25/6/0325/6/04) (%)

GATradeTool FinTradeTool Metastock

39 601 32 000

17.57 67.15 30.3

6.5 11.7 4.5

Fig. 2 depicts the evolution of the maximum, minimum and average return across the 300 generations for the Dimbeta trading system (population size 80, crossover rate 0.6). It can be observed that the maximum return has a positive trend. It appears to be relatively stable after 150 generations and moves in the range between 1.2 and 1 (i.e. 120%100% return). For the minimum tness no pattern seems to exist. For the average population return a clear upward trend can be found in the rst 180 generations, this is an indication that the overall tness of the population improves over time. Concerning the volatility of the solutions, standard deviation of solutions after an increase in the rst generations stabilizes in a range between 0.3 and 0.6 providing evidence of a stable and efcient set of solutions. Fig. 3 provides a three dimensional plot of the optimum solutions given by the GATradeTool. In axes x and y we have the parameters 1 , 2 for the dimbeta indicator and its moving average. Axis 2 shows the return of the Dimbeta trading system for the selected optimum parameters. As can be easily understood our tool provides an area of optimum solutions in contrast with the FinTradeTool that provides only the best solution. 6. Conclusions While technical analysis is widely used as an investment approach among practitioners or academics, they are rarely focused on the issue of parameter optimization. It is not our role to defend technical analysis here, although our results show that there is some predictability in the UBS mutual fund investing in emerging stock markets based on historical data alone. Our main objective in this paper is to illustrate that the new technology of MATLAB can be used in order to implement a genetic algorithm tool that can improve optimization of technical trading systems.

196

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

Fig. 2. Evolution of several statistics over 300 generations.

Fig. 3. A 3-D plot of the optimum area.

Our experimental results show that GATradeTool can improve digital trading by providing quickly a set of near optimum solutions. Concerning the effect of different GA parameter congurations, we found that an increase in population size can improve performance of the system. The parameter of crossover rate does not affect seriously the quality of the solution. By comparing the solutions of the optimization problem conducted by different software tools, we found that the GATradeTool can perform better, by providing very fast a set of optimum solutions that present a consistency throughout the evaluation period. Finally, it would be interesting for further research to test a series of different systems in order to see the correlation between a genetic algorithm and system performances. At a time of frequent changes in nancial markets, researchers and traders can easily test their specic systems in GATradeTool by changing only the function that produces the trading signals. Acknowledgements This research paper was part of the postdoctoral research of Dr S. Papadamou that has been funded by IKY Greek State Scholarships Foundation. References
[1] F. Allen, R. Karjalainen, Using genetic algorithms to nd technical trading rules, Journal of Financial Economic 51 (1999) 245271.

S. Papadamou, G. Stephanides / Mathematical and Computer Modelling 46 (2007) 189197

197

[2] H.L. Allen, M.P. Taylor, The use of technical analysis in the foreign exchange market, Journal of International Money and Finance 11 (1992) 303314. [3] J.E. Baker, Adaptive selection methods for genetic algorithms, in: Proceedings of the rst International Conference on Genetic Algorithms, 1985, pp. 101111. [4] R.J. Bauer, G.E. Liepins, Genetic algorithms and computerized trading strategies, in: D.E. OLeary, P.R. Watkins (Eds.), Expert Systems in Finance, Elsevier Science Publishers, Amsterdam, The Netherlands, 1992. [5] R.J. Bauer Jr., Genetic Algorithms and Investment Strategies, John Wiley & Sons, Inc, New York, 1994. [6] W. Brock, J. Lakonishok, B. LeBaron, Simple technical trading rules and the stochastic properties of stock returns, Journal of Finance 47 (1992) 17311764. [7] S. Brown, W. Goetzmann, R. Ibbotson, S. Ross, Survivorship bias in performance studies, Review of Financial Studies 5 (1992) 553580. [8] S. Brown, W. Goetzmann, S. Ross, Survival, Journal of Finance 50 (1995) 853873. [9] Y.W. Cheung, C.Y.P. Wong, The performance of trading rules on four asian currency exchange rates, Multinational Finance Journal 1 (1997) 122. [10] K. De Jong, An analysis of the behavior of a class of genetic adaptive systems, Ph.D. Diss., University of Michigan, University Microlms No. 76-9381, 1975. [11] F. Fern andez-Rodr guez, C. Gonz alez-Martel, S. Sosvilla-Rivero, Optimisation of Technical Rules by Genetic Algorithms: Evidence from the Madrid Stock Market, Working Papers 2001-14, FEDEA, 2001. ftp://ftp.fedea.es/pub/Papers/2001/dt2001-14.pdf. [12] D.E. Goldberg, Genetic Algorithms in Search, Optimization and Machine Learning, Addison-Wesley, 1989. [13] J.H. Holland, Adaptation in Natural and Articial System, University of Michigan Press, 1975. [14] N. Jegadeesh, S. Titman, Returns to buying winners and selling losers: Implications for stock market efciency, Journal of Finance 48 (1) (1993) 6591. [15] P.J. Kaufman, The New Commodity Trading Systems and Methods, John Wiley & Sons, 1987. [16] B.N. Lehmann, Fad, martingales, and market efciency, Quarterly Journal of Economics 105 (1990) 128. [17] A.W. Lo, A.C. MacKinlay, When are contrarian prots due to stock market overreaction? Review of Financial Studies 3 (1990) 175206. [18] S. Mahfoud, G. Mani, Financial forecasting using genetic algorithms, Journal of Applied Articial Intelligence 10 (6) (1996) 543565. [19] R.N. Markellos, Backtesting trading systems, Journal of Computational Intelligence in Finance 5 (6) (1997) 510. [20] L. Menkhoff, M. Schlumberger, Persistent protability of technical analysis on foreign exchange markets? BNL Quarterly Review 193 (1995) 189216. [21] C. Neely, P. Weller, R. Ditmar, Is technical analysis in the foreign exchange market protable? A genetic programming approach, in: C. Dunis, B. Rustem, (Eds.), Proceedings, Forecasting Financial Markets: Advances for Exchange Rates, Interest Rates and Asset Management, London, 1997. [22] M. Oussaidene, B. Chopard, O. Pictet, M. Tomassini, Practical aspects and experiences Parallel genetic programming and its application to trading model induction, Journal of Parallel Computing 23 (8) (1997) 11831198. [23] S. Papadamou, G. Stephanides, A new matlab-based toolbox for computer aided dynamic technical trading, Financial Engineering News (31) (2003). [24] S. Papadamou, S. Tsopoglou, Investigating the protability of technical analysis systems on foreign exchange markets, Managerial Finance 27 (8) (2001) 6378. [25] F.M. Werner, D. Bondt, R. Thaler, Further evidence on investor overreaction and stock market seasonality, Journal of Finance 42 (3) (1987) 557581. [26] D. Whitley, The Genitor algorithm and selection pressure: Why rank-based allocations of reproductive trials are best, in: Proceedings of the Third International Conference on Genetic Algorithms, 1989, pp. 116121.

Potrebbero piacerti anche