An Algorithm for Testing the Efficient Market Hypothesis
Post on: 16 Март, 2015 No Comment

Abstract
The objective of this research is to examine the efficiency of EUR/USD market through the application of a trading system. The system uses a genetic algorithm based on technical analysis indicators such as Exponential Moving Average (EMA), Moving Average Convergence Divergence (MACD), Relative Strength Index (RSI) and Filter that gives buying and selling recommendations to investors. The algorithm optimizes the strategies by dynamically searching for parameters that improve profitability in the training period. The best sets of rules are then applied on the testing period. The results show inconsistency in finding a set of trading rules that performs well in both periods. Strategies that achieve very good returns in the training period show difficulty in returning positive results in the testing period, this being consistent with the efficient market hypothesis (EMH).
Introduction
This paper describes a genetic algorithm used to create a trading system, consisting of several rules for opening and closing trading positions in the FX market. The aim of this study is to assess the weak form efficiency of the EUR/USD market. Our paper shows that the distribution of the outcome in the out-of-sample period is uniformly distributed around an average close to 0. This provides evidence that all the information available in the EUR/USD market is reflected in the price and no arbitrage can be made by trading this currency pair based on historical information.
Our findings should capture the attention of investors in the FX market that base their decisions on technical analysis signals. The results are in the support of previous academic literature that in general provides evidence for the impossibility of forecasting financial market movements by only analyzing historical prices.
Algorithmic trading has evolved exponentially in recent years because of more rapid reactions to temporary mispricing and easier price management from several markets [1]. As compared to human dealers, computers can learn from thousands of sources of information simultaneously and avoid emotional influence.
Technical analysis is a methodology of forecasting price movements by analyzing past market data [2]. The efficient market hypothesis (EMH) [3] contradicts this approach by stating that all public information in the market is immediately reflected in prices; therefore, no arbitrage can be made based on historical data. Time series is split in two parts. The trading system with several parameters is applied in-sample over the training period and strategies that generate the highest returns are selected and tested over the following period (out-of-sample). The objective of the system is to achieve high returns over the testing period. The impossibility of finding a good performing strategy over both training and testing period would support the EMH.
The research proceeds as follows. This section offers a review of the existing literature regarding the tests on the efficient market hypothesis, studies on the performance of technical analysis based on several indicators as well as the improvement of trading strategies using genetic algorithms. Section 2 presents the database used for testing the efficiency of the system and the methodology involved. Section 3 discusses empirical findings of our analysis and concludes. One currency pair has been used, EUR/USD.
Efficient Market Hypothesis
EMH, developed by Eugene Fama [3]. assumes that all the information in the market at a specific moment is reflected in the prices and therefore market participants cannot consistently perform better than the average market returns on a risk-adjusted basis. However, empirical findings have shown that the EMH may be questionable. Hasan et al. [4] find inefficiencies in the Dhaka stock market. They notice that factors like return, market capitalization, book-to-market ratio and market value influence the share returns. Moreover, similar features such as thin trading, volatility, small number of securities listed and investors’ attitude towards investment strategy characterize DSE, as well as other emerging markets.
Several studies find volatility in the level of efficiency over time and among different markets. Alvarez-Ramirez et al. [5] observe that the efficiency degree of financial markets changes over time. The relative efficiency of the US stock market varied over 1929–2012, with a decline in the late 2000s induced by the economic recession. The most efficient period was 1973–2003. Another study showing that the degree of inefficiency is not constant over time is made in [6]. IRR/USD market was inefficient over 2005–2010 and this may be caused by the negative long-range dependence, meaning that if the exchange rate is up it is likely to go down in the close future. A similar result is revealed by Kim et al. [7]. They provide evidence that supports time-varying return predictability of the Dow Jones Industrial Average index over the period 1900–2009. While the market seems efficient during market crashes, economic and political crises induce predictability in returns. The efficiency of the Asian stock markets varies with the level of equity market development [8]. The developed emerging markets are found to be weak-form efficient, while the secondary emerging markets are characterized by inefficiencies.
Dragota et al. [9] could not reject the weak-form EMH for the Bucharest Stock Exchange by applying Multiple Variance Ratio test to random walk hypothesis. For the same market, Armeanu and Balu [10] tested the efficiency of the Markowitz model, emphasizing the benefits of portfolio diversification. Charles et al. [11] evaluated the predictability of exchange rate returns and found that while they are unpredictable most of the times, return predictability may appear with coordinated central bank interventions and financial crises. The Chinese stock markets efficiency is investigated in [12]. The results show that Class A shares, which are generally available for domestic investors, seem efficient, while Class B shares, eligible for foreigners, are significantly inefficient. Trolle and Schwartz [13]. using a database of 11 years of data for crude oil and natural gas futures and options traded on NYMEX, found that it is difficult to explain the variation and the level in energy variance risk premia using systematic factors such as the returns on commodities or equity market portfolios or specific factors such as inventories.
Technical Analysis
Most automated trading systems use several indicators in order to generate purchase and sale recommendations [14]. One found that the best indicator for companies with high capitalization is RSI and the best for small capitalization companies is Momentum. Moreover, indicators that do not give many trade signals, such as Momentum, are more suitable when the transaction costs are high. One research assessed the performance of technical analysis in the US equity market for some technical industry sectors and small caps, over the period 1995–2010 [15]. Results show that the strategies are capable of outperforming the buy-and-hold strategy after adjusting for data-snooping bias and without transaction costs in the first half of the sample period. However, the same strategies are not able to produce superior performance over the second half. Success in the period 1995–2002 is tempered when introducing transaction costs. Moreover, the forecast of short-term return became weaker in the recent years, this being consistent with the EMH in the equity market. A positive performance of technical analysis is generated by applying moving average trading rules on 16 European stock markets over the period 1990–2006 [16]. A moving average trading rule combined with a strategy that at buy signals recommends investing in the stock market, while at sell signals recommends investing in the money market outperforms the buy-and-hold strategy over the sample period.
In [17] is found that one can achieve performing returns using trading strategies only if he has full information of the stock price change for the future. However, if the future information is not accurate, it can be useless in increasing profits. Moreover, a search in a strategy space to get high profit is impossible and this is based on lack of future information of a company.
Trading strategies have been mainly based on technical analysis in the commodity futures market [18]. [19]. [20] and foreign exchange market [21]. [22]. [23]. [24]. Evaluation of the technical analysis’ performance in the equity markets has generally been done using market indices such as Dow Jones Industrial Average [25]. [26]. S&P 500 [26]. [27]. NYSE and NASDAQ [26]. [28]. [29] or Russell 2000 [26]. [27]. [29]. Technical analysis has evolved beyond filter and moving averages rules, now including psychological barriers such us resistance and support levels [30] ; [31] .
Genetic Algorithms
In recent years, individuals and companies have developed algorithms that try to improve profitability of trading rules. Genetic algorithms (GA) represent a class of optimization techniques that generate solutions to search problems and quickly adapt to changing environments. GA were developed by Holland [32] and they simulate the process of natural evolution. As the species evolve through genetic processes such as selection, crossover and mutation, GA create classes of solutions that evolve over some generations through analogous processes in order to generate one solution with the best fit to the specific problem [33]. Algorithms start by creating some strategies with specific parameters. In the following steps, they dynamically change their parameters in order to achieve higher profits.
In a natural evolution process, species change over time. New organisms are born by recombination between members. They inherit parents’ traits and are also influenced by environment conditions. The natural selection process comes from the fact that while the population grows, the organism need to struggle for resources. Therefore, only the organisms that possess well-suited characteristics for this struggle will bring more offspring to the new generation.
Holland [32] developed a way in which the natural evolution process might be imported into algorithms that offer solutions to search problems. GA are very suitable for managing financial markets because these represent a continuous changing environment and trading strategies need to adapt to the new conditions. The search problem is represented by finding a strategy that achieves positive excess returns when applied to a specific sample. GA generate many strategies and those well fitted (according to a specific function that can be mean return, Sharpe ratio or one that takes into account also environment conditions) are selected for passing in the new generation and for recombining to generate new strategies.

Mendes et al. [34] developed a system based on a genetic algorithm that optimizes a set of rules to obtain a profitable strategy to trade EUR/USD and GBP/USD. The system generates individuals defined by ten mandatory and optional rules, from which five of them decide whether opening a long/short position or not at current price in the market and the other five decide when to close an opened position. The rules contain 31 parameters that evolve in many generations through selection, crossover and mutation and, based on return and risk, the individual that had the highest performance is selected and tested in the next period. Results have shown that, considering transaction costs, the best individuals in the training series were often not able to achieve positive results in the out-of-sample test series. Dempster and Jones [2] created an adaptive trading system that uses genetic programming. They used USD/GBP spot foreign exchange tick data from 1994 to 1997. The algorithm is applied on out-of-sample data to provide new rules and a feedback system helps rebalancing the rule portfolio. The genetic algorithm is profitable even in the presence of transaction costs.
Another study about the performance of the genetic algorithms for FX markets has been developed in [35]. The authors show that the system often returned profit when the testing period was consecutive to the training period. They concluded that the success of the system depended on the similarity in the trends of the two periods. Also, genetic algorithms succeeded in finding performing trading rules for six exchange rates over the period 1981–1995 [36] .
One bias that may appear when one tests a large number of strategies on the same sample is the data-snooping bias. As explained in [37]. data-snooping bias appears when a set of data is used more than once for the purpose of model selection. Strategies that generate positive returns on a specific sample may be performing only due to luck and do not have a genuine predictive power. Therefore, when applied to a different sample, the results can be negative and investors may suffer important losses. A solution to this problem is the Bootstrap Reality Check developed by White [38] that relies on resampling the return series in order to give a reliable verdict regarding the genuine performance of the strategy.
Materials and Methods
The database used in this paper is the tick-by-tick series of EUR/USD currency pair over the year 2012 (ratedata.gaincapital.com). Time series with frequency of 60 minutes were used for testing the performance of the genetic algorithm.
Time series have been separated in two sets: the training period and the testing period. The first one considers the first six months of 2012 and is used for finding the strategy that achieves the highest performance. The second set tests the performance of the strategy found in the first step.
The algorithm is applied 100 times on the training time series, in order to find the characteristics of the best 100 individuals. We then assess the performance of these individuals on the out-of-sample series.
The hourly data extracted from the tick-by-tick data also consider the minimum and maximum tick for both bid and ask quotes. We needed this information to establish if the take-profit or stop-loss level had been reached during that period.
The purpose of the genetic algorithm is to optimize a set of trading rules to generate higher profit. Trading rules base their decisions on several indicators presented below together with their formulas.
Exponential moving average. It gives greater weights to the latest prices when computing the average. When the price is above this indicator, the signal is for a long (buying) position and when the price is below the exponential moving average it signals the selling.