How to time the stock market Using Artificial Neural Networks and Genetic Algorithms Donn S. Fishbein, MD, PhD Neuroquant.com ABSTRACT Despite considerable bad press that market timing has received in the past year, it remains the linchpin of successful investing. Although simple timing strategies can improve on buy-andhold performance, they suffer from several limitations. Artificial neural networks and genetic algorithms (ANN/GA) address some of these limitations, and offer a more flexible method to develop high performance market timing strategies. This paper will comment briefly on conventional market timing techniques, review continuing results of ANN/GA systems described by the author, and introduce a new ANN/GA market timing system. INTRODUCTION Market timing has gotten a bad name in the past year. Certain unethical or fraudulent mutual fund trading practices, specifically late trading and mutual fund zone arbitrage, were referred to in the press as market timing, and have contributed to the misunderstanding that all market timing is unethical or illegal. Market timing is not only legal, but a necessary strategy to profit in all market conditions. The very movement of the market is a function of investors and speculators trying to buy low and sell high - the very definition of market timing (Timertrac). Market timing refers to buying and selling investments based on a prediction of how well the market will perform in the future. A wide range of techniques are available for market timing, some of which have been reviewed in earlier papers (Fishbein, 2001, 2002) and elsewhere (Acheli). There are those who contend that market timing does not improve investment returns. Two closely related theories, that of efficient markets and market random walk, state that all that known about market valuation is incorporated into the current market price, and therefore the next price movement will be random, and therefore unpredictable. It is surprising how long-lived these theories have been when they are so easily disproved. THE FOUR PERCENT SWING SYSTEM Few things are harder to put up with than the annoyance of a good example. Mark Twain The good example is this case is the 4% Swing investment strategy, developed by Ned Davis of Ned Davis Research. The system is easy to explain and quickly disproves the theory that market timing doesn t work. Marty Zweig popularized the percent swing system in a 1986 book entitled Winning on Wall Street (Zweig, 1986). The system logic is very simple. Originally based on weekly closes for the Value Line Composite index, the system buys after a four percent
rise above a prior weekly low and sells after a four percent decline from a prior weekly high. The system can be followed on a chart without a computer. The system was profitable during a 19- year back-test period from 1966 to 1985, prior to its publication, and has remained profitable since its publication. Figure 1-4% Swing System NASDAQ-100 Trust (QQQ) 1999-Apr 2004, Weekly Bars; Buys Indicated By Up Arrows Below Price Bars, Sells By Down Arrows Above Price Bars The system meets the criteria of broad applicability and robustness for traditional technical analysis systems. First, it works well across different instruments, such as stocks, market indices, and futures. The above chart shows the indicator applied to the Nasdaq-100 exchange traded fund QQQ, which didn t come into existence until decades after the first description of the percent swing system. Second, it works well across different time frames such as hour, day, and week bars. Finally, its parameters, the percent upswing necessary to trigger a buy and the percent downswing necessary to trigger a sell, are not particularly critical. The system works with a wide range of values, and is therefore robust. Although its gains are not spectacular, it has beaten market averages in both back tests and forward tests since its introduction. Using the 4% swing system over the past four decades would have allowed you to miss much of the 1973-74 bear market, miss the 1987 crash entirely, and miss most of the recent bear market. The four percent swing system logic guarantees that a significant move in either direction will not be missed. While adequate to demonstrate that technical analysis has merits, the percent swing system also demonstrates the weaknesses of simple nonadaptable systems with fixed parameters. Although its logic is good at capturing trending market moves, it does poorly in a range bound market. It subjects its adherents to whipsaws, in which signals are triggered just as a minor move is completed and the
market reverses to the opposite direction. A more adaptable system might be able to recognize trending from trend-less markets, and only fire signals when a trending market was detected. Alternately, parameters could be dynamically adjusted to better fit current market conditions. The tradeoff for robustness and general applicability in the four percent swing system is somewhat lackluster performance. Although the system beats market averages over long periods of time, it suffers from poor performance during trend-less market periods. When average market swings are less than 4%, the system doesn t trigger. When swings are between 4% and 8%, the system triggers and loses money with each trade. The markets on average do not trend strongly, and therefore it is up to periods of strong trend to make up for the losses suffered in trend-less markets. The weaknesses of the four percent swing system, mainly its lack of adaptability to changing market conditions, can be ameliorated in several ways. Rules could be constructed to attempt to identify whether the instrument was trending or not, and apply the four percent swing only during strong trends. During range-bound conditions, other trading systems could be used, or the trader could simply remain flat (Fishbein, 2001). THE ADAPTABILITY OF NEURAL NETWORK BASED INDICATORS By their nature, properly constructed ANN/GA trading systems are adaptable to changing market conditions. In an earlier paper (TCF 2003), ANN/GA trading systems initially described between 2000 and 2002 were reviewed. All remained profitable during the 2002 to 2003 period, without any change in their network design. The AMA 2 SMA system was first presented in 2001 and subsequently discussed several additional times (Fishbein 2002, 2003). It is based on a specialized neural network construct, a general regression neural network (GRNN), to calculate a smoothed, adaptive moving average of the closing price. The relationship SMA 1 < AMA < SMA 2 is evaluated, where AMA refers to the adaptive moving average, and SMA 1 and SMA 2 are simple moving averages whose parameters are determined by a GA. The same expression is evaluated for triggering long and short trades, with only the parameters for each SMA differing. Separate training and evaluation periods are typically not employed with systems based on GRNNs, because these systems are never predicting the training set. Rather, they perform a comparison of today s bar with all of the bars in the training set. The output they produce is in effect a weighted average of all of the outputs of those bars which are similar to today s bar. The AMA 2 SMA system has remained profitable in each year since it was introduced. In the year ending on April 8, 2004, the system returned 26.5% trading the Dow Jones 30 exchange traded fund (DIA), 12.7% trading the S&P 500 exchange traded fund (SPY), and 80.1% trading the Nasdaq-100 exchange traded fund (QQQ). During this same period, the buy-and-hold return for QQQ was 41.7%. TREND QUALITY INDICATOR NEW INDICATORS and their ANN/GA ADAPTATION
One of the most productive uses of ANN/GA in market timing is to make small, incremental improvements to existing timing systems. David Sepiashvili described the Trend- Quality Indicator in a recent article in Technical Analysis of Stocks & Commodities (Sepiashvili, 2004). The author defined two indicators, the Q-indicator and the B-indicator, which attempt to measure the strength of an existing trend. The Q-indicator is unbounded, while the B-indicator is an oscillator which varies between 0 and 100. The implication is that stronger trends are more sustainable and therefore easier to trade. Sepiashvili s article is insightful, and looks at trend identification in a unique way. The author provides that the indicators may then be used to recognize trends and their strengths. To use these indicators to trade financial instruments mechanically, they need to be incorporated into a system, with entry and exit rules at a minimum. This usually involves setting parameters for each indicator which determine whether the indicator favors a long, neutral, or short position. Establishing parameters involves choosing fixed values, and furthermore optimizing these values for the time period and specific instrument under consideration. When more than one indicator is being used, the question of how to weight each indicator and how to combine them to yield a single buy, hold or sell signal also arises. The process of optimizing a system is complicated, and runs the risk of curve-fitting, in which parameters are selected that best fit the historical data but do not predict future data. ANN/GA offer another approach for turning indicators into a full-blown trading system. The indicators are used as inputs to a feed-forward, back-propagation neural network, usually in combination with the closing price. The neural network is trained using historical data, holding back a portion of the data for walk-forward testing. The neural network establishes a complex, non-linear relationship between the indicators and the desired output, namely long, hold or short. The risk of overoptimization of the network is reduced by limiting both the size of the neural network and the optimization time. A genetic algorithm can be used at the same time to optimize fixed values contained within the indicators. Finally, the held back out-of-sample data is tested with the fully trained and optimized network to assess whether it yields profitable results. The Q-indicator and B-indicator are calculated using several intermediate indicators, which in turn are based on the closing price and two exponential moving averages (7 and 15 day). All of these indicators, along with the closing price itself, are used as inputs to a feed-forward backpropagation neural network, which seeks to predict the per cent change in the closing price 10 days in the future. Based on this prediction, buy and sell signals are generated. The fixed parameters are optimized using a genetic algorithm. The networks are trained using 30 months of daily closing prices for the Nasdaq-100 and S&P 500 exchange traded funds, QQQ and SPY respectively. The systems were always in the market, either long or short.
Figure 2 Trend Quality Indicator: Top-QQQ Close 2001-2004; Middle - QIndicator and BIndicator; Bottom: TQI Trading Strategy, Buys Indicated By Up Arrows Below Price Bars, Sells By Down Arrows Above Price Bars The networks performed well during the training and testing periods, which encompassed the period from Jan, 2001 to March, 2004. Results were evaluated trading a fixed number of shares for each trade, with allowances for commission costs. During this period, the QQQs (Nasdaq-100) lost 0.7% annualized, while the network trading the QQQs gained 41.3% (64.6% training, 21.9% out-of sample testing) annualized. The SPYs (S&P 500) lost 5.0% annualized, while the network trading the SPYs gained 26.0% (31.9% training, 14.6% out-of-sample testing) annualized. In both cases, the networks trained with indicators of the Trend Quality Indicator significantly outperformed buy-and-hold. SUMMARY Investment returns can be improved by using market timing strategies. Conventional market timing techniques do not generalize well across all markets and time frames. In addition, they require considerable trial and error to arrive at a workable set of indicators and parameters. ANN/GA offer a method to develop customized indicators for specific financial instruments and time frames, and can aid in successful market timing and trading. REFERENCES Acheli SB. Technical Analysis from A to Z. http://www.equis.com/free/taaz/ Fishbein DS. Trading Financial Markets with Neural Networks and Genetic Algorithms. Trenton Computer Festival Proceedings, 2001.
Fishbein DS. Neural Networks and Genetic Algorithms: Another Tools for the Technical Analysis of Financial Markets. Trenton Computer Festival Proceedings, 2002. Fishbein DS. Mechanical Stock Trading Systems That Really Work. Trenton Computer Festival Proceedings, 2003. Neuroquant.com: www.neuroquant.com Sepiashvili D. Trend Quality Indicator. Technical Analysis of Stocks & Commodities, Vol 22:4, April 2004, pg. 14-20. Timertrac.com: www.timertrac.com Zweig, M. Winning of Wall Street. 1986, 1997(revised), Warner Books, 282 pg.