13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

391

thresholds are set to 1.5 and 0.5 standard deviations, respectively. Since the account equity is

set at 500,000 USD the base_quantity of shares is set to 10,000.

These values can all be tested and optimised, such as with a grid-search procedure if desired.

# coint_bollinger_strategy.py

..

..

# Use the Cointegration Bollinger Bands trading strategy

weights = np.array([1.0, -1.213])

lookback = 15

entry_z = 1.5

exit_z = 0.5

base_quantity = 10000

strategy = CointegrationBollingerBandsStrategy(

tickers, events_queue,

lookback, weights,

entry_z, exit_z, base_quantity

)

strategy = Strategies(strategy, DisplayStrategy())

..

..

To run the backtest a working installation of QSTrader is needed and these two files described

above need to be placed in the same directory. Assuming the availability of the ARNC and UNG

data, the backtest will execute upon typing the following command into the terminal:

$ python coint_bollinger_backtest.py --tickers=ARNC,UNG

You will receive the following (truncated) output:

..

..

Backtest complete.

Sharpe Ratio: 1.22071888063

Max Drawdown: 0.0701967400339

Max Drawdown Pct: 0.0701967400339

27.6 Strategy Results

27.6.1 Transaction Costs

The strategy results presented here are given net of transaction costs. The costs are simulated

using Interactive Brokers US equities fixed pricing for shares in North America. They do not

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

Saved successfully!

Ooh no, something went wrong!