Stock Prediction Report
Stock Prediction Report
Abstract stock price index movement. ANN has its own way to learn
patterns. ANN emulates functioning of our brain to learn
A good approach to predict future price of a
by creating network of neurons. This study focuses on a
stock, based on its past price and other factors
modification of ANN, a Long Short-Term Memory Neural
was investigated. In this paper we try to predict
Network, which is an optimization of RNNs. Here we use
whether the price of a stock will go up or down
the LSTMs(Hochreiter & Schmidhuber, 1997) in a classi-
on the next day, based on a classification model
fication approach, in order to predict the next day, if the
that we built, using LSTMs from keras library.
stock’s price will be up or down.
our data through the features dimension of the LSTM cell, Cadima, 2016). PCA is a statistical procedure that uses
then through the timestep dimension. Another model we an orthogonal transformation to convert a set of observa-
built was making the LSTM network stateful - with mem- tions of possibly correlated variables into a set of values
ory between the batches of data we passed, making it learn of linearly uncorrelated variables called principal compo-
from every sequence instead of every epoch. Afterwards, nents. This transformation is defined in such a way that
we applied dropout of 0.2 to the model that gave the best the first principal component has the largest possible vari-
results. That was done in order to avoid any overfitting of ance (that is, accounts for as much of the variability in the
our algorithm to our training set, trying to make it gener- data as possible), and each succeeding component in turn
alize better to unseen data. All these models were built in has the highest variance possible under the constraint that
order to fully capture the nature of our problem, trying to it is orthogonal to the preceding components. The resulting
see which algorithm would fit best as a solution. vectors (each being a linear combination of the variables
and containing n observations) are an uncorrelated orthog-
The way we evaluated our model was through a custom
onal basis set. From this analysis we resulted to 5 variables,
metric, named gain. While classic metrics, like mean
which try to capture the most information from our data and
squared error, mean absolute error etc, can be used to eval-
we followed the same procedure, to build the new models,
uate how close is our prediction to the actual price of the
as before.
stock, the problem itself suggests that we should see if the
model is gaining money or not. With that in our mind, if However, in the results of this process, it can be noticed,
we predict that the stock will move to the same direction that even though it wasn’t possible to predict the stock
as the actual move, then we won the absolute value of the price, the predictions were following correctly the direc-
subtraction of the closing price from the opening price. In tion the price was going. For this reason , we transformed
the same way we lost money if we predict the opposite di- the whole problem to a new one. Instead of predicting the
rection from the markets. price directly, we will try now to predict the direction of the
price where the price is heading, making it a classification
Afterwards, we built stacked LSTM models, trying to take
problem.We transform our data to binary, 0 if the price fell
advantage of the memory the LSTM cells provide to a net-
that day, 1 if the price went up. That way the information
work. The architecture is composed from two layers, one
our models need to process is much simpler and therefore,
with 50 neurons followed by one with 30. We followed the
much easier to learn.
same principle as before while building our models.
References
Dey, Shubharthi, Kumar, Yash, Saha, Snehanshu, and
Basak, Suryoday. Forecasting to classification: Predict-
ing the direction of stock market price using xtreme gra-
dient boosting, 10 2016.
Hochreiter, Seep and Schmidhuber, Jurgen. Long short-
term memory. NEURAL COMPUTATION, 9(8):1735–
1780, 1997.
Jolliffe, Ian T. and Cadima, Jorge. Principal component
analysis: a review and recent developments. Philosoph-
ical Transactions of the Royal Society A: Mathematical,
Physical and Engineering Sciences, 374(2065), 04 2016.
Wei Bao, Jun Yue, Yulei Rao. A deep learning framework
for financial time series using stacked autoencoders and
long-short term memory. PLOS ONE, 12(7):1–24, 07
2017.