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.

186

USING PYTHON TO BACKTEST YOUR ALGORITHM

class marketDataClass(object):

def __init__(self):

self.symbol = ""

self.minMove = 0

self.bigPtVal = 0

self.seed = 0

self.date = list()

self.open = list()

self.high = list()

self.low = list()

self.close = list()

self.volume = list()

self.opInt = list()

self.dataPoints = 0

def setDataAttributes(self,symbol,bigPtVal,minMove):

self.symbol = symbol

self.minMove = minMove

self.bigPtVal = bigPtVal

def readData(self,date,open,high,low,close,volume,opInt):

self.date.append(date)

self.open.append(open)

self.high.append(high)

self.low.append(low)

self.close.append(close)

self.volume.append(volume)

self.opInt.append(opInt)

self.dataPoints += 1

This class acts like a container that holds all of the price data and market attributes

for each file selected by the user. It also contains the methods for gathering that data.

The init method creates all of the storage needed to handle years and years of data.

Other than the single variables self.symbol, self.minMove, self.bigPtVal, the

rest of the data holders are lists. Each list is capable of holding tremendous amounts

of data. The other two methods, setDataAttributes and readData, areusedto

set the market specifications and fill up the lists with price data. Notice Python uses

the .append method to add values to an existing list. Lists act like arrays, but are

much more powerful due to their associated methods. If I want to know the number

of elements in a list, all I have to do is: listLen = len(myList). Len() is simply a

method of the list class.

Now keep in mind all of this code is inside a for loop. The number of loops

is determined by the number of markets selected by the user. If the user selected

five files, then this loop would be performed five times. You would have five

instantiations of the marketDataClass objects, and each would be used to set the

market specifications for the five markets and read in the different price data from

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!