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 single line of code:

files = askopenfilenames(filetypes=(('CSV files', '*.txt'),

('All files', '*.*')),

title='Select Markets To Test')

opens an OS-independent File Open Dialog labeled Select Markets To Test

and asks the operating system to list all files with a .CSV extension in that particular

location. Once the user selects one or more files, the selection is passed back and

stored in the variable files.

fileList = root.tk.splitlist(files)

The files are then listed separately and stored in a list named fileList. This is all

handled with the built-in method root.tk.splitlist(files). This method takes all of

the files the user selected and then splits them apart and stores the individual file

names in a list.

head,tail = os.path.split(fileList[marketCnt])

tempStr = tail[0:2]

for i in range(totComms):

if tempStr == commName[i]:

commIndex = i

Another OS method os.path.split takes the name of each individual file and

splits the path name (C:\myPath\Data\) and the actual filename apart (BP.CSV).

The head variable is assigned the pathname and the tail variable the filename. Once

the filename is separated the first two letters in the filename can be accessed by

simply indexing into the string: tempStr = tail[0:2]. The first two characters in

the filename represent the symbol that was selected. From this the symbol can

be cross-referenced in the DataMaster and the market name, big point value, and

minimum move can be attached to the symbol.

newDataClass = marketDataClass()

newDataClass.setDataAttributes(commName[commIndex],

bigPtVal[commIndex],minMove[commIndex])

As soon as the filename is cross referenced with DataMaster,amarketData-

Class object with the variable name newDataClass is instantiated by calling the

marketDataClass() method. The marketDataClass class looks like this:

185

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!