13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

439

#model = LinearDiscriminantAnalysis()

#model = BaggingClassifier(

# base_estimator=DecisionTreeClassifier(),

# n_estimators=n_estimators,

# random_state=random_state,

# n_jobs=n_jobs

#)

#model = GradientBoostingClassifier(

# n_estimators=n_estimators,

# random_state=random_state

#)

model = RandomForestClassifier(

n_estimators=n_estimators,

n_jobs=n_jobs,

random_state=random_state,

max_depth=10

)

model.fit(X_train, y_train)

#model.fit(X, y)

print("Outputting metrics...")

print("Hit-Rate: %s" % model.score(X_test, y_test))

print("%s\n" % confusion_matrix(model.predict(X_test), y_test))

print("Pickling model...")

joblib.dump(model, ’/path/to/your/ml_model_rf.pkl’)

# intraday_ml_strategy.py

import numpy as np

import pandas as pd

from sklearn.externals import joblib

from qstrader.price_parser import PriceParser

from qstrader.event import (SignalEvent, EventType)

from qstrader.strategy.base import AbstractStrategy

class IntradayMachineLearningPredictionStrategy(AbstractStrategy):

"""

Requires:

tickers - The list of ticker symbols

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

Saved successfully!

Ooh no, something went wrong!