31.07.2021 Views

Ultimate Algorithmic Trading System

Using automated systems for trading in stock markets

Using automated systems for trading in stock markets

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mutating Chromosomes—Using VBA Excel

242

GENETIC OPTIMIZATION, WALK FORWARD

mutRate = 0.1 ' rate of mutation

numMutations = Int(mutRate * 24) ' 24 genes available for

mutation

Call printDivider(lineCount, 4)

lineCount = lineCount + 1

Randomize

For i = 0 To numMutations - 1 'loop for 2 mutations

Next i

chromoMut(i) = Int((24 - 0 + 1) * Rnd + 0) 'which

genes to mutate

genLocRow = Int(chromoMut(i) / 4) 'locate the gene

in the matrix

If genLocRow = 0 Then genLocRow = 1

genLocCol = 4 - chromoMut(i) Mod 4

chromoMutCoOrds(i, 0) = genLocRow - 1 'found gene row

chromoMutCoOrds(i, 1) = genLocCol + 1 'found gene

Randomize

column

rndVal = Int((24 - 0 + 1)*Rnd + 0) 'randomize the new gene value

chromo(genLocRow - 1, genLocCol - 1) = rndVal

After selection, reproduction, and mutation a new generation has been created.

Here are the second generation’s chromosomes and respective fitness values after

subtracting 40:

Chromosome (0) = [16,05,13,28] = 53

Chromosome (1) = [13,08,22,20] = 75

Chromosome (2) = [00,30,30,04] = 114

Chromosome (3) = [16,05,13,28] = 53

Chromosome (4) = [10,30,30,04] = 124

Chromosome (5) = [00,20,05,15] = 30

It seems redundant to state this again, but here is another example of how genetic

algorithms mimic nature by not only creating inferior offspring but also creating

an inferior generation. However, since these generations live inside of a computer,

they are short-lived and the computer moves quickly onto the next generation until

a solution is found. This GA solved the problem in 13 generations after a mutation

occurred. Eventually, chromosome (2) with genes [13,0,4,15] was chosen as the

solution. Test it!

Test ∶ 13 + 2 ×(0)+3 ×(4)+15 = 40

www.rasabourse.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!