This document describes using Grammatical Evolution to automatically generate trading rules based on a Backus-Naur Form (BNF) grammar. The best rules found after 100 generations are presented, which were profitable when backtested on historical S&P 500 data from 2000-2008. However, this test does not guarantee real-world performance, as commission costs and true forecasting were not considered. Further experiments are needed using a more complex grammar and realistic settings.
2. buy buy buy sell sell sell sell An automatic trading system decides when to buy and sell based on a certain rule set If we base the rules on moving averages (colored lines) one possible rule would be: buy, if yellow crosses above purple
3. The following BNF (Backus–Naur Form) grammar makes it easy to describe a whole universe of different rule sets. <S> ::= <tradingrule> <tradingrule> ::= sigdn = ifelse(<signal>,-1,0);sigup = ifelse(<signal>,1,0); <signal> ::= (<signal>) AND (<signal>)|(<signal>) OR (<signal>)|<var> <relop> <var> <relop> ::= <= | >= <var> ::= sma5|sma10|sma20|sma40|sma80|sma160
4. Such automatically generated trading rules can be tested on historical data. If we define a criterion for the quality of a trading rule we can then create an algorithm that searches for the best possible set of trading rules. Grammatical Evolution
5. GEVA 2.0 That is the setup used for the result on the following slides.
6. BNF grammar The encoding and the grammar distinguishes Grammatical Evolution from Evolutionary Algorithms / Programming.
7. The following settings were used to construct a simple trading system. BNF grammar Settings for the genetic search algorithm
8. sigdn = ifelse( ( sma40 <= sma20 ) | ( sma160 >= sma80 ) ,-1,0); sigup = ifelse( sma5 <= sma10 ,1,0); The winning trading rules after 100 generations are: The following formula has been used to calculate the fitness of each rule set.
9. The best trading rules applied to the S&P 500 from 2000-01-02 to 2008-12-05. This is not an realistic test for real world performance, please notice remarks on next slide.
10.
11. No commission was included, which might explain the many trades on the short side. But, It clearly shows that the algorithm was capable to find trading rules that make intuitively sense and are profitable under the circumstances we provided. Further experiments with complexer grammar with more realistic settings is needed to obtain further insides.
22. Extensions of the GEVA 2.0 code and files needed to modify the rule generation. Setup GEVA and starts instance of R Here get the rule sets pushed into R and feedback captured R files to setup the data and evaluate the rule sets. BNF grammar Properties for genetic search.