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.

■ Initial Population Setup Using VBA Excel

'All Lines starting with single quote is a comment

'Random variables into each chromosome’s genes

'Numbers range between 0 and 30

'Chromos will be represented by a table/matrix

'The first index in the chromo table will be row #

'The second index in the chromo table will be column #

'Excel's RNG is invoked by using the Rnd function call

'Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)

232

GENETIC OPTIMIZATION, WALK FORWARD

Randomize '<– must use this to get different numbers

For i = 0 To 5 ' Six Chromos

Next i

For j = 0 To 3 ' Four Genes

Next j

chromo(i, j) = Int((30 - 0 + 1) * Rnd + 0)

How good or fit is this population? Fitness is determined by how close each

chromosome comes to providing a solution to our equation. Remember, this is a very

simple problem, but these ideas are easily scalable to problems involving extreme

complexity. Calculating fitness is quite easy; simply plug in the chromosomes’

genes (values) for a, b, c and d. In chromosome (0) its fitness is determined by:

a(10) +2b(2 ∗ 11) +3c(3 ∗ 20) +d(19) =111. The solution we are seeking

is 40 so this fitness doesn’t seem to be that good. However, each chromosome’s

fitness is relative to all the other chromosomes.

Fitness 1: Chromosome(0) = 111

Chromosome(1) = 94

Chromosome(2) = 64

Chromosome(3) = 90

Chromosome(4) = 164

Chromosome(5) = 93

■ Testing Fitness of Chromosomes Using VBA Excel

'Equation is : a + 2b + 3c + d = 40

'a coefficient = Cell(3,3)

'b coefficient = Cell(3,4)

'c coefficient = Cells(3,5)

'd coefficient = Cells(3,6)

'the summation of the equation is in Cells(3,7)

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!