Genetic Algorithm

Genetic Algorithm is similar to Genetic Programming Module. It differs from Genetic Programming in that you have to write a buy and a sell rule with as many parameters as you wish, and declare the minimum and the maximum values for each parameter. If you use minimum and maximum values of float type (2.3, 1.7, 1.1, ...) you'll use that parameter as float, but be aware you need to put it in the rules so that it doesn't generate a syntax error. If you use minimum and maximum values of integer type (2, 3, 4, ...) you'll use that parameter as integer, but be aware to put it in the rules so that it doesn't generate a syntax error. The Genetic Algorithm process will modifiy the parameter values inside the rules, according to the range inserted.

A frequently asked question is the following: I've tried the genetic algorithm, but it doesn't work, is unable to finish or it stops after having found just some solutions. The genetic algorithm doesn't assure completion and sometimes a solution cannot be found. The only hint that can be given is choosing the buy and sell rules the best you can, so that the genetic algorithm can find a solution more easily, assuming it exists! The following sections show you two examples which may be of help.

RSI Example

A simple example is to use the following rules: buy rule: rsi(14)<32.0 + paramBuy, sell rule: rsi(14)>72.0 + paramSell. If you set paramBuy and paramSell with values changing from 0.0 to 1.0, you may find good solutions to the most of the trading periods. Pay attention to the parameters' setting: In this example we've set the parameters as float, otherwise set as integer you would have had only few solutions (4): (0,0), (0,1), (1,0), and (1,1), and the algorithm could not work properly.

Neural Network Example

A more complex but interesting example are the artificial neural networks. If you do not know anything about neural networks you can look at the Joone project on sourceforge. Here you can find just an example of neural networks, where the weights are from the genetic selection of the genetic algorithm. This is the only thing that can be done in genetic algorithm analysis section. For the sake of simplicity we use the sigmoid function, so the neuron is modelled by the Gondola expression: (1.0/(1.0+exp(-1.0*input))). The neurons are input for the hidden layer through the synapses, so each hidden layer will be ((v11*inputneuron1 + ... ) + v1n*inputneuronn). The same process can be applied for the output layer. At the end you obtain one output neuron for the buy rule and one for the sell rule that can be used in Venice.

If you want a quick couple of rules, I give you the rules that represent two artificial neural networks of 4 input neurons and 6 hidden neurons and 1 output neuron. The first neural network can be used for the buy rule, the second for the sell rule. The input are open, close, high and low, but you can modify as you like as soon as you've practised with that expressions. The parameters that you have to set are: v11 .. v64 (24 parameters), w11 .. w16 (6 parameters), y11 .. y64 (24 parameters), z11 .. z16 (6 parameters). I put them ranging from -1.0 to 1.0.

Here the long skeleton of buy rule to be inserted in the genetic algorithm section: (1.0/(1.0+exp(-1.0*(((((((w11*(1.0/(1.0+exp(-1.0*((((v11*(1.0/(1.0+exp((-1.0)*open))))+(v12*(1.0/(1.0+exp((-1.0)*close)))))+(v13*(1.0/(1.0+exp((-1.0)*low)))))+(v14*(1.0/(1.0+exp((-1.0)*high)))))))))+(w12*(1.0/(1.0+exp(-1.0*((((v21*(1.0/(1.0+exp((-1.0)*open))))+(v22*(1.0/(1.0+exp((-1.0)*close)))))+(v23*(1.0/(1.0+exp((-1.0)*low)))))+(v24*(1.0/(1.0+exp((-1.0)*high))))))))))+(w13*(1.0/(1.0+exp(-1.0*((((v31*(1.0/(1.0+exp((-1.0)*open))))+(v32*(1.0/(1.0+exp((-1.0)*close)))))+(v33*(1.0/(1.0+exp((-1.0)*low)))))+(v34*(1.0/(1.0+exp((-1.0)*high))))))))))+(w14*(1.0/(1.0+exp(-1.0*((((v41*(1.0/(1.0+exp((-1.0)*open))))+(v42*(1.0/(1.0+exp((-1.0)*close)))))+(v43*(1.0/(1.0+exp((-1.0)*low)))))+(v44*(1.0/(1.0+exp((-1.0)*high))))))))))+(w15*(1.0/(1.0+exp(-1.0*((((v51*(1.0/(1.0+exp((-1.0)*open))))+(v52*(1.0/(1.0+exp((-1.0)*close)))))+(v53*(1.0/(1.0+exp((-1.0)*low)))))+(v54*(1.0/(1.0+exp((-1.0)*high))))))))))+(w16*(1.0/(1.0+exp(-1.0*((((v61*(1.0/(1.0+exp((-1.0)*open))))+(v62*(1.0/(1.0+exp((-1.0)*close)))))+(v63*(1.0/(1.0+exp((-1.0)*low)))))+(v64*(1.0/(1.0+exp((-1.0)*high))))))))))))))>0.5

Here the long skeleton of sell rule to be inserted in the genetic algorithm section: (1.0/(1.0+exp(-1.0*(((((((z11*(1.0/(1.0+exp(-1.0*((((y11*(1.0/(1.0+exp((-1.0)*open))))+(y12*(1.0/(1.0+exp((-1.0)*close)))))+(y13*(1.0/(1.0+exp((-1.0)*low)))))+(y14*(1.0/(1.0+exp((-1.0)*high)))))))))+(z12*(1.0/(1.0+exp(-1.0*((((y21*(1.0/(1.0+exp((-1.0)*open))))+(y22*(1.0/(1.0+exp((-1.0)*close)))))+(y23*(1.0/(1.0+exp((-1.0)*low)))))+(y24*(1.0/(1.0+exp((-1.0)*high))))))))))+(z13*(1.0/(1.0+exp(-1.0*((((y31*(1.0/(1.0+exp((-1.0)*open))))+(y32*(1.0/(1.0+exp((-1.0)*close)))))+(y33*(1.0/(1.0+exp((-1.0)*low)))))+(y34*(1.0/(1.0+exp((-1.0)*high))))))))))+(z14*(1.0/(1.0+exp(-1.0*((((y41*(1.0/(1.0+exp((-1.0)*open))))+(y42*(1.0/(1.0+exp((-1.0)*close)))))+(y43*(1.0/(1.0+exp((-1.0)*low)))))+(y44*(1.0/(1.0+exp((-1.0)*high))))))))))+(z15*(1.0/(1.0+exp(-1.0*((((y51*(1.0/(1.0+exp((-1.0)*open))))+(y52*(1.0/(1.0+exp((-1.0)*close)))))+(y53*(1.0/(1.0+exp((-1.0)*low)))))+(y54*(1.0/(1.0+exp((-1.0)*high))))))))))+(z16*(1.0/(1.0+exp(-1.0*((((y61*(1.0/(1.0+exp((-1.0)*open))))+(y62*(1.0/(1.0+exp((-1.0)*close)))))+(y63*(1.0/(1.0+exp((-1.0)*low)))))+(y64*(1.0/(1.0+exp((-1.0)*high))))))))))))))>0.5