‹ Volver a la ficha Doc. dt-2001-14

Optimisation of technical rules by genetic algorithms: Evidence from the Madrid stock market* by Fernando Fernández-Rodríguez** Christian González-Martel** Simón Sosvilla-Rivero*** DOCUMENTO DE TRABAJO 2001-14

August 2001

* We are very grateful to Mayte Ledo (BBVA) for kindly providing us with the data set used in this paper. Simón Sosvilla-Rivero also acknowledges partial financial support by the Spanish Ministry of Education, through DGICYT Project PB98-0546-C02-02.

** Universidad de Las Palmas de Gran Canaria.

*** FEDEA and Universidad Complutense de Madrid. Corresponding author: Address: FEDEA, Jorge Juan 46, 28001 Madrid, Spain. Tel: +34-914 350 401, Fax: +34-915 779 575.

ABSTRACT

This paper investigates the profitability of a simple and very common technical trading rule applied to the General Index of the Madrid Stock Market. The optimal trading rule parameter values are found using a genetic algorithm. The results suggest that, for reasonable trading costs, the technical trading rule is always superior to a risk-adjusted buy-and-hold strategy.

JEL classification numbers: G10, G14, C53

KEY WORDS: Technical trading rules, Genetic algorithms, Security markets

1. Introduction

A considerable amount of work has provided support for the view that simple technical trading rules (TTRs) are capable of producing valuable economic signals [see, Brock et al. (1992), Bessembinder and Chan (1995), Mills (1997) and Fernández Rodríguez et al. (1999), among others]. However, the majority of these studies have ignored the issue of parameter optimisation, leaving them open to the criticism of datasnooping and the possibility of a survivorship bias [see Lo and MacKinley (1990) and Brown et al. (1995), respectively]. To avoid this criticism, a more objective and valid approach consists in choosing TTRs based on an optimisation procedure utilising in-sample data and testing the performance of these rules out-of-sample. In this sense, a genetic algorithm is appropriate method to discover TTRs, as shown in Allen and Karjalain (1999).

The aim of this paper is to investigate the profitability of some popular TTRs using genetic algorithm optimisation procedures. Section 2 describes the TTRs examined in this paper, while Section 3 presents the genetic algorithms and. The empirical results are shown in Section 4.

2. Technical trading rules

The simplest and most common trading rules are moving averages (MA). In particular, we consider a generalised MA (GMA) rule that can be represented by the following binary indicator function:

\[S (\Theta) _ {t} = M A \left(\theta_ {1}\right) _ {t} - \left(1 + \left(1 - 2 S _ {t - 1}\right) \theta_ {3}\right) M A \left(\theta_ {2}\right) _ {t}\tag{1}\]

where denotes the parameters associated to the GMA rule, and MA(θ ) is a MA indicator defined as follows:

\[M A _ {t} (\theta) = \frac {1}{\theta} \sum_ {i = 0} ^ {\theta - 1} P _ {t - i}, \quad t = \theta , \theta + 1, \dots , N\]

The lengths of the short and long MA are given by and , while represents a filter parameter included to reduce the number of false buy and sell signals generated by a MA rule when price movement is nondirectional.

The GMA rule is used to indicate the trading position that should be taken at time t. In particular, equation (1) returns either a one o zero, corresponding to a buy or sell signal, respectively1.

3. Genetic algorithms

Genetic algorithms (GA), developed by Holland (1975), are a class of adaptive search and optimisation technique. A GA starts with a population of randomly generated solution candidates, which are evaluated in terms of an objective function. This candidates are usually represented by vectors consisting in binary digits. Promising candidates, as represented by relatively better performing solutions, are then combined through a process of binary recombination referred to as crossover. Finally, random mutations are introduced to safeguard against the loss of genetic diversity, avoiding local optima. Successive generations are created in the same manner and evaluated using the objective function until a well-defined criterion is satisfied.

1 Three different MA rules are nested within the GMA rule and can be derived individually by imposing certain restrictions on equation (1):
1) Simple MA: 0 1, 1, θ1 = θ2 > θ3 =
2) Filtered MA: 0 1, 1, θ1 = θ 2 > θ3 >
( ) ( ) t tt 2 S P MA Θ = − θ
3) Double MA: 0 1, , θ1 > θ2 > θ1 θ3 = θ1 > 1,θ2 > θ1,θ3 = 0
( ) ( ) t t( ) 1 1 2 1 3 2( ) S P S MA Θ = − + − θ θ
( ) ( ) ( ) t t t1 2S MA MA Θ = − θ θ

In order to determine which solution candidates are allowed to participate in the crossover and undergo possible mutation, we apply the genitor selection method proposed by Whitley (1989). This approach involves ranking all individuals according to performance and then replacing the poorly performing individuals by copies of better performing ones. In addition, we apply the commonly used single point crossover, consisting in randomly pairing candidates surviving the selection process and randomly selecting a break point at a particular position in the binary representation of each candidate. This break point is used to separate each vector into two subvectors. The two subvectors to the right of the break point are exchanged between the two vectors, yielding two new candidates. Finally, mutation occurs by randomly selecting a particular element in a particular vector. If the element is a one it is mutated to zero, and viceversa. This occurs with a very low probability in order not to destroy promising areas of search space.

4. Empirical results

The data consists of daily closing prices of the General Index of the Madrid Stock Exchange (IGBM) and the daily 3-month rate in the interbank deposits markets, covering the 2 January 1972-15 November 1997 period (4376 observations). The total period is split into an in-sample optimisation period from 2 January 1972 to 16 December 1988 and an outof-sample test period from to 16 December 1988 to 15 November 1997 (2188 observations in each subperiod).

The initial population was set at 150 candidates, while the maximum number of both generation allowed and iterations without improvement was fixed at 300. The maximum the probabilities associated with the occurrence of crossover and mutation were set at 6% and 0.5%, respectively. These choices were guided by previous studies (see, Bauer, 1994) and experimentation with different values.

The signals from the trading rules are used to divide the total number of trading days ( N ) into either “in” the market (earning the market return or “out” of the market (earning the risk-free rate of return . Therefore, the objective function used to evaluate the trading rules is given by the following expression:

\[r _ {t r} = \sum_ {t = 1} ^ {N} S _ {t - 1} r m _ {t} + \sum_ {t = 1} ^ {N} (1 - S _ {t - 1}) r f _ {t} - T ^ {*} c\tag{2}\]

whereT is the number of transactions and c is the cost per transaction.

As an appropriate benchmark, we consider the return from a riskadjusted buy and hold strategy defined as

\[r _ {b h} = \alpha \sum_ {t = 1} ^ {N} r f _ {t} + (1 - \alpha) \sum_ {t = 1} ^ {N} r m _ {t} - 2 c\tag{3}\]

where α is the proportion of trading days that the rule is out of the market.

Table 1 summarises the results. As can be seen, the best GMA rules are double MA rules, without a filter parameter (except for the case of 0 transaction costs). The Sharpe ratio and the annualised returns corresponding to the best GMA rule are higher than those from the riskadjusted buy and hold strategy, both for the in-sample and out-of-sample periods2. It is interesting to note that this results holds for all transaction costs examined.

Table 1: Performance statistics

GMA trading ruleRisk-adjusted buy and hold strategy
Transaction CostsParameter ValuesIn-sampleOut-of-sampleIn-sampleOut-of-sample
$\bar{r}$ SR $\bar{r}$ SR $\bar{r}$ SR $\bar{r}$ SR
0.25%(207,242,0)33.300.007214.630.006825.360.006810.860.0044
0.10%(1,20,0)38.580.010516.890.007222.920.00729.950.0041
0(1,2,3)43.210.012213.360.007818.540.007810.180.0046

Notes: GMA trading rules are identified as , where s and l are the length of the short and long period (in days) and b is the filter parameter. r is the average annualised return of the trading strategy and SR is the Sharpe ratio .

2 The Sharpe ratio is a measure of risk-adjusted returns: , where r is the average annualised return of the trading strategy, σ is the standard deviation of daily trading rule returns, and Y is equal to the number of trading days per year.

References

  1. Allen, F. and R. Karjalain, 1999, Using genetic algorithms to find technical trading rules, Journal of Financial Economics 51, 245-271.
  2. Bauer, R. J., 1994, Genetic algorithms and investment strategies (John Wiley and Sons, New York).
  3. Bessembinder, H. and K. Chan, 1995, The profitability of technical trading rules in Asian stock markets, Pacific Basin Finance Journal 3, 257- 284.
  4. Brock, W., Lakonishhock, J., and B. LeBaron, 1992, Simple technical trading rules and the stochastic properties of stock returns, Journal of Finance 47, 1731-1764.
  5. Brown, S., Goetzmann, W. and S. Ross, 1995, Survival, Journal of Finance 50, 853-873.
  6. Fernández Rodríguez, F.. Sosvilla-Rivero, S. and J. Andrada-Felix, 1999, Technical analysis in the Madrid stock exchange, Working Paper 99- 05, FEDEA (available at ftp://ftp.fedea.es/pub/Papers/1999/DT99- 05.pdf).
  7. Holland, J., 1975, Adaptation in natural and artificial systems (University of Michigan Press, Michigan).
  8. Lo, A. and A. MacKinley, 1990), Data snooping biases in tests of financial assets pricing models, Journal of International Money and Finance 12, 451-474.
  9. Mills, T., 1997, Technical analysis and the London Stock Exchange: Testing trading rules using the FT30. International Journal of Finance and Economics, 2, 319-331.
  10. Whitley, D., 1989, The GENITOR algorithm and selection pressure: Why rank-based allocation of reproductive trials is best, in: D. Schaffer, ed., Proceedings of the third international conference on genetic algorithms (Morgan Kaufmann, San Mateo, California) 116-121.

RELACION DE DOCUMENTOS DE FEDEA

TEXTOS EXPRESS

2001-01: “La reforma de las pensiones en el contexto internacional”, José A. Herce y Juan F. Jimeno.

2000-03: “Efectos sobre la inflación del redondeo en el paso a euros”, Mario Izquierdo y Simón Sosvilla-Rivero.

2000-02: “El tipo de cambio Euro/Dolar. Encuesta de FEDEA sobre la evolución del Euro”, Simón Sosvilla-Rivero y José A. Herce.

DOCUMENTOS DE TRABAJO

2001-14: “Optimisation of Technical Rules by Genetic Algorithms: Evidence from the Madrid Stock Market”, Fernando Fernádez-Rodríguez, Christian González-Martel y Simón Sosvilla-Rivero.

2001-13: “The Reduction of Dimension in the Study of Economic Growth Models”, J. R. Ruiz-Tamarit y M. Ventura-Marco.

2001-12: “Explaining Firms’ Export Behaviour:The Role of R&D and Spillovers”, Salvador Barrios, Holger Görg y Eric Strobl.

2001-11: “Drawing Lessons from the Boom of Temporary jobs in Spain”, Juan J. Dolado, Carlos García-Serrano y Juan F. Jimeno.

2001-10: “Ranking de Investigación en Economía en España: Instituciones y Autores (1990-1999)”, Juan José Dolado, Antonio García-Romero y Gema Zamarro.

2001-09: “The Measurement of Growth under Embodied Technical Change”, Omar Licandro, Jorge Durán y Javier Ruiz-Castillo.

2001-08: “Análisis económico de los comportamientos adictivos no saludables: Principales propuestas teóricas”, Fabiola Portillo y Fernando Antoñanzas.

2001-07: “Las migraciones interiores en España”, Samuel Bentolila.

2001-06: “Is the Deficit under Control?. A generational Accounting Perspective on Fiscal Policy and Labour Market Trends in Spain”, Gemma Abío, Eduard Bernguer, Holger Bonin, Joan Gil y Concepció Patxot.

2001-05: “Duración de los regímenes del SME”, Simón Sosvilla-Rivero y Reyes Maroto.

2001-04: “Assessing the Credibility of a Target Zone: Evidence from the EMS”, Francisco Ledesma-Rodríguez, Manuel Navarro-Ibáñez, Jorge Pérez-Rodríguez y Simón Sosvilla-Rivero.

2001-03: “La política macroeconómica en economías interdependientes”, Simón Sosvilla-Rivero.

2001-02: “Smoking in Spain: Analysis of Initiation and Cessation”, Namkee Ahn y José Alberto Molina.

2001-01: “La privatización de las pensiones en España”, José A. Herce.

2000-28: “Multinational Enterprises and New Trade Theory: Evidence for the Convergence Hypothesis”, Salvador Barrios, Holger Görg y Eric Strobl.

2000-27: “Obsolescence Vs modernization in a Schumpeterian vintage capital model”, Raouf Boucekkine, Fernando del Río y Omar Licandro.

2000-26: “Provisión de servicios públicos y localización industrial”, Luis Lanaspa, Fernando Pueyo y Fernando Sanz.

2000-25: “Labor Force Participation and Retirement of Spanish Older Men: Trends and Prospects”, Namkee Ahn y Pedro Mira.

Este Documento solamente está accesible en pdf en nuestra página web: http://fedea.es/hojas/publicaciones.htm