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.

def exitPos(myExitPrice,myExitDate,tempName,myCurShares):

global mp,commission

global tradeName,entryPrice,entryQuant,exitPrice,

numShares,myBPV,cumuProfit

if mp < 0:

trades = tradeInfo('liqShort',myExitDate,tempName,

myExitPrice,myCurShares,0)

profit = trades.calcTradeProfit('liqShort',mp,

entryPrice,myExitPrice,entryQuant,myCurShares) * myBPV

profit = profit - myCurShares *commission

trades.tradeProfit = profit

cumuProfit += profit

trades.cumuProfit = cumuProfit

if mp > 0:

trades = tradeInfo('liqLong',myExitDate,tempName,

myExitPrice,myCurShares,0)

profit = trades.calcTradeProfit('liqLong',mp,

entryPrice,myExitPrice,entryQuant,myCurShares) * myBPV

trades.tradeProfit = profit

profit = profit - myCurShares * commission

cumuProfit += profit

trades.cumuProfit = cumuProfit

curShares = 0

for remShares in range(0,len(entryQuant)):

curShares += entryQuant[remShares]

return (profit,trades,curShares)

#------------------------------------------------------------

#End of functions

#------------------------------------------------------------

Lists and Variables Initiation You can use this section to initialize your own

lists and variables. These lines of code are pretty cool.

#------------------------------------------------------------

#Lists and variables are defined and initialized here

#------------------------------------------------------------

alist, blist, clist, dlist, elist = ([] for i in range(5))

marketPosition,listOfTrades,trueRanges,ranges =

([] for i in range(4))

dataClassList,systemMarketList,equityDataList =

([] for i in range(3))

181

USING PYTHON TO BACKTEST YOUR ALGORITHM

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!