0% found this document useful (0 votes)
22 views14 pages

Improving S&P Stock Prediction With Time Series Stock Similarity

Uploaded by

mohitbgupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views14 pages

Improving S&P Stock Prediction With Time Series Stock Similarity

Uploaded by

mohitbgupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Improving S&P stock prediction with time series stock similarity

Lior Sidi
Department of Software and Information System Engineering
Ben-Gurion University of the Negev
Israel
liorsidisc@[Link]

ABSTRACT improve a model performance" and "which similarity configuration


Stock market prediction with forecasting algorithms is a popular improves the model the most?"
topic these days where most of the forecasting algorithms train only From the extensive literature overview we applied, We believe
arXiv:2002.05784v1 [[Link]] 8 Feb 2020

on data collected on a particular stock. In this paper, we enriched that we are the first to evaluate how similar stocks enchantments
the stock data with related stocks just as a professional trader would can improve the prediction of a stock price. We prepared a back-
have done to improve the stock prediction models. We tested five testing framework to train and optimize prediction models with
different similarities functions and found co-integration similarity different time series processing, segmentation, and modeling. In the
to have the best improvement on the prediction model. We evaluate Methods chapter, we describe the back-testing pipeline and explain
the models on seven S&P stocks from various industries over five the different similarity functions we apply for finding the most
years period. The prediction model we trained on similar stocks similar stocks. In the Experiment setup chapter, we explain how
had significantly better results with 0.55 mean accuracy, and 19.782 we optimize and evaluate the back-testing process on S&P stocks.
profit compare to the state of the art model with an accuracy of Finally, in the experiment results chapter, we compare between
0.52 and profit of 6.6. models that trained on similar stocks with models that trained
only on the target stock or random stocks. The results show a
KEYWORDS clear advantage of models trained on similar stocks with a short
horizon period (the next day) with a mean profit of 19.87 and a
ACM proceedings, Time series similarity, Stock predictions
mean accuracy of 0.55.
ACM Reference Format:
Lior Sidi. 2020. Improving S&P stock prediction with time series stock
2 RELATED WORK
similarity. In Proceedings of . ACM, New York, NY, USA, Article 4, 14 pages.
[Link] In this research, we aim to improve stock prediction with a hybrid
approach that combines stock similarity and classification. This
section starts with an overview of the stock data representation
1 INTRODUCTION and evaluation. We review different appliances of stock similarities
Prediction of stock price or any financial equity is well-investigated and clustering techniques.
subject by many researchers [10], traders, and hedge funds. In
an entire algotrading framework, the stock prediction component
collects information from different sources, such as market trading
2.1 Stock time series overview
and news. The components’ goal is to feed the strategy component Cavalcante et al. describes a two parts framework for financial
with feed on the following price values. The strategy component trading forecasting; the first part deals with conventional forecast-
is responsible for digesting the information regarding the current ing aspects such as data preparation, algorithm choosing, model
trader position, risk parameters, losses, and the price prediction to training, and accuracy evaluation. The second part is responsible
set actions for buying or selling particular finance equity. for financial forecasting aspects such as trading strategy and then
Similarity analysis on time series data in the finance domain is profit evaluation.
used widely to cluster different equities into domains for manual
exploration [20] [1] but also to identify correlated stocks for trading 2.1.1 Stock time series data
strategy [2] and for stock recommendation [17]. . A standard financial data usually consist of aggregated data of the
In this research, we investigate if a prediction model improves stock price for a certain period. The aggregations are usually high
by adding similar stock during training and in prediction. Our two price, low price, opening price, closing price, trade volume, trading
main research questions are "is the enhancement of similar stock amount. Many papers also extract known technical indicators to
identify trends and momentum in the stock price [21]. Table 1 cover
Permission to make digital or hard copies of all or part of this work for personal or
the most important technical indicators.
classroom use is granted without fee provided that copies are not made or distributed A critical aspect in the data preparation is the prediction period,
for profit or commercial advantage and that copies bear this notice and the full citation a short horizon period such as one day, one week, and one month
on the first page. Copyrights for components of this work owned by others than ACM
must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, is more suitable for financial prediction with technical indicators
to post on servers or to redistribute to lists, requires prior specific permission and/or a [9].
fee. Request permissions from permissions@[Link].
,
2.1.2 Segmentation
© Association for Computing Machinery.
. Time series representation and segmentation are a major part of
, L. Sidi

Table 1: Technical indicators for stock time series

Technical indicator description


relative strength index (RSI) holds the magnitude of recent
gains and losses over a specified
time period
rate of change (ROC) estimating the speed of change
in a price
moving average convergence accumulating the relationship
/ divergence (MACD) between two moving averages of prices
Sharpe ratio calculating the risk of a certain
period by subtracting the profits
with the standard deviation

many stock time-series tasks. The goal is to reduce the dimensional- clustering to extract subsequences per time series such as sliding
ity and complexity of the data and enable identification of technical window. Aghabozorgi et al. also adds time point clustering to cluster
patterns, clustering, or prediction [6]. the points values in the time series.
The similarity and the clustering are highly affected by the seg-
2.1.3 Prediction
mentation and representation method applied, Keogh and Kasetty
. Forecasting proven to be well-suited for financial data modeling,
boldly claim that the clustering of time-series subsequences with
sophisticated machine learning (ML) models such as artificial neural
time window is meaningless unless only the significant motifs are
networks, SVM and genetic programming showed state of the art
considered.
results in the field.[12] [9] [21].
In the rest of this section, we will explore the recent appliances
Finnie et al. surveyed different techniques for time series fore-
of clustering on financial time series data per type of similarity
cast on financial data; they differentiate between machine learning
distances.
technique, forecasting period, and the input variables. They summa-
rized with the noticed that the Artificial Neural Networks (ANNs) 2.2.1 Numeric distance
is a dominant machine learning technique. Nevertheless, Gerlein . Aghabozorgi and Teh used different clustering methods to cate-
et al. demonstrates that also simple ML models such as decision gorize companies based on their stock data similarity; they used
tree, logistic regression, nearest neighbor, and Naive Bayes showed basic Euclidean distance to find similarity in time points in stock
good results as well. Therefore using simple forecast algorithms can data. Because Euclidean distance is not capable of identifying trends
be a good benchmark to evaluate different representation methods shapeliness they used Dynamic Time Warping (DTW) distance to
and enrichments. find similarity in the stock data shape, DTW first introduced in the
1960s and still show similar results to more advance methods [8].
2.1.4 Evaluation
In general, DTW deals with unequal length and solves the local
. Evaluating a stock time series predictor involves two types of
shift problem in the time series to find similar shapes between time
metrics, the first is a conventional evaluation of the predictor with
series in different time phase axis.
the accuracy measures such as mean absolute error, mean absolute
Wang et al. applied DTW on foreign exchange (FX) market and
percentage error, and root mean square error. The second is money
use minimal spanning tree (MST) and hierarchical tree (HT) to
evaluation, which evaluates the profit for a certain trading strategy
cluster different currencies together. They strongly claimed that the
[6].
usage of the Pearson correlation coefficient (PCC) is not suitable
One of the most popular strategies for evaluation is a Buy &
for FX time series data because it is not robust to outliers and must
Hold strategy [10]. The strategy simply buys a stock that predicted
have homogeneous, synchronous, and equal length samples.
to go up and sell it otherwise. Still, any strategy shall apply a risk
Jeon et al. searched for similar patterns in historical stock data
control mechanism such as stop loss[7].
with DTW and stepwise regression feature selection to improve
predictions. The selected data set is used to train an artificial neu-
2.2 Similarity and clustering on stock time ral network (ANN). They evaluate their predictor with root mean
series square error (RMSE) and new evaluation that represent the target
Clustering in time series stock data serves many goals such as port- value with SAX and apply Jaro-Winkler similarity.
folios balancing, patterns discovery, risk reduction, finding similar Caiado and Crato used generalize autoregressive conditional het-
companies, prediction, and recommendation. Applying a cluster- eroskedasticity (GARCH) models to estimate the distance between
ing model requires three key components: clustering algorithm, stock time series volatilities. They used hierarchical clustering and
similarity definition, and evaluation method [23]. multidimensional scaling technique to differentiate geographical
Keogh and Kasetty address two types of clustering time series, stock markets. GARCH model assumes that the conditional vari-
the first is whole time-series clustering to cluster set of individ- ance is dependent on a past linear volatility model; the GARCH
ual time series by their similarity, and the second is subsequence model is lean with parameters and provides a good representation
Improving S&P stock prediction with time series stock similarity ,

of volatility for a variety of processes. Their distance formulation


considers the time series GARCH measurement combined with the
sum of the series covariance-vector-estimation.

2.2.2 Symbolic distance


. Soon and Lee compared the numeric and symbolic representation
for stock data similarity. For numeric representation, they use the
original data with Euclidean distance, and for symbolic represen-
Figure 1: Workflow pipeline stages
tation, they used UP, DOWN, and SAME symbols with a number
of matching symbols as distance. They found that opening, clos-
ing, highest, and lowest prices of the stock are able to produce 3.1 Folds preparation
consistent results in similarity and demonstrate that under the rep- In this stage, the process split the data to n folds; the split separates
resentation and distances described above, the numeric distance the data to n equal width folds. Each fold contains a train data, a
was more consistent then symbolic distance. fold before the split, and a test data, a fold after the split.
Aghabozorgi and Teh used Symbolic ApproXimation Aggre- in order to keep the model relevant to the test data, We select
gation (SAX) representation for dimensionality reduction, SAX only half of the test data near a split point,
method discrete stock continues representation with symbols per
static data segment; they used a k-Modes algorithm that suites 3.2 Data processing
categorical data. For the SAX distance measurement, they develop
APXDIST instead of MINDIST distance for symbolic distance [16] The processing stage is responsible for manipulating, modeling, and
because MINDIST considers the neighbor symbols as zero, APXDIST feature extraction of the stock data. The actions performed by this
distance also considering the global minimum and maximum sym- component are normalization (standardization), financial feature
bols in the sequence. extraction (MACD, RSI, Price rate of change, volume, open-close
Branco combined SAX and Shape Description Alphabet (SDA) difference, and trading volume), data segmentation (SAX or PCA)
representation with a genetic algorithm to generate buy and sell and data modeling (time points or time windows).
signals. SDA representation calculates the amplitude difference The component is also responsible for training the normaliza-
between two adjacent points and represents it as a symbol. SAX tion and segmentation processes on each train fold data and apply
is not capable of identifying the difference between segments that it to the relevant test fold. Furthermore, this stage differentiates
have the same average value, whereas the SDA identifies trends and between univariate modeling with only one value and multivariate
relation between adjacent points. For SAX, they use MINDIST, and modeling with all the financial features. We apply time window
for SDA, they use simple numeric subtraction between the relative modeling only for the univariate to reduce the size of dimensional-
representations. ity and eliminate overfitting. We also did not apply normalization
Tamura et al. conducted time series classification based on SAX on some financial features because their original raw values already
representation with Moving average convergence divergence (MACD) normalized between ranges.
Histogram and applied one nearest neighbor (1NN) with extended 3.2.1 Standard normalization. The standardization phase nor-
Levenshtein distance that suites strings with SAX representation. malizes the financial data. The normalization is possible in the stock
MACD captures the velocity and the acceleration of the time series prediction scenario because of the values of random behavior. The
and is used widely in the financial domain, MACD calculates the min-max normalization is not advised because the stock values are
difference between two exponential moving averages (EMA) with not limited to a certain price range, and the prices can change dra-
different window size. Tamura et al. used SAX to represent the matically. Therefore, we normalize the stock prices with elementary
original values and MACD values, and then they combined the standardization function:
values in an alternates order. x − mean(X )
z=
std(X )
3.2.2 Data modeling. Time series data modeling can take place
3 METHODS in various ways; each modeling represents the prediction record
We developed a workflow that prepares the stocks data and manage differently and exposes different information regarding the instance
the back-testing process, the workflow’s generic implementation and its context.
allows the evaluation of different methods configurations. • Timepoint - Addresses each time point separately without
In this chapter we will describe the workflow’s stages and meth- data of previous time points. Timepoint representation al-
ods we apply in this research, the workflow code is written in lows adding complexity like feature extraction or combining
Python and is available on GitHub: [Link] similar stocks values at the same timepoint.
StockSimilarity. The workflow pipeline has four stages: Prepare Nevertheless, timepoint approach has several limitations,
fold data, process data, similar stocks enhancement, and stock pre- the first is a significant reduction of data when joining simi-
diction. lar stocks on the same time point due to missing data, and
the second limitation is the lack of contextual information
, L. Sidi

Figure 2: The different configurations for stock similarity

from recent points. Therefore, adding financial features that 3.3 Similar stocks enhancement
capture previous information such as exponential windows The stock enhancement component applies the different functions
might be more beneficial. for measuring the stock similarity. In figure 2, we describe the
• Time Window - Represents each instance as a window necessary configurations, the value for calculating the similarity,
of adjacent time points, this modeling allows the model to the fix the length function, the similarity functions, and lastly, the
find a relation between adjacent points. Still, this modeling k top stocks are chosen.
enlarges the instance and can harm the ability to add more As explained in the previous data modeling section, The combi-
features and stocks. nation of similar stocks depends on the data modeling approach.
In our implementation, we extract windows for each stock
separately and do not join their values as applied in the time 3.3.1 length fixing. Each instance (stock or equity) may miss
point modeling. On the one hand, the similar stocks data different time points due to system error, vacation days, or stock
is not used in prediction, only in training. But on the other splitting.
hand, the training data increases dramatically with similar When computing the distances between time-series, it’s impor-
stocks and improves the models. tant to correlate them to have the same length size, in order to do
this, we implemented and examined the following fixing methods:
3.2.3 Data segmentation. • Time join - a basic correlation between stocks, if one stock
is missing a time point while the other is not the time point
• Principals component analysis (PCA) - creates a smaller is eliminated (equivalent to inner join in SQL) this fixing is
representation of the dataset while maintaining its variance the most popular but may reduce the data substantially.
using eigenvector decomposition on the data covariance. • Delayed time join - stock values are pushed t times points
The PCA produces principal components (PCs), which are a backward (delay), this correlation meant to identify if one
linear combination of different features that acts as a new stock indicated future behavior of the other one.
attribute. PCA is a common tool for data exploration and • Padding - basic padding fixing technique that adds a dupli-
allows good reasoning of the data variance. cate value at the beginning of the shorter series.
In our experiment, we set the PCA to produce 3 PCs from • Perceptually important points (PIP) - select the most
the entire data set to act as new attributes. important points in a series with the following steps: the
• Symbolic ApproXimation Aggregation (SAX) - A dimen- first and the last points are set as PIP’s. Then, the third PIP
sionality reduction technique, allows distance measures to will be the point with the maximum distance to the first two
be defined on the symbolic approach that lower bounds eu- PIP’s. The fourth PIP will be the point with the maximum
clidean distance [15]. distance between two adjacent PIPS, the algorithm finish
SAX involves performing two stages on the data: first, it when achieving a predefined number of points.
transforms the original time-series into the appropriate piece- In our experiment, We use PIP on each stock to find impor-
wise aggregate approximation (PAA) representation. tant time points (10 percent of original length), and then we
The PAA representation divides the series to parts (according combined both PIPs and correlated the stock time points.
to the given output length) and calculates each interval’s
mean value. Later it converts the PAA data into a string after 3.3.2 Similarity functions.
normalization according to the given alphabet size. In our • Euclidean distance - A common indicator that measures
experiment, we use SAX representation while keeping the the dissimilarity between time series comparing the obser-
same word size as the origin. vations at the exact same time. The Euclidean distance is a
Improving S&P stock prediction with time series stock similarity ,

square root of the sum of the squared differences of each 3.4 Stock prediction
pair of corresponding points. The prediction component trains a regressor or a classifier model
The main limitation of this measure is its inability to identify with the relevant algorithm. The model goal is to predict if the stock
shifting and trends in the data. value will increase or decrease to a certain horizon.
• Pearson correlation coefficient - A known measure of Figure 4 explains how the system train and apply the classifier
the linear correlation between two vectors, the coefficient is or the regressor model. For the classifiers, the system train on the
calculated by dividing the two series covariance with theirs two classes in the traditional way. The regressors are trained to
standard deviation product, the correlation value range is predict the next price value, but in prediction, the predicted value
between -1 and 1 for negative and positive correlation. is a binary value for an increase or decrease in the price value.
Pearson has two major limitations regarding stock price In our experiment, we choose to evaluate two ensemble algo-
correlation. The first is that it assumes stationary behavior, rithms that showed good results in the stock prediction domain:
and the second is that it cannot deal with non-linear behavior Random Forest and Gradient Boosting Tree. Both models have a
between series. classification and regression implementation in Scikit-learn (Python
• Dynamic Time Warping (DTW) - A template matching library).
algorithm in pattern recognition, DTW, which can align
• Random Forest - Train t decision trees on different features
sequences that vary in time or speed.
and, in prediction, apply a majority voting on the results from
DTW is an old technique but still very relevant in financial
all trees.
similarity. In our experiment, we used Python’s implementa-
• gradient boosting trees - Train a chain of decision trees
tion of DTW, based on Euclidean distance.
where each tree tries to predict the error of the previous
• MINDIST - A distance computation of SAX representation,
decision tree, the model has a learning rate for summing the
the MINDIST formula defined by [15] and explained in fig-
values from the tree chains.
ure 3. The main limitation of MINDIST in stock price series,
as mentioned by Liu and Shao, is that it does not address
adjacent change in values. To fix this, we tested MINDIST
(and all other similarity functions as well) on the price rate
of change (PROC) to identify a high increment of adjacent
change.
• Co-integration - A statistical feature between multiple non-
stationary time series, co-integration checks if there is a
parameter that it’s multiplication with one of the time series
resolve with a constant spread between the non-stationary
series.
Stock prices are not necessarily stationary because their
mean and standard deviation may change over time. Co- Figure 4: The training and appliance pipeline for classifiers
integration is used widely to compare similarity between and regressors models
stocks and may state that there is some relation between
them [3].
For testing series co-integration, we use the co-integration
Python implementation "stattools" library that test for co- 4 EXPERIMENT SETUP
integration behavior with Engle-Granger two-step co-integration In order to evaluate if stocks similarity improves a baseline model,
test. We used the test P-value as a similarity measurement we conduct two-step experiments (back-testing) to evaluate differ-
between the two series, a low p-value of the test means that ent types of configurations. The first experiment goal is to come
the series are co-integrates. up with a processing pipeline and a baseline model. The second
experiment is to evaluate how different stock similarity functions
influence the baseline model. In figure 5, we mapped the different
configuration parameters the back-testing process will evaluate.
Our dataset contains daily historical data for all the S&P (Stan-
dard & Poor) 500 stock market index companies from 2012 to 2017.
The features given are date, open price, closing price, highest price,
lowest price, volume, and the short name of the stock. The S&P is
an American stock index of the largest companies listed in NYSE or
Figure 3: MINDIST Equation - n is the number of window NASDAQ, maintained by S&P Dow Jones Indices. It covers about
points, w the number of segments, Gi the value number i 80 percent of the American equity market by capitalization.
of series G transformed by the SAX method, and the Hi the We apply the evaluation process on stocks from different indus-
value number i of series H transformed by the SAX method. tries: Consumer (Disney - DIS, Coca Cola KO), Health (Johnson and
Johnson - JNJ), Industrial (General electric - GE , 3M - MMM), In-
formation technology (Google - GOOGL) and Financial (JP Morgan
, L. Sidi

Figure 5: A configuration tree of all the setup to be optimize and evaluate in workflow pipeline

- JPM). The validation folds are set to five and prepared for each length fixing functions, size of k similar stocks (10, 25, 50), similar
stock separately. value to compare (Close price or price rate of change).
The experiment will compare the best-enhanced model with the
best non-enhanced model from the first experiment and with a
4.1 Experiment 1 - processing model model that randomly choose stocks for enhancement. The second
evaluation comparison goal is to evaluate if the model’s improvement is due to
The experiment’s goal is to evaluate the basic processing and pre- similarity enhancement and not due to general stock enrichment.
diction model parameters to set a baseline model and processing
configurations. The baseline settings are set in the next experi- 5 RESULTS
ments to evaluate the similarity enhancement, rather them model
The evaluation metrics are accuracy score and F1 score; we calculate
and processing tuning.
each metric per class (increase/decrease) and average it to one score.
For processing, the experiment evaluates features (univariate or
To evaluate the model profit, we implement a simple Buy & Hold
multivariate), segmentation methods (SAX, PCA, or raw values),
algorithm that applies a long or short position regarding the model
temporal modeling (time points, or windows size 5 or 10). For stock
price prediction. We also measure the risk of the strategy with the
prediction, the experiment evaluates the following configurations:
Sharp ratio.
prediction value (close price or price rate of change), horizon (next
For visualizing the results of the experiment, we use Tableau
day, next three days or next week), and weighing instances per
software to export graphs and tables based on CSV results from the
stock (applied only for the Euclidean similarity models).
pipeline Python implementation.
To identify if stock similarity enhancements improve a baseline
model we do not need to focus on improving the models with
endless parameters tuning, but set recommended parameters to 5.1 Experiment 1 - processing model
reduce the complexity of the experiments, the models recommended evaluation
configuration: Random forest with 100 trees and Gradient boosting The first stage of experiment one is to evaluate which processing
with 0.02 learning rate. The first experiment also applies two basic configuration will resolve with the best accuracy, F1 score, profit,
stock similarity configurations: Euclidean similarity function on and low risk.
the price value with ten similar stock compared to no enrichment
of similar stocks. 5.1.1 Processing configuration evaluation
. In figure 5, we present the different configuration and metrics of
the data processing configuration, and in figure 7, we emphasize the
4.2 Experiment 2 - Enhancement similarities
profit difference per configuration. The best overall performance
evaluation configurations are univariate modeling with SAX transformation.
The second experiment evaluates the improvement each similarity Furthermore, SAX transformation showed the best results with all
function parameters have on the baseline models defined in the other configurations. Each metric in the figure is the mean of 1680
first experiment. examples (7 different stocks, five-folds, three different horizons,
For similarity parameters, the experiment evaluates similarity two predictions values, four types of models and two types of K
functions (co-integration, DTW, Euclidean, Pearson, and SAX), top stocks)
Improving S&P stock prediction with time series stock similarity ,

5.1.2 Prediction models evaluation 5.2 Experiment 2 - Similarity enhancement


. In the next step of the experiment, we evaluate the parameters of evaluation
the prediction, from the results in figure 8 we can observe that the
The second experiment train the models with the processing sug-
overall performance for predicting rate of change price (PROC) is
gested from the first experiment and apply the similarity enhance-
higher than predicting the closing price (the columns of price rate
ment configurations as follows: similarity function, similarity value,
of change is all green with only positive mean profits).
top k stock to choose and the stock length fixing.
The classification models have good accuracy results, but their
In this section, we present the evaluation figures only on profit.
standard deviation is high and results with negative profit along
We found the accuracy and profit are correlated with each other.
with high risk. The performance of the next day prediction horizon
The full results are in appendix A.
is higher than other horizons. For model performance, we witness
an interesting behavior between the regressors and the classifiers. 5.2.1 Similarity functions evaluation
The classifiers had the best accuracy for predicting the closing . The results from figure 10 map the metrics for top K stock and simi-
price, whereas the regressors failed. However, the classifiers also larity stocks (rows) over the similarity value used for computing the
meet negative mean profit, and the regressors did not, probably similarity. Each cell in the table is a mean of 1680 instances (seven
because of the prediction inconsistency (high standard deviation) stocks, five-folds, three horizons, four models, 4 fixing length tech-
and threshold calibration. From the results, we see a slight but niques). The results present a clear advantage of the co-integration
not significant advantage of the Gradient boosting trees over the and the SAX MINDIST similarities, price rate of change as similarity
Random forest models. value, and selecting the top 50 stock. These combinations lead to a
mean accuracy of 0.53 and a mean profit of more than 9.55 (SAX)
and 9.81 (co-integration). The results already show a significant
improvement from the baseline model presented in figure 9.
In figure 13b, we evaluate the length fixing functions of the best
similarity configuration: the 50 top stocks with high SAX or co-
integration similarity on price rate of change. Time join for fixing
have the best results with a profit of 15.67 (co-integration) and 14.85
(SAX).
In figure 12, we present the final results of these similarities
with the best performing processing and modeling configurations:
a gradient boosting regressor trained on the price rate of change
with SAX transformation and 50 top stocks with co-integration
similarity.

5.2.2 Random stock enhancement comparison


. Finally, we compare the results from the enhanced model with
models that we enhanced with random 50 and 100 stocks. As de-
scribed in 12, the random enhanced model also had significantly
Figure 6: Experiment 1 processing parameters results - trans- better results than the baseline model presented in the first exper-
formation function, features and temporal modeling. (rows iment. The random models improve as the horizon rise, and the
- configuration , columns - metrics and color - profit scale) number of random stocks is selected, this phenomena can be ex-
plained by the fact that the S&P stocks are known to have similar
behavior and can contribute the predictions because many investors
and ETFs buy or sell the index stocks all together causing the prices
to behave similarly.
As a part of experiment one, we also evaluate the models that For the horizon of the next day, the co-integration stock simi-
train on top 10 similar stocks calculated with simple Euclidean larity has significantly higher profit from the random 100 stocks
distance alongside models that trained only on the target stock. In with 19.78 and 16.21. On the other hand, the random model is sig-
figure 9, the results point out that the model trained only on the nificantly more profitable in the long horizons. The long horizon
target stock has better results than the model trained on the ten performance is a result of the same phenomena explained above
similar stocks using Euclidean distance. regarding the S&P stocks. Nevertheless, the co-integration based
From this experiment results, we conclude that the best process- model is more accurate in terms of accuracy score and F1 score
ing and prediction parameters for the next experiment will be SAX than the random 100 stocks model with accuracy between 0.542 -
transformation only on the price rate of change value (univariate). 0.55 and an F1 score between 0.448 - 0.459. The random 100 stocks
The price rate of change will also be the prediction value. model had less accurate results with an accuracy score between
We did not witness any significant results for the temporal mod- 0.526 - 0.535 and an F1 score between 0.437 - 0.443 (these detailed
eling and prediction models and horizon prediction configurations; results are in appendix A).
therefore, in the next experiment will apply all these configurations We further investigate the profit behavior of the co-integration
as well. model and the random 100 stocks model in order to understand the
, L. Sidi

model’s profitability behavior. In figure 11 we plot the profit value


over time for each stock (x-axis) in each of the five folds evaluated
(y-axis), the models predict the next day value and then the simple
buy and hold strategy is applied, the color represents each of the
two models. From the plots, we identify the co-integration model
(orange color) to be more profitable in most stock’s folds except
JPM stock. Figure 9: Experiment 1 basic similarity results - a compar-
ison between a model with top 10 similar stocks with Eu-
clidean distance and a model without similarity enhance-
ment. for predictions parameters: prediction model, Hori-
zon and Value (rows - configuration, columns - metrics and
color - profit scale)

Figure 7: Experiment 1 processing parameters results - mean


profit values per transformation configuration

Figure 10: Experiment 2 similarity configurations - a profit


comparison between similarity configurations

similarity. We compared the enhanced model, the optimized base-


line, and the random similarity model on seven stocks from different
industries in five folds split over five years period.
The enhanced model had better results than the other models in
terms of accuracy and profit. The mean accuracy of the enhanced
model is 0.55 compare the 0.52 and 0.546 of the non-enhanced
and random enhanced models (respectively). In terms of profit, the
Figure 8: Experiment 1 prediction parameters results - pre- enhanced model showed a high mean profit of 19.87 compared to
diction model, Horizon and Value (rows - configuration, 6.66 and 15.02 of the non-enhanced and random enhanced models.
columns - prediction value with metrics and color - profit During the research, we identify two limitations; the first regards
scale) the small data volume of the daily data set because the scope of
daily prices is not enough data to train a well-fitted model. We
believe that applying the pipeline on intra-day data might improve
6 CONCLUSIONS the models because of the data volume that may consist of much
In this paper, we focus on improving prediction models on stock more useful similarities patterns.
data with similar stocks; the process of enhancement is not straight- The second limitation regards the S&P stocks index in general.
forward and requires several data processing phases. We design a The index has two types of limitations; The first is that the index
pipeline for applying back-testing for all processing and prediction was mostly positive after the crisis of 2008; this behavior may affect
configurations. the results in all the models evaluated. The other type is that the
We came up with an optimized enhanced model with the follow- S&P stocks correlate to each other because traders usually buy
ing configurations: data processing of 10 size windows with the the entire S&P index causing all the stocks to increase or decrease
price rate of change SAX transformation. The predictor is a gradient together. This kind of behavior eliminates some of the advantages
boosting regressor with a 0.02 learning rate, and its training set is a similarity measure might have because the stocks are already
compound from the top 50 similar stocks found with co-integration similar. In order to address these limitations, we aim to apply the
Improving S&P stock prediction with time series stock similarity ,

Figure 11: Experiment 2 folds profit per stock - a profit comparison between top 50 stocks from co-integration similarity
(orange) and 100 random stock selection enhancement (Blue) for each stock (x axis) in different folds (y axis)

[2] Saeed Aghabozorgi and Ying Wah Teh. 2014. Stock market co-movement assess-
ment using a three-phase clustering method. Expert Systems with Applications
41, 4 PART 1 (2014), 1301–1314. [Link]
[3] Carol Alexander and Anca Dimitriu. 2003. Equity Indexing , Cointegration and
Stock Price Dispersion : A Regime Switching Approach to Market Efficiency.
ISMA Centre Discussion Papers in Finance 44, 2 (2003), 29.
[4] Tiago Branco. [n. d.]. Pattern analysis in stock markets optimized by genetic
algorithms using modified SAX. ([n. d.]), 1–10.
[5] Jorge Caiado and Nuno Crato. 2007. A GARCH-based method for clustering
of financial time series: International stock markets evidence. Munich Personal
RePec Archive 2074 (2007).
[6] Rodolfo C. Cavalcante, Rodrigo C. Brasileiro, Victor L.F. Souza, Jarley P. Nobrega,
and Adriano L.I. Oliveira. 2016. Computational Intelligence and Financial Markets:
A Survey and Future Directions. Expert Systems with Applications 55 (2016), 194–
211. [Link]
[7] T Chande. 1997. Beyond Technical Analysis. 143 pages. [Link]
com/scholar?hl=en&btnG=Search&q=intitle:Beyond+Technical+Analysis#2
[8] H Ding, G Trajcevski, P Scheuermann, X Wang, and E J Keogh. 2008. Querying
and mining of time series data: experimental comparison of representations
and distance measures. Proc. of the VLDB Endowment 1, 2 (2008), 1542–1552.
Figure 12: Experiment 2 random selection compare - a profit [Link]
comparison between SAX and co-integration similarities on [9] Cain Evans, Konstantinos Pappas, and Fatos Xhafa. 2013. Utilizing artificial
top 50 stocks and random stock selection neural networks and genetic algorithms to build an algo-trading model for intra-
day foreign exchange speculation. Mathematical and Computer Modelling 58, 5-6
(2013), 1249–1266. [Link]
[10] Gavin Finnie, Bjoern Krollner, Bruce Vanstone, and Gavin Finnie. 2010. Financial
time series forecasting with machine learning techniques : A survey. European
pipeline on other investment instruments like crypt-currency and Symposium on Artificial Neural Networks ESANN2010 April (2010). [Link]
commodities (Gold, Oil, silver, etc.). We believe that the similarity [Link]/bruce_vanstone/17
pipeline on other datasets where most of the items do not correlate [11] Eduardo A. Gerlein, Martin McGinnity, Ammar Belatreche, and Sonya Cole-
man. 2016. Evaluating machine learning classification for financial trading:
will have dramatically better results than in this research. An empirical approach. Expert Systems with Applications 54 (2016), 193–207.
For future work, we suggest some improvements. The most [Link]
straightforward is to apply an ensemble similarity model on the [12] Yong Hu, Kang Liu, Xiangzhou Zhang, Lijun Su, E. W.T. Ngai, and Mei Liu. 2015.
Application of evolutionary computation for rule discovery in stock algorithmic
different similarity measurements to combine the advantage of each trading: A literature review. Applied Soft Computing Journal 36 (2015), 534–551.
method. Another improvement is to use deep learning models; we [Link]
[13] Seungwoo Jeon, Bonghee Hong, and Victor Chang. 2017. Pattern graph tracking-
assume that the similarity enhancement will increase the training based stock price prediction using big data. Future Generation Computer Systems
dataset and will improve deep learning models that require much (2017). [Link]
more data for training. [14] Eamonn Keogh and Shruti Kasetty. 2002. On the need for time series data mining
benchmarks. Proceedings of the eighth ACM SIGKDD international conference on
Knowledge discovery and data mining - KDD ’02 (2002), 102. [Link]
REFERENCES 1145/775047.775062
[1] Saeed Aghabozorgi, Ali Seyed Shirkhorshidi, and Teh Ying Wah. 2015. Time- [15] Jessica Lin, Eamonn Keogh, Stefano Lonardi, and Bill Chiu. 2003. A symbolic
series clustering - A decade review. Information Systems 53 (2015), 16–38. https: representation of time series, with implications for streaming algorithms. Pro-
//[Link]/10.1016/[Link].2015.04.007 ceedings of the 8th ACM SIGMOD workshop on Research issues in data mining and
, L. Sidi

knowledge discovery - DMKD ’03 (2003), 2. [Link]


[16] Wei Liu and Liangshan Shao. 2009. Research of SAX in Distance Measuring for
Financial Time Series Data. 70572070 (2009), 935–937.
[17] Binoy B. Nair, P. [Link] Kumar, N. R. Sakthivel, and U. Vipin. 2017. Clustering
stock price time series data to generate stock trading recommendations: An
empirical study. Expert Systems with Applications 70 (2017), 20–36. [Link]
org/10.1016/[Link].2016.11.002
[18] Lay Ki Soon and Sang Ho Lee. 2007. An empirical study of similarity search in
stock data. Conferences in Research and Practice in Information Technology Series
84, Aidm (2007).
[19] Keiichi Tamura, Tatsuhiro Sakai, and Takumi Ichimura. 2016. Time Series Clas-
sification using MACD-Histogram-based SAX and Its Performance Evaluation.
(2016), 2419–2424.
[20] Qiang Tian, Pengjian Shang, and Guochen Feng. 2016. The similarity analysis
of financial stocks based on information clustering. Nonlinear Dynamics 85, 4
(2016), 2635–2652. [Link]
[21] Bruce Vanstone and Gavin Finnie. 2009. An empirical methodology for developing
stockmarket trading systems using artificial neural networks. Expert Systems
with Applications 36, 3 PART 2 (2009), 6668–6680. [Link]
2008.08.019
[22] Gang Jin Wang, Chi Xie, Feng Han, and Bo Sun. 2012. Similarity measure and
topology evolution of foreign exchange markets using dynamic time warping
method: Evidence from minimal spanning tree. Physica A: Statistical Mechanics
and its Applications 391, 16 (2012), 4136–4146. [Link]
2012.03.036
[23] T. Warren Liao. 2005. Clustering of time series data - A survey. Pattern Recognition
38, 11 (2005), 1857–1874. [Link]
Improving S&P stock prediction with time series stock similarity ,

7 APPENDIX A - SIMILARITY CONFIGURATION EVALUATIONS


In this appendix, we collect the full evaluations per similarity configuration; these results address in the experiment results chapter.

(a) Experiment 2 similarity configurations - a full metrics comparison between similarity configurations

(b) Experiment 2 length fixing functions - a profit com-


parison between different fixing functions on top simi-
larity configurations
, L. Sidi

(a) Experiment 2 length fixing functions - a full metrics comparison between different
fixing functions on top similarity configurations

(b) Experiment 2 length fixing functions - a full metrics comparison between different
fixing functions on top similarity configurations

(c) Experiment 2 random selection compare - a full metrics comparison between SAX and co-integration similar-
ities on top 50 stocks and random stock selection
Improving S&P stock prediction with time series stock similarity ,

8 APPENDIX B - STOCK SIMILARITY EXPLORATIONS


In this appendix, we describe the manual exploration we conducted on the similarity results we conducted. In order to reason the similarity
function, we tested if the similarity function can group stocks in the same industry.
In Figure 15 each row is a target stock, the bin graph contains the similar stocks found in a certain rank, and the color represents the
sector count. For example, in Disney target function, the first bin is an all dark blue that represents the consumer sector, the same sector of
the Disney stock. That means all the similarity functions choose the most similar stock from the same sector as Disney; If we continue
with the y-axis, we can see how the target stock sector is dominant in the beginning and then spread, this means that the similarities find a
relationship between the stocks’ behavior and their sector.

Figure 15: Target stock sector spread per rank

In Figure 16, we demonstrate a confusion matrix between the target stock and the sector for the top 10 similar stocks found per similarity
values (horizon) and similarity function (vertical). For example, the Pearson and close proc (Price rate of change) on the coca-cola stock
found that all top 10 similar stocks belong to the same sector as coca-cola, consumer staples. The stocks and sectors arranged in a way that
each stock corresponds to its relevant sector, meaning that if the diagonal is all dark green with ten value, the similarity function found the
stocks similar to its sector’s stocks.
In Figure 16, we describe which stocks found most similar to the target stocks, for example, in the coca-cola stocks, the similarities
functions found Pepsi to be the most similar.
, L. Sidi

Figure 16: Target stock and sector confusion matrix for top 10 stocks per similarity function (vertical) and similarity value
(horizontal)

Figure 17: Coca cola and JP Mrgan Top stocks chosen

You might also like