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.

The one trade that you took on Day 4 was a disaster. First off, you closed out a $12

loser ($112 − $100), and to add insult to injury your OTE is −$10 ($100 − $110).

You real cumulative losses stand at −$2 and your paper loss stands at −$10. All these

values are needed to calculate a daily equity stream and that is why we have: self.cls

TrdEquity, self.openTrdEquity, self.cumuClsEquity. The rest of the module

keeps track of the daily equity stream as well as the maximum equity peak, and

the subsequent equity valley. From these values the worst-case drawdown can be

derived.

def setEquityInfo(self,equityDate,equityItm,clsTrdEquity,

openTrdEquity):

self.equityDate.append(equityDate)

self.equityItm.append(equityItm)

self.cumuClsEquity += clsTrdEquity

tempEqu =self.cumuClsEquity+openTrdEquity

self.dailyEquityVal.append(tempEqu)

self.peakEquity = max(self.peakEquity,tempEqu)

maxEqu = self.peakEquity

self.minEquity = min(self.minEquity,tempEqu)

minEqu = self.minEquity

self.maxDD = max(self.maxDD,maxEqu-tempEqu)

maxDD = self.maxDD

maxDD = maxDD

The next class, systemMarketClass, is used to keep track of each system on each

individual market. I did this in case a future version of PSB might combine multiple

markets on multiple systems. You could have a bunch of these systemMarketClass

objects reflecting the performance on several system/markets; you then could

combine certain ones to produce a very efficient equity curve. For right now,

though, these class objects contain the following data:

def __init__(self):

self.systemName = ""

self.symbol = ""

self.tradesList =list()

self.equity = equityClass

self.avgWin = 0

self.avgLoss = 0

self.avgTrade = 0

self.profitLoss = 0

self.numTrades = 0

self.maxxDD = 0

self.perWins = 0

189

USING PYTHON TO BACKTEST YOUR ALGORITHM

Each systemMarketClass contains the name of the system and the symbol. In

addition, it stores a list of trades, the equity stream, the average win, loss, and trade,

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!