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.

All these files deal with opening and reading a comma-delimited file. The rest of the

imported files all deal with the PSB.

Helper Functions for the PSB These functions help parse the .csv file into

the individual myDate, myHigh, myLow, myClose, myVol, andmyOpInt

lists. The attributes of each data file, symbol, pointValue, andminMove are

collected here as well. A function that calculates the results of exiting a trade is

also located here. I won’t bore you with the details of these functions right now,

but I want to bring to your attention another really cool thing about Python.

A Python function can return multiple values. The exitPos function returns

three values: profit, trades, andcurShares. When you call a multiple return

function, make sure you have the correct number of variables on the left side of

the assignment:

myProfit, myTrades, myCurShares = exitPos(price,myDate[i],

"RevLongLiq",curShares)

180

USING PYTHON TO BACKTEST YOUR ALGORITHM

The larger exitPos function was put here because it uses several global variables.

These variables are shared among most of the functions in this file module. I didn’t

want to have to pass these variables back and forth within different function calls.

I was slightly lazy in doing this, but it does help improve readability by reducing the

number of different parameters included in the argument list.

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

#Helper Functions local to this module

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

def getDataAtribs(dClass):

return(dClass.bigPtVal,dClass.symbol,dClass.minMove)

def getDataLists(dClass):

return(dClass.date,dClass.open,dClass.high,dClass.low,dClass.close)

def calcTodaysOTE(mp,myClose,entryPrice,entryQuant,myBPV):

todaysOTE = 0

for entries in range(0,len(entryPrice)):

if mp >= 1:

todaysOTE += (myClose - entryPrice[entries])

*myBPV*entryQuant[entries]

if mp <= -1:

todaysOTE += (entryPrice[entries] - myClose)

return(todaysOTE)

*myBPV*entryQuant[entries]

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!