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 portfolioClass(object):

def __init__(self):

self.portfolioName = ""

self.systemMarkets = list()

self.portEquityDate = list()

self.portEquityVal = list()

self.portclsTrdEquity = list()

self.portDailyEquityVal = list()

self.portPeakEquity = 0

self.portMinEquity = 0

self.portMaxDD = 0

tempEqu = 0

cumEqu = 0

maxEqu = -999999999

minEqu = 999999999

maxDD = 0

As you know, a portfolio is simply a collection of different markets. A portfolio

has to have a name, a list of the different systemMarkets or just markets, and

lists that make up equityDate, equityVal, clsTrdEquity, anddailyEquity at

the portfolio level. The methods involved with this class are rather long and for

brevity’s sake will not be displayed here. All classes including their methods will be

listed in the appendix. There are a couple of Pythonesque list features I would like

to discuss, because they are so cool. If you have traded commodities or futures, you

know some days one market is open and another closed. Creating a master date list

to contain the daily portfolio equity had to take this into consideration. The use of

Python’s lists made creating a master date list that included all the dates of the entire

portfolio very easy. I simply concatenated (added together) all of the different date,

not data, streams from each systemMarket.

for i in range(0,len(self.systemMarkets)):

masterDateList += self.systemMarkets[i].equity.equityDate

This loop starts at 0 and loops through all the systemMarkets. If you have five

markets in your portfolio, then the loop would start at 0 and end at 4. You will

notice the += operand after masterDateList in the code. This is a shortcut like

a = a + 1. Using this operand eliminates repeating the variable name after the equal

sign. If you want to see how this works, jump over to the Python Shell and type this:

191

USING PYTHON TO BACKTEST YOUR ALGORITHM

>>> a = list()

>>> a = [1,2,3,4,6,7,8,9]

>>> b = list()

>>> b = [1,2,3,4,5,6,7,8,10]

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!