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.

168

USING PYTHON TO BACKTEST YOUR ALGORITHM

who is deeply devoted to FORTRAN and C. The skillset that you would acquire

would only enhance your abilities in other languages and testing/trading platforms.

Python has caught on for many reasons, but the biggest is ease of learning.

Plus, you are exposed to the two predominant programming paradigms: object

oriented and procedural. If you were formally educated in computer science in

the 1970s and 1980s, you probably come from the procedural school of thought.

I have a programmer friend who worked at Bell Laboratories in the 1970s, and he

doesn’t even want to talk about ‘‘objects.’’ Today’s programmers, or should I say

constructors, can build a rich graphical user interface (GUI) in a matter of minutes—

something that took me a week to do back in the 1980s. A really good programmer

can use both objects and procedures.

This chapter introduces ideas from both schools of thought. However, this chapter

is only a small introduction to the Python language. If you want to learn more

about Python and computer science in general, I highly recommend John Zelle’s

Python Programming: An Introduction to Computer Science. This book provides a solid

foundation not only in Python but also in some of the most useful topics in computer

science—knowledge that can be carried over into the trading arena.

In this new world of touchscreens, the usage of typing in a command line is disappearing.

Well, that is if you are not from a Unix background. Python programmers

become very comfortable with the command line, because it is so powerful. In many

cases, a sophisticated user interface isn’t necessary and this backtesting application

is one of those cases. There isn’t any exposure to developing a GUI because it

wasn’t necessary. Time was spent on topics that provided exposure on file manipulation,

simple input/output, objects, and functions. Before we start discussing

the Python system backtester (PSB), here is a list of why Python was the language

of choice:

Python is an interpreted language. The user doesn’t need to go through an additional

compilation step. Once you type the program into the editor, all you need to do

is run it. If there is a syntax or runtime error, the Python shell will let you know

about it.

Python has a shell. This interactive command line interpreter can be used for testing

small bits of code, as the output window for printing out information from your

programs, or as a very cool calculator. The PSB uses this window exclusively in

this tutorial. This window also alerts you to syntax and runtime errors.

Python is dynamically typed. A user can create a variable name on the fly without

having to declare/size it before using it. This is similar to AFL and VBA. This

helps the creative flow process. In other languages, when you create a variable

you have to go back to the top of the code and declare it. By the time you get

back to using it, you might have forgotten what you were planning on doing.

Well, this is a problem I suffer; you might not. There are both advantages and

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!