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.

■ PSB Structure

The PSB consists of a collection of files or modules. The main module is this one—it

pulls or calls all the other modules to facilitate the loading of data, looping through

each and every bar, accounting for all of the trades and input/output. If you want to

create another trading algorithm, you start with an existing one and simply save it as a

different name. There aren’t separate submodules that simply include trading logic.

This is just like the VBA-based ESB. This is unlike AmiBroker and TradeStation. In

these softwares, trading rules, functions, and indicators are stored in a library.

Everything you program will take place in this module or the indicators.py module.

All Python source code files have the .py extension. The PSB is very simple—type

in your trading logic, which hopefully you have derived from a flowchart or a finite

state machine, and then Check Module under the Run menu. If it passes, then

you simply Run it by going under the Run menu and selecting Run Module.

Let’s run this PSBBollinger module by selecting Run Module from the Run

menu. After you select Run Module, a File Browser window titled Select

Markets To Test will open. The PSB is asking you to select a .CSV file or files that

in can read into memory to which it will apply the Bollinger algorithm. Navigate to

the Commodity Data folder and select the file that starts with CL (crude oil). Once

you select the file and click OK, data and results generated by the algorithm will

flow to the Python Shell and be displayed there. The results are presented in the

following order:

Combined results. The PSB will combine the results of a multimarket selection. If

only one market is selected, then it will just be the results from the single market.

Combined monthly results. The monthly results in $ are shown for all markets

selected.

Individual market results. Performance metrics for each market are displayed.

Trade-by-trade results. A list of entries and exits and the $P/L derived from each

trade are shown.

That’s it. There aren’t any fancy charts involved—everything is presented in a

tabular format. If you want to see indicator values, you simply print them out to the

Shell. The PSB structure, just like IDLE, was kept as simple as possible. Let’s learn

some Python by looking at the different PSB modules.

171

USING PYTHON TO BACKTEST YOUR ALGORITHM

Indicator.py

This module contains all of the indicators that are utilized in the PSB. Go under the

File menu in the Shell and open indicators.py. Keep the Python Shell open and

quickly accessible. There are two types of indicators in this file. Some are just simple

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!