240 likes | 337 Vues
Explore the use of Genetic Algorithms in finance to optimize trading rules and decision-making processes. Genetic Programming and Building Block Functions are elaborated to enhance trading strategies.
E N D
An Example of the use of Genetic Algorithms in Finance Chris Riley March 8, 2007
Using Genetic Algorithms to Find Technical Trading RulesJournal of Financial Economics 51 (1999) 245-271 Franklin Allen The Wharton School, University of Pennsylvania Risto Karjalainen Merrill Lynch & Co., Inc., Mercury Asset Managent
Technical Analysis • Technical factors: price, volume, open interest • Use indicators to determine state of the market • Used to time entry and exit
Genetic Algorithm Use - Motivation • Technical trading rules are specified in an ad hoc manner • Accusations of data snooping – trading rules specified ex post • GA can derive trading rules that are optimal in some sense and are not ad hoc • Rules are chosen by a GA using price data available before the start of the test period
Genetic Programming • An extension of GA developed by Koza (1992) • Traditional GA represent genetic structures as fixed length character strings, which is restrictive if the size or form of the solution cannot be assessed beforehand
Genetic Programming • Solutions in GP are represented as hierarchical compositions of functions • These are tree-like structures • Successors of each node provide the arguments for the function identified with the node • Terminal nodes are the input data • The entire tree is a function evaluated recursively by evaluating the root node of the tree
Genetic Programming • Solution structure is not specified a priori • A set of building block functions are defined that are recombined by the GA • Initial population is composed of random trees • Root node is chosen at random among functions of the same type as the desired composite function • Each argument of that function is selected functions of the appropriate type • This continues down each branch of the tree until a function with no arguments is reached
Genetic Programming • Crossover – two solution candidates are recombined by replacing a randomly selected subtree in the first parent with a subtree from the second parent • If different types of functions are used within a tree, the crossover node from the first parent is chosen randomly, then the crossover node from the second parent is chosen from nodes of the same type • GP allows trading rules to be represented in a natural way
Building Block Functions • Simple functions of past price data • Numerical and logical constants • Functions are either real or Boolean • Root is always a Boolean function • Real functions include average, max, min, arithmetic operators, absolute value • Boolean functions include if-then-else, and, or, not, >, <
Trading Rules • Each genetic structure is a particular technical trading rule • The goal is to find decision rules that divide days into in the market (earning the market rate of return) or out of the market (earning the risk free rate) • Each rule returns either a buy or sell signal for any given price history • The signal specifies the position to take the following day
Trading Strategy • If the current state is ‘in’ and the trading rule signals ‘sell’ then move out of the market; if the current state is ‘out’ and the trading rule signals ‘buy’ then move into the market. • In the other states then no change • This strategy does not consider the possibility of short selling
Sample Trading Rules • Left: 50-day moving average • if moving average over past 50 days < then buy, else sell • Right: 30-day trading range break rule • if closing price > max of last 30 days then buy, else sell
Fitness Measure • Based on the excess return over the buy-and-hold strategy • Simple return from a single trade • Continuously compounded return fro a trading rule
Fitness Measure • Return for the buy-and-hold strategy (buy the first day, sell the last day) • Excess return
Constraints • Population size: 500 • Maximum nodes: 100 • Stopping criteria: 50 generations or until no improvement after 25 generations • Trials: 100
Data • S&P 500 index daily return data for January 3, 1928 to December 29, 1995 • One-month risk-free rates corresponding to Treasury bills from • CRSP for 1929 to 1991 • Datastream for 1992 to 1995 • Since the index is nonstationary, data is transformed by dividing each day’s price by a 250-day moving average
Example Trading Rule Formed by the Genetic Algorithm Price x minimum(price) – 0.0688 x price > 0.8943
Example Trading Rule Formed by the Genetic Algorithm lag(price,1) > average(price / abs(price - 1.1727))
Conclusions • Rules do not earn excess returns out of sample • Rules take long positions when returns are positive and daily volatility is low • Rules stay out of market when returns are negative and volatility is high • One day lag removes most forecasting ability, indicating the rules exploit positive low-order serial correlation
Results • From each of the 100 trials, one trading rule is saved • Find 89 trading rules in the 100 trials(no rules are saved if excess returns are not positive in selection period)