a real-time adaptive trading system using genetic programming

33
A real-time adaptive trading system using Genetic Programming QF5205 : Topics in Quantitative Finance Donny Lee Nadim Mouchonnet

Upload: xue

Post on 26-Feb-2016

46 views

Category:

Documents


0 download

DESCRIPTION

A real-time adaptive trading system using Genetic Programming. QF5205 : Topics in Quantitative Finance Donny Lee Nadim Mouchonnet. Summary. Introduction Genetic Algorithm and Genetic Programming Trading System Genetic Program Results. Introduction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A real-time adaptive trading system using Genetic Programming

A real-time adaptive trading system using Genetic Programming

QF5205 : Topics in Quantitative FinanceDonny Lee

Nadim Mouchonnet

Page 2: A real-time adaptive trading system using Genetic Programming

Summary

1. Introduction2. Genetic Algorithm and Genetic Programming3. Trading System4. Genetic Program5. Results

Page 3: A real-time adaptive trading system using Genetic Programming

Introduction

• Many traders use indicator based trading rules• … but they may be loss making (see chart)• Double Objective

Create a system than trades and make profitEmulate the behavior of a technical trader

Motivation:“Can a technical trader consistently make a profit?” and “should a technical trader or trading system adapt to market conditions or is it better to use a static system?”

Page 4: A real-time adaptive trading system using Genetic Programming

Introduction(2)

• Results using only a single strategy, backtested on historical data.

• Stochastic strategy: Buy when indicator crosses the 20% mark from below and sell when it crosses the 70% mark from above.

• Simple moving average strategy: Buy when the slow lag (50 day look back) crosses the fast lag (20 day look back) from below and sell when vice versa.

Page 5: A real-time adaptive trading system using Genetic Programming

Introduction(3)• Using the stochastic strategy on SIA stock from 02/11/10 to 08/26/10.• Loss is $0.30.

Page 6: A real-time adaptive trading system using Genetic Programming

Introduction(4)• Using the SMA strategy on KEP stock from 02/11/10 to 08/26/10.• Loss is $0.27.

Page 7: A real-time adaptive trading system using Genetic Programming

Introduction(5)• Using the GBPUSD for a period of 3 months• Bloomberg can summarize a whole bunch of strategies

Page 8: A real-time adaptive trading system using Genetic Programming

Introduction(6)• Using the GBPUSD for a period of 3 months• Parabolic SAR

Page 9: A real-time adaptive trading system using Genetic Programming

Genetic Algorithm and Genetic Programming (1)

• GA is an iterative system• … aiming to find near-optimal solutions• … to multi-extremal problems• … by imitating the process of evolution• Rule is : SURVIVAL OF THE FITTEST

Page 10: A real-time adaptive trading system using Genetic Programming

Genetic Algorithm and Genetic Programming (2)

• GA representation consists of binary strings of fixed length.

• Search space is finite• GA needs to be initialized …• … by random sampling• Difference between GA and GP is that GP

allows string length to vary within the solution space.

Page 11: A real-time adaptive trading system using Genetic Programming

Trading System : Data

• Analysis carried out on spot FX ticks for GBP/USD from CQG Data Factory and Future Source from 1994 to 1997

• CQG : gathered from various FX brokers• Future Source : live feed from the Omega

TradeStation utility (major banks FX quotes)• Got bid and ask and transforms them into mid• Data aggregated into OHLC

Page 12: A real-time adaptive trading system using Genetic Programming

Trading System : Software

• Imitating the technical trader i.e. chooses technical strategies from a range of popular trading rules

• GP based rule selection engine choosing combinations of such strategies

• Cash management filter exits strategies when losses > user-defined threshold

• Each backtested strategy returns : Profit, max drawdown, Modified Stirling ratio, number of trades

• Transaction costs are taken into account with various slippage depending on trading time

Page 13: A real-time adaptive trading system using Genetic Programming

Trading System : Software

Page 14: A real-time adaptive trading system using Genetic Programming

Trading System : Strategies

• 6 Rules used : simple moving averages crossover, adaptive moving averages, price channel breakout, stochastic, relative strength index, commodity channel index

• 3 Connectors : AND / OR / XOR (00/01/10)• System rules allowed to use different

frequencies/lags• Strategies ranked by stirling ratio (when return is

positive) or by absolute return when negative.

Page 15: A real-time adaptive trading system using Genetic Programming

Genetic Program• Representation of a strategy.• A strategy of ours can be represented graphically.

Page 16: A real-time adaptive trading system using Genetic Programming

Genetic Program(2)• From a graphical understanding of a strategy, we can translate

to a strategy structure. or a binary string representation.

Page 17: A real-time adaptive trading system using Genetic Programming

Genetic Program(3)• Or a binary string representation.

Page 18: A real-time adaptive trading system using Genetic Programming

Genetic Program(4)• This is essential as we ultimately need to convert our strategy

into a binary string for our GP to work.

Each strategy can be written in the form

RULE | CONDITION | CONNECTOR |RULE | CONDITION | CONNECTOR | ……… | ACTION

Page 19: A real-time adaptive trading system using Genetic Programming

Genetic Program(5)• From there, we can form our binary string representation for

our GP.

I.e., consider the rule “BUY if AMA TRUE AND CCI FALSE OR RSI TRUE”

It would be represented in binary as,

1000011111

Page 20: A real-time adaptive trading system using Genetic Programming

Genetic Program(6)• Now with each strategy represented as a binary string, we

perform the following in each iteration.

1. Initialize population2. Calculate Fitness3. Crossover4. Mutate

Page 21: A real-time adaptive trading system using Genetic Programming

Genetic Program(7)• We initial the population with a certain number of strings

which will represents the strategies we will use.

1. Assume there are a maximum of k included indicators and a minimum of j. We may construct rules from a total of I indicators.

2. Generate U uniform pseudo-random integer variables V where 1 <= V <= I. For indicators to be used, we write a ‘1’ in the structure part, otherwise a ‘0’.

3. Generate U uniform pseudo-random binary variables corresponding to the indictor bit for each indicator.

4. Assume there are C connectors allowed. For each indicator, we generate a fixed width binary of D(1,C) and write it next to the corresponding indicator bit.

Page 22: A real-time adaptive trading system using Genetic Programming

Genetic Program(8)• At each trial over a user-defined period, each of these

strategies is tested by simulating their trading performance over historical data.

• There are many ways to assess performance. The Stirling ratio – profit divided by maximum drawdown – is often used by traders to assess performance.

• For Crossover and Mutation, we would pick a strategies with a certain top % in their Stirling ratio.

Page 23: A real-time adaptive trading system using Genetic Programming

Genetic Program(9)• Crossover is the process of cutting strategy string pairs at

points and exchanging tails and heads to make a new a pair.

• Only the best s% are considered for crossover. For those strings rank i, the probability of selecting this string is

• A cut point is selected uniformly pseudo-randomly and ‘head’ and ‘tail’ parts are exchange.

Page 24: A real-time adaptive trading system using Genetic Programming

Genetic Program(10)An example of a Crossover, suppose the following two pairs of strings are selected along with a uniformly distributed random number:

1010001010 and 1100111100 and 30100100111 and 0001101110 and 8

Crossover:101|0001010 and 110|0111100 becomes

1100001010 and 1010111100 01001001|11 and 00011011|10 becomes

0100100110 and 0001101111

Page 25: A real-time adaptive trading system using Genetic Programming

Genetic Program(11)• Mutation is the process of randomly changing appropriate bits

in a strategy string and is executed in a bitwise manner.

• Elitist model: top-ranked 5% of strings are not mutated.• Number of strings mutated = Mutation Rate x No. of Strings.

• M uniform pseudo-random integer are generated between 1 and B, length of each string, without replacement.

• Each corresponding numbered bit is then mutated (‘0’ becomes ‘1’ and ‘1’ becomes ‘0’)

Page 26: A real-time adaptive trading system using Genetic Programming

Genetic Program(12)• Example of a mutation.

• Strings are of length 10 and four pseudo-random integers are generated and arranged in ascending order – 3, 5, 7, 8.

• The following strings are mutated as follows:

1010001010 becomes 10001001101100111100 becomes 11100100000100100110 becomes 01100010100001101110 becomes 0011000010

Page 27: A real-time adaptive trading system using Genetic Programming

Genetic Program : Summary

Step 1• Initialize : Generate 100 strategies randomly

Step 2• Crossover strategies using 50% of the best strategies

Step 3• Mutate the strategies outside the best 5%

Step 4• Repeat Steps 2 & 3 until convergence of the solutions

Page 28: A real-time adaptive trading system using Genetic Programming

Results : Test

• Step 1 : In Sample backtesting using 15-minute data used to determine the 20 best strategies during Q1 1994

• Step 2 : Out Sample trading using the best 20 strategies over the next quarters and assess the performance in live trading conditions

Page 29: A real-time adaptive trading system using Genetic Programming

Results : Improvement of solutions (1)

Page 30: A real-time adaptive trading system using Genetic Programming

Results : Improvement of solutions (2)

Page 31: A real-time adaptive trading system using Genetic Programming

Results : Profit

Page 32: A real-time adaptive trading system using Genetic Programming

Results : Further work

• Periodic reoptimization as performance decreases as time out of sample increases

• Parallel optimization

Page 33: A real-time adaptive trading system using Genetic Programming

Our experience

• Unsuccessful Programming in the Java framework

• 1 solution : using the Technical Analysis tool of Bloomberg’s Excel Add-in