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.

class stochClass(object):

class stochClass(object):

316

PYTHON SYSTEM BACKTESTER

def __init__(self):

self.fastK = 0

self.fastD = 0

self.slowD = 0

self.seed = 0

def calcStochastic(self,kLen,dLen,dSloLen,hPrices,

lPrices,cPrices,curBar,offset):

curBarLookBack = curBar - offset

testSeed = self.seed

if self.seed == 0:

self.seed = 1

stoKList =[]

stoDList = []

index1 = kLen - 1 + dLen - 1 + dSloLen -1

index2 = dLen - 1 + dSloLen -1

loopCnt = 0

for i in range(0,index2+1):

loopCnt = loopCnt + 1

hh = 0

ll = 9999999

lowRngBound = curBarLookBack - (index1 - i)

highRngBound =lowRngBound + 3

for k in range(lowRngBound,highRngBound):

if hPrices[k] > hh:

hh = hPrices[k]

if lPrices[k] < ll:

ll = lPrices[k]

if hh - ll == 0.0:

hh = ll + 1

whichClose = curBarLookBack - (index2 -i)

stoKList.append((cPrices[whichClose] - ll) /

(hh - ll) *100)

lenOfStoKList = len(stoKList)

self.fastK = stoKList[len(stoKList)-1]

if (i >= dLen-1):

tempSum = 0

lowRngBound = len(stoKList)-dLen

highRngBound = lowRngBound + dLen

for j in range(lowRngBound,highRngBound):

tempSum += stoKList[j]

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!