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.

exitQuant.append(numShares)

profit,trades,curShares = exitPos(price,myDate[i],

tradeName,numShares)

if curShares == 0 : mp = marketPosition[i] = 0

totProfit += profit

todaysCTE = profit

listOfTrades.append(trades)

maxPositionL = maxPositionL -1

Unless you are adding a new indicator to the indicator.py file, this is the only file

you will ever need to modify. Once you make your changes, all you need to do

to run your algorithm is go under the Run menu and select Check Module. If

everything checks out, then you go under the Run menu once again and select Run

Module.

I guarantee that you will get some type of syntax error or run-time error every

time you create a new trading algorithm module. This is a good learning experience,

as IDLE will point out the offending line of code. Figure 6.2 is an example of a

syntax error message dialog and Figure 6.3 shows the offending line. You will see

this until you stop forgetting the difference between the assignment operator (=)

and the comparison operator (==).

Another easy thing to forget is using parentheses ( ) when you really want to use

square brackets [ ]. If you do make this mistake you will see the error message shown

in Figure 6.4.

This is a run-time error because it will pass the Check Module. However,

when you run the module, it will pop this error message into the Python Shell. The

FIGURE 6.2

A Python syntax error message.

199

USING PYTHON TO BACKTEST YOUR ALGORITHM

FIGURE 6.3 In this case, the syntax error was the result of confusion between the assignment

operator (=) and the comparison operator (==). Python highlights the problematic code.

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!