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.

percent wins, number of trades, and maximum drawdown. The methods in this

class set the pertinent data, such as system name and symbol, and calculate all the

performance metrics.

190

USING PYTHON TO BACKTEST YOUR ALGORITHM

def setSysMarkInfo(self,sysName,symbol,trades,equity):

self.systemName = sysName

self.symbol = symbol

self.tradesList = list(trades)

self.equity = equity

temp1 = 0

temp2 = 0

temp3 = 0

temp4 = 0

temp5 = 0

temp6 = 0

temp7 = 0

numTrades = 0

for i in range(0,len(self.equity.dailyEquityVal)):

temp5 = self.equity.dailyEquityVal[i]

temp6 = max(temp6,temp5)

temp7 = max(temp7,temp6-temp5)

self.maxxDD = temp7

for i in range(0,len(self.tradesList)):

if self.tradesList[i].entryOrExit == 1:

numTrades += 1

if self.tradesList[i].tradeProfit > 0:

temp1 += self.tradesList[i].tradeProfit

temp2 += 1

if self.tradesList[i].tradeProfit < 0:

temp3 += self.tradesList[i].tradeProfit

temp4 += 1

if temp2 != 0: self.avgWin = temp1/temp2

if temp4 != 0: self.avgLoss = temp3/temp4

if numTrades != 0: self.avgTrade = temp5/numTrades

self.numTrades = numTrades

self.profitLoss = temp5

if numTrades != 0: self.perWins = temp2 / numTrades

The setSysMarkInfo method is the only method in this class, but it does a bunch

of work. Notice about halfway through the variables with temp in their name; these

are temporary holders for data that is not stored in the class. They are born when

the method is called and die when the method exits. They are not members of the

class. The portfolio class is similar to the systemMarketClass, but is much more

macroscopic in nature. Basically, it sits on top of systemMarketClass and stores

aggregate information concerning the multiple markets in the portfolio.

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!