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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

loops from trade #1 to the last trade. The interior loop loops from the current trade

number to the last trade.

# start trade draw down analysis - utilizing the tradeTuple

tupleLen = len(tradeTuple)

tradeTuple = sorted(tradeTuple,key=itemgetter(0))

for x in range(0,tupleLen):

cumStartTradeEquity = 0

maxStartTradeDD = -99999999

maxCumEquity = 0

for y in range(x,tupleLen):

cumStartTradeEquity += tradeTuple[y][1]

maxCumEquity = max(maxCumEquity,cumStartTradeEquity)

maxStartTradeDD = max(maxStartTradeDD,maxCumEquity -

cumStartTradeEquity)

startTradeTuple += ((x,cumStartTradeEquity,

maxStartTradeDD),)

266

GENETIC OPTIMIZATION, WALK FORWARD

The outer loop indexed by x controls the number of trade histories. The inner

loop indexed by y flows through the different trade histories and keeps track of

each history’s cumulative equity and maximum drawdown. At the beginning of each

trade history, these two values are zeroed out. Each trade’s P/L is stored as the

second element in the tuple tradeTuple. This value is extracted through each y

iteration and used to calculate the two performance metrics. Once an individual

history is created it is then stored in a list of tuples named startTradeTuple.

The first element in this tuple is x (the trade history number). The second element

cumStartTradeEquity stores the cumulative equity of the history and the third

element maxStartTradeDD stores the max drawdown of the history.

Once the trade histories are compiled, the bins that hold the different max

drawdowns must be constructed. The first step in the construction process is to

calculate the largest and smallest historic drawdown values.

minDD = 99999999

maxDD = 0

for y in range(0,len(startTradeTuple)):

print(startTradeTuple[y][0],' ',startTradeTuple[y][1],

' ',startTradeTuple[y][2])

if startTradeTuple[y][2] < minDD: minDD =

startTradeTuple[y][2]

if startTradeTuple[y][2] > maxDD: maxDD =

startTradeTuple[y][2]

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!