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.

257

seen whether it is feasible to produce a robust strategy that can be profitable above the higher

frequency transaction costs necessary to carry it out.

18.6 Bibliographic Note

A gentle introduction to tree-based methods can be found in James et al (2013)[59], which covers

the basics of both DTs and their associated ensemble methods.

A more rigourous account, pitched at the late undergraduate/early graduate mathematics/statistics

level can be found in Hastie et al (2009)[51].

Murphy (2012)[71] provides a discussion of Adaptive Basis Function Models, of which DT/-

CART models are a subset. The book covers both the frequentist and Bayesian approach to

these models.

For the practitioner working on "real world" data (such as quants!), Kuhn et al (2013)[67] is

an appropriate text pitched at a simpler level.

18.7 Full Code

# ensemble_prediction.py

import datetime

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import pandas_datareader.data as web

import seaborn as sns

import sklearn

from sklearn.ensemble import (

BaggingRegressor, RandomForestRegressor, AdaBoostRegressor

)

from sklearn.metrics import mean_squared_error

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import scale

from sklearn.tree import DecisionTreeRegressor

def create_lagged_series(symbol, start_date, end_date, lags=3):

"""

This creates a pandas DataFrame that stores

the percentage returns of the adjusted closing

value of a stock obtained from Yahoo Finance,

along with a number of lagged returns from the

prior trading days (lags defaults to 3 days).

Trading volume is also included.

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

Saved successfully!

Ooh no, something went wrong!