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.

432

’--filename’,

default=’’,

help=’Pickle (.pkl) statistics filename’

)

def main(config, testing, tickers, filename):

tickers = tickers.split(",")

config = settings.from_file(config, testing)

run(config, testing, tickers, filename)

if __name__ == "__main__":

main()

In order for the code to work it is necessary to change the paths to your appropriate data

directories for both the AREX bar data CSV file and the directory where the pickle model lives.

It will be necessary to change the following directories to point to your data:

• csv_dir = "/path/to/your/data/"

• model_pickle_file = ’/path/to/your/ml_model_rf.pkl’

To run the model type the following into the Terminal:

$ python intraday_ml_backtest.py --tickers=AREX

The results are presented in the following section.

29.5 Results

Two intraday backtests are presented here, both of which cover the period 1st January 2013

to 11th March 2014, which is a little over a year. The first test trains a Linear Discriminant

Analyser with default Scikit-Learn settings, while the second trains a Random Forest classifier

ensemble model with a maximum tree depth equal to ten. Both models are trained on AREX

data from 8th November 2007 to 31st December 2012.

Both of the backtests use the respective model "out of sample", that is on data which has

not been seen by the classifiers in training. In addition both of the backtests were calculated

net of standard US Interactive Brokers commission. The tests did not include slippage, market

impact or the effect of spread–all of which will likely have a negative effect on the CAGR.

The tearsheet for the Linear Discriminant Analyser strategy is presented in Figure 29.1.

It posts an out-of-sample Sharpe Ratio of 2.02, which is higher than what is often found in

a daily model, as is to be expected with higher frequency models. With a transaction block of

10,000 shares it posts a CAGR of 5.35%, with a maximum daily drawdown of 1.71%. The low

drawdown is a consequence of the very short holding periods of the strategy, which are usually

on the order of minutes. The equity curve is broadly rising although there is a period where the

strategy remains underwater for three months at the end of 2013.

The tearsheet for the Random Forest strategy is presented in Figure 29.2.

It posts an out-of-sample Sharpe Ratio of 3.02, on a CAGR of 10.63%. Note that calculating

a CAGR on approximately one year of data is misleading, since it will almost be equal to the

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

Saved successfully!

Ooh no, something went wrong!