Vous êtes sur la page 1sur 5

Strategy Learner

Anthony Singhavong
CS7646 Spring 2018
asinghavong@gatech.edu

1 Introduction

This project details the usage of a Random Decision Tree as a classifier to inform trades on the
JPMorgan Chase Co. stock from January 1, 2008 to December 31 2009.

2 Methodology

Decision trees are often used for both regression and classification problems. The main difference
between the two is that regression returns a continous output (e.g. The predicted value of a stock
at a later date) whereas a classification returns a discrete prediction (e.g. "BUY" or "SELL"). In
the case of a random decision tree, the problem space is divded by some random seed value of the
given training data. For this particular problem, we want to classify when a particular stock (JPM),
should be bought, when it should be sold, and when to do nothing. In order to facilitate the training
of our random classification model, we need to define the technical indicators that will help inform
the model when to take action on the stock. This paper will explore the use of three indicators that
are hypothesized to be strong signals when performing trades.

2.1 Indicators

Bollinger Bands are an effective signal to determine when a stock should be bought or sold. Par-
ticularly, observing the price of a stock re-entering back into the bands is often a strong signal to
buy or sell. The Exponential Moving Average was designed to smooth out price fluctuations and
to better visualize trends over a window of time. It is advantageous to the Simple Moving Average
because it responds more rapidly to volatility. The index fund known as SPY attempts to model the
overall trends of the market through a collection of 500 large-and mid-cap U.S. stocks. Together,
these technical indicators make up a robust strategy that generate strong returns.

2.2 Training

In order to utilize the aforementioned indicators, it’s important to first cleanse the data of any
undefined values (i.e. NaN) and normalize the data prior to training a decision tree. Normalising the
indicators upon calculation is an important step to maintain the same scale for all indicators. This
is particularly useful for both calculations and visualization. Once normalized, training data can be
made available by calculating the N day change in price. Where N is a parameter that represents how
many days of trade to use as the basis of the delta calculation. Each price delta is then compared to a
buy and sell threshold which are also adjustable parameters. To find a good threshold, finding the
most occured positive/negative values across some number of runs should be a good base to tune
from. Once found, the delta values will be compared to the tunable high and low constants and will
be put into the buy bucket if it’s greater than the high constant (i.e. YBUY) and in the sell bucket if
less than the low constant (i.e. YSELL). Once populated, the training data is then utilized by the tree
classifier. Upon completion of the training step, the decision tree should return classification values
when given stock prices.
3 Experiment 1
Due to the nature of the random decision tree, results vary greatly per each epoch. Because of this,
it’s difficult to track progress over N runs. When comparing portfolio statistics to a ManualStrategy
that employs the same indicators, it’s important to keep track of the randomness that occurs to ensure
that the portfolio value of each epoch far exceeds that of the rule based strategy.
To methodically measure each run of the experiment, it’s best to keep as many variables constant
when tunning the highly parameterized random decision tree. An example of this would be to change
the buy/sell thresholds that were previous mentioned in training. Upon changing those parameters,
run the classification learner N times, then average out the portfolio statistics. Despite keeping
these parameters fairly constant, the random decision tree showed too much variance per run to
reliably trade. The initial assumption being that one tree would suffice as the learning model though
perhaps an ensemble of random trees (also known as a random forest) is more fitting for this problem.
Later in the expirement, a Random Forest classifier was introduced to aid in reducing variance and
overfitting the training data. Performing the same modifications, results began to show less variance
and improved portfolio statistics.

3.1 Tunable Parameters

YBUY is the threshold that indicates when to buy a stock. In particular, the threshold is compared to
the N day change in price. Where the change in price is defined as:

Delta = (price[t+N]/price[t]) - 1.0

Similarly, YSELL is the corresponding sell threshold that indicates when to sell the JPM stock. From
observation across 20 epochs, YBUY and YSELL seemed to return the best results when the thresholds
were 0.002 and -0.002 respectively. To observe data, the variable N tracks the range of datapoints to
be used as the numerator in the return calculation. By increasing N, we take into consideration more
days in the numerator of the above equation versus less days. 14 days seemed return good results
versus numbers less than 14. When increasing N above 14, the returns were not as good. The other
parameters that wree available for tunning were the leaf size of the trees and subsequently the number
of bags allowed for the random forest method. The strategy traded in higher volume when the leaf
size was as small as possible (i.e. 5) and the number of trades decreased as the leaf size increased (i.e.
21). At a certain point, the StrategyLearner stopped trading (i.e. 37). The strategy did well when the
leaf size was set to 5. The opposite was true with BagLearner; the higher the number of bags, the
better the results. Though when increasing bags, time to query also increases since we’d iterate over
more learners to get the mode of all the results. At the same time, by reducing the number of bags to
a small number, we risk the chance of overfitting to our training data. The best cumulative returns
came from setting number of bags to 15.

4 Experiment 2
Impact is the effect that one trade has on the overall market. For the purpose of this report, market
impact is considered a penalty that manifests as a deduction from the total cash balance. Particuarly,
when a purchase or sale is made, impact should be included when calculating total returns. As impact
increases, the portfolio value of the trader will go down. To further illustrate the effect of impact,
Table 3 averages common portfolio statistics (over 20 epochs) such as cumulative return, average

Table 1: Below are common portfolio statistics that further illustrate the differences of the three
strategies. StrategyLearner beats both Benchmark and ManualStrategy in every category.

StrategyLearner versus Manual Strategy versus Benchmark (in-sample)


Strategy Cumulative return Standard Deviation of Daily Returns Mean of Daily Returns
StrategyLearner 0.6172 0.0102655922264 0.000712135256384
ManualStrategy 0.3494 0.0207079382531 0.00062494732119
Benchmark 0.0123 0.0141346583486 0.000116208281218

2
Figure 1: The in-sample comparison of a Benchmark Strategy (i.e. Buy and Hold) versus a Manual
Strategy (using the same indicators mentioned above) and the StrategyLearner (i.e. Random Tree
Learner). As made apparent, the StrategyLearner exceeds the performance of the other two strategies.

daily return, and the last portfolio value. Both Figure 3 and Table 3 provides further evidence that as
impact increases, the overall portfolio value of the holdings decrease.

Table 2: Below are common portfolio statistics that were averaged across 20 epochs with a single
tree versus a random forest. The best tree results came from setting leaf size to 5 and the best random
forest results came from setting number of bags to 15.

RandomTree Averages versus RandomForest Averages (in-sample)


Strategy Cumulative return Standard Deviation of Daily Returns Last Portfolio Value
RandomForest 1.07176 0.00869236341 207176
RandomTree 0.8601 0.00933487196 186010

3
Figure 2: When comparing Figure 1 to Figure 2, it’s evident that bagging improves portfolio values
by a larger margin than a single random tree.

Figure 3: Portfolio values decreasing when increasing impact by 0.1, 0.2, and 0.3 respectively.

4
Table 3:
StrategyLearner impact 0.1, 0.2, and 0.3 (in-sample)
Impact Cumulative return Daily Returns Last Portfolio Value
0.1 -1.57408505195 -0.00213874902941 -55200.0
0.2 -4.17786492752 0.00236172314454 -293336.0
0.3 -4.17786492752 0.00236172314454 -665296.0

References
[1] Adele Cutler, Guohua Zhao. (Jan 2001) Perfect Random Tree Ensembles,
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.232.2940rep=rep1type=pdf
[2] John Bollinger. (Jan 1992) Using Bollinger Bands by John Bollinger, Stocks Commodities V.
10:2, pp. 47-51.
[3] J.R. Quinlan. (June 1986) Induction of Decision Trees, MACH. LEARN.

Vous aimerez peut-être aussi