You are on page 1of 3

STOCK MARKET PREDICTION

USING MACHINE LEARNING

Ishita Parmar, Navanshu Aggarwal, Sheirsh Saxena, Ridam Arora, Shikhin Gupta, Himanshu Dhiman
Department of Computer Science and Engineering
National Institute Of Technology, Hamirpur – 177005, INDIA

Abstract-In Stock Market Prediction, we predispose during the time period. The model is then tested on
the future value of financial stocks of a company. the test data. Regression and LSTM models are
The recent trend in the stock market prediction engaged for this conjecture separately. Regression
technologies is the use of machine learning which involves minimizing error and LSTM contributes to
makes prediction on the value of current stock market remembering the data and results for the long run.
indices by training on the their previous values. Finally, we plot graphs for the fluctuation of prices
Factors considered are open, close, low, high and with the dates in case of Regression based model and
volume. Machine learning itself employs different between actual and predicted price for the LSTM
models to make prediction easier and authentic. We based model. The rest of the paper consists of
have used Regression and LSTM based Machine following : Part 2 puts forward the two models used
learning in our project, which have been known to and the methods used in them in detail. Part 3
decrease error and increase accuracy of the discusses the results produced with different plots for
predictions. The dataset used is from Yahoo Finance. both the models in detail. Part 4 consists of
conclusion and the last section involves the
Keywords- Open, Close, High, Low, Volume, acknowledgement and the references.
Regression, LSTM

MODELS USED FOR PREDICTION


INTRODUCTION
Stock market prediction seems a complex problem
A correct prediction of stocks can determine huge
because there are many factors that have to be
profits for the seller and the broker. Frequently, It is
addressed and it doesn’t seem statistical at first. But
brought out that Prediction is chaotic rather than
by proper use of machine learning techniques, we can
random, which means it can be predicted by carefully
relate previous data to the current data and train our
analyzing the history of respective stock market.
machine to learn from it and make appropriate
Machine learning is an efficient way to represent
assumptions. Machine learning as such has many
such processes. It predicts market value close to the
models but we have focused on two most important
tangible value, thereby increasing accuracy.
of them and made our predictions using them.
Introduction of machine learning to stock prediction
area has appealed many researches because of its [1] Regression based model
efficient and accurate measurements.
The vital part of machine learning is the dataset used.
The dataset should be concrete as a little change in
data can perpetuate massive changes in the outcomes.
In this project, supervised machine learning is
employed on yahoo finance dataset. This dataset
comprises of following five variables: open, close,
low, high and volume. Open, close, low and high are
different bid prices for the stock at separate times
with nearly direct names. The volume is the number
of shares that passed from one owner to another Figure 1: Flow chart for regressive predictive model
Regression is used for predicting continuous values the RNNs through retaining information for older
through some given independent values. The project stages making the prediction more accurate. Since
is based upon the use of linear regression algorithm stock market involves processing of huge data, the
for predicting correct values by minimizing the error gradients with respect to the weight matrix may
function as given in figure1. This operation is called become very small and may degrade the learning rate
gradient descent. Regression uses a given linear of our system. This corresponds to the problem of
function for predicting continuous values: Vanishing Gradient. LSTM prevents this from
happening. The LSTM consists of a remembering
V = a + bK + error
cell, input gate, output gate and a forget gate. The cell
Where V: continuous value; K: known remembers the value for long term propagation and
value/independent value; a,b=coefficients the gates regulate them.
We worked on csv format of data through panda In our project we have made a sequential model and
library and calculated the parameter which is to be stacked two LSTM layers on top of each other with
predicted, the price of the stocks with respect to time. the output value of 256. The input to the layer is in
The data is divided into different train sets for cross the form of two layer[0] and layer[1]. We have fixed
validation to avoid over fitting. The test set is a dropout value of 0.3 which means that 0.3 out of
generally kept 20% of the whole dataset. Linear total nodes will be freezed during the training process
regression as given by the above equation is to avoid over-fitting of data and increase the speed of
performed on the data and then predictions are made, the training process. At last, the core dense layer
which are plotted to show the results of the stock where each neuron is connected to every other in the
market prices vs time. next layer is added providing input of 32 parameters
to the next core layer which gives ouput as 1. The
[2] Long Short Term Memory networks (LSTM)
model is compiled with a mean square cost function
based model.
to maintain the error throughout the process and
accuracy is chosen as a metric for the prediction.
Follow Figure 2.

EXPERIMENTAL RESULTS

The proposed system is trained and tested over yahoo


finance dataset and yields the following results :
[1] Regression based results.

Figure2: LSTM Layers

LSTM is the advanced version of Recurrent neural


networks (RNN) where the information belonging to
previous state persists. These are different from
RNNs as they involve long term dependencies and
RNNs works on finding the relationship between the
recent and the current information. This indicates that
the interval of information is relatively smaller than
that to LSTM. The main purpose behind using this
model in stock market prediction is that the
predictions depends on large amounts of data and are
generally dependent on the long term history of the
market. So LSTM regulates error by giving an aid to Figure3: Plot between Price and Date using Regression.
The plot in figure3 is the result of application of Radhika M. Rai (Manipal Institute of
linear regression algorithm on the dataset to predict Technology, Manipal University, Manipal
varying prices with respect to the time. 576 104, India).
[2] Beginners guide to regression analysis and
[2] LSTM based results. plot interpretation.
[3] Stock market prediction (from Wikipedia,
the free encyclopedia).
[4] Predicting Stocks with Machine Learning,
University of Oslo.
[5] Colah’s blog, (understanding LSTM
networks).
[6] Keras Documentation (github).

ACKNOWLEDGEMENT

[1] We would like to express our gratitude to


our mentor Dr. Lokesh Chouhan, dept. CSE
NIT Hamirpur for guiding and encouraging
Figure3- Plot between actual and predicted trend of LSTM. us throughout our project work. Knowledge
that we have attained through this process
The above graph figure 3 is plot over the data having from him, can be considered as a valuable
batch size 512 and 90 epochs. The prediction is part of our life.
shown by red line and the actual trend is shown by
blue. The proximity of these two lines tells us how [2] We would also like to thank the faculty of
efficient the LSTM based model is. The prediction computer science and engineering
approximates real trend when a considerable amount department for their incredible support and
of time has passed. The more we train our system the collaboration.
more accuracy will be improved.

CONCLUSION
We have used two techniques in this paper: LSTM
and Regression, on the Yahoo finance dataset. Both
the techniques have shown an improvement in the
accuracy of predictions, thereby yielding positive
results. Use of recently introduced machine learning
techniques in the prediction of stocks have yielded
promising results and thereby marked the use of them
in profitable exchange schemes. It has led us to
believe that it is possible to predict stock market with
more accuracy and efficiency.

REFERENCES

[1] Prediction Models for Indian Stock market,


Aparna nayak (Manipal Institute of
Technology , M.M. Manohara rai( Manipal
Institute of Technology, Manipal university),

You might also like