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.

the five different files. A total of five different objects would be spawned to handle

all of the data. The best way to keep these classe objects together would be to put

them in a list.Ibetyouknewalist can contain primitive data types like numbers,

strings, letters, and Booleans. But, I bet you didn’t know a list can contain complex

data structures like our marketDataClass. Jump over the Python Shell and type

the following:

>>> a = list()

>>> a = ["apple","banana","strawberry"]

>>> a

When you hit enter after the last line, the Shell will display:

[‘apple’, ‘banana’, ‘strawberry’]

No surprise here, it basically repeated what we put into the list. Now type this:

>>>b = list()

>>> b = ["pineapple","coconut","mango"]

c = list()

>>> c.append(a)

>>> c.append(b)

>>> c

and hit return. The Shell shows:

[[‘apple’, ‘banana’, ‘strawberry’], [‘pineapple’, ‘coconut’, ‘mango’]]

You have a list that contains two other lists. Notice the grouping? [‘apple’,

‘banana’, ‘strawberry’] is the a list and [‘pineapple’, ‘coconut’, ‘mango’] is the

b list.

This line of code, dataClassList.append(newDataClass) inserts the individual

marketDataClasse object in the dataClassList list. This list will be accessible

to the rest of the program later on.

Getting back to:

dataClassList = getData()

numMarkets = len(dataClassList)

portfolio = portfolioClass()

The first simple line of code does quite a bit. The next line starting with numMarkets

gets the length of the list that contains all the marketDataClass objects. In other

words, it returns the number of marketDataClass objects, which is the number

of markets selected by the user. The next line of code instantiates a portfolioClass

objectd labeled portfolio. The portfolioClass is quite large, so I won’t regurgitate

it here. I will in the appendices. There are some very important and cool things

going on in this class, so I want to highlight those very quickly. But before we

do, that there are two important class structures that are a prerequisite to the

187

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!