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.

435

total return. The Sharpe Ratio is higher than that for LDA as the returns have increased but

the drawdowns have stayed approximately the same. The equity curve also looks more visually

consistent. Despite this, it also remains underwater for the latter three months of 2013 and only

begins to recover at the start of 2014.

29.6 Next Steps

There is a lot of work to be done to turn this into an effective strategy that would be placed in

production.

The first step would be to replicate this model across many tens or hundreds of equities

(depending upon available capital!) as a means of attempting to generate many uncorrelated

"bets" on, say, separate sectors of the market.

In addition a more robust hyperparameter study should be carried out for many of the

classifiers. This will optimise the bias-variance trade-off in the models. To some extent this is

controlled by the maximum depth of the tree in the Random Forest classifier.

Taking this from a backtested system to a consistently working production model will require

accounting for slippage, market impact, average daily volume of shares traded and more realistic

commissions.

Running at minutely frequency is clearly a lot harder than carrying out daily strategies. This

is the "price to pay" for obtaining larger Sharpe ratios and thus strategies that possess improved

statistical significance.

29.7 Full Code

# intraday_ml_model_fit.py

import datetime

import numpy as np

import pandas as pd

import sklearn

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

from sklearn.ensemble import (

BaggingClassifier, RandomForestClassifier, GradientBoostingClassifier

)

from sklearn.externals import joblib

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import train_test_split

from sklearn.tree import DecisionTreeClassifier

def create_up_down_dataframe(

csv_filepath,

lookback_minutes=30,

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

Saved successfully!

Ooh no, something went wrong!