100% found this document useful (1 vote)
82 views9 pages

Stock Market Prediction Using LSTM

Different machine learning algorithms are discussed in this literature review. These algorithms can be used for predicting the stock market. The prediction of the stock market is one of the challenging tasks that must have to be handled.In this paper, it is discussed how the machine learning algorithms can be used for predicting the stock value. Different attributes are identified that can be used for training the algorithm for this purpose. Some of the other factors are also discussed that can
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
100% found this document useful (1 vote)
82 views9 pages

Stock Market Prediction Using LSTM

Different machine learning algorithms are discussed in this literature review. These algorithms can be used for predicting the stock market. The prediction of the stock market is one of the challenging tasks that must have to be handled.In this paper, it is discussed how the machine learning algorithms can be used for predicting the stock value. Different attributes are identified that can be used for training the algorithm for this purpose. Some of the other factors are also discussed that can
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
You are on page 1/ 9

10 IV April 2022

https://doi.org/10.22214/ijraset.2022.42039
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

Stock Market Prediction Using LSTM


Shaikh Shoieb Abubaker1, Syed Rouf Farid2
1, 2
Computer Engineering, Keystone School of Engineering, Pune, Maharashtra ,India

Abstract: Different machine learning algorithms are discussed in this literature review. These algorithms can be used for
predicting the stock market. The prediction of the stock market is one of the challenging tasks that must have to be handled.In
this paper, it is discussed how the machine learning algorithms can be used for predicting the stock value. Different attributes
are identified that can be used for training the algorithm for this purpose. Some of the other factors are also discussed that can
have an effect on the stock value.
Keywords: Machine learning, stock market prediction, literature review, artificial neural network, support vector machine,
genetic algorithm, investment decision, RNN, LSTM.

I. INTRODUCTION
The stock market is the place where the buyers and sellers come for the purpose of buying the stocks and selling the stocks of a
company. With the passage of time, more and more people are getting interested in the stock market. The
increasing interest of the people makes this topic more important for the research. Machine learning provides different predictive
algorithms that can be very helpful in this domain. Different sectors are using the machine learning
for their improvement. The use of machine learning enables the computers to learn without the involvement of any external
program.Recurrent neural networks (RNN) have proved one of the most powerful models for processing sequential data.Long
Short-Term memory is one of the most successful RNNs architectures. LSTM
RNN, capable of learning long-term dependencies. They were introduced by Hochreiter & Schmidhuber (1997), and were refined
and popularised by many people in following work.1 They work tremendously well on a large variety of problems, and are now
widely used. The paper that we have presented modelled and predicted the stock returns of Apple and 5 other major tech companies
using LSTM. We are in the ever growing generation on financial literacy and the never ending scope on the stock market. Although
people have been using pen paper and the traditional mathematical manner to predict stock movement. So after looking at the other
few models and methods available we decided to take a dive into this field and have a solution that can predict the movement of
stocks for an individual .

II. METHODOLOGY
A. Proposed Systems
The prediction methods can be mainly categorised into two ,statistical methods and artificial intelligence methods. Statistical
methods consist of logistic regression model, ARCH model, etc. Artificial intelligence methods includes multi-layer
perceptron, convolutional neural network, Back propagation network,single-layer LSTM, recurrent neural network, etc. They used a
Long short-term memory network (LSTM).

B. Long Short Term Memory


Long Short Term Memory networks – usually just called “LSTMs” – are a special kind of RNN, capable of learning long-term
dependencies. They were introduced by Hochreiter & Schmidhuber (1997), and were refined and popularised by many people in
following work.1 They work tremendously well on a large variety of problems, and are now widely used.

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3178
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

C. Working of LSTM
LSTM is a special network that has three gates in its structures. these gates are placed in an LSTM unit, called as input gate,
forgetting gate and output gate.AS the information enters the LSTM’s network, it can be selected by rules defined . Only the
information that follows the algorithm will be left, and the information that does not follow the algorithm will be forgotten through
the forgetting gate. The experimental data in this paper are the actual historical data downloaded from the Internet. Three data sets
were used in the experiments. It is needed to find an optimization algorithm that requires less resources and has faster convergence
speed. The System that we propose has several steps that lead to model generation . The steps involved are as follows .
1) Stage 1: Raw Data: In this stage, the historical stock data is collected from the internet and this historical data is used for the
prediction of future stock prices.
2) Stage 2: Data Preprocessing: The pre-processing stage involves
a) Data discretization: Part of data reduction but with particular importance, especially for numerical data
b) Data transformation: Normalisation.
c) Data cleaning: Fill in missing values.
d) Data integration: Integration of data files. After the dataset is transformed into a clean dataset, the dataset is divided into
training and testing sets so as to evaluate. Here, the training values are taken as the more recent values. Testing data is kept as
5-10 percent of the total dataset
3) Stage 3: Training Neural Network: In this stage, the data is fed to the neural network and trained the prediction is done by
assigning random biases and weights. Our LSTM model is composed of a sequential input layer followed by 2 LSTM layers
and 4 dense layer with ReLU activation and then finally a dense output layer.
4) Stage 5: Output Generation: In this layer, the output value generated by the output layer is compared to the target value from
the dataset . The error or the difference between the target and the obtained output value is minimized by using back
propagation algorithm which adjusts the weights and the biases of the network

D. Advantages of LSTM
The advantage of the Long Short-Term Memory (LSTM) network over other recurrent networks back in 1997 came from an
improved method of back propagating the error. Hochreiter and Schmidhuber called it “constant error back propagation”
One of the main advantages of LSTM is its capacity to read intermediary context. Each unit of cll remembers data for a
long / short period without unambiguously utilising the activation function.
An important fact is that any cell state is repeated only with the release of the forget gate, which varies between range of 0
to 1. That’s to say, the gateway for forgetting in the LSTM cell is responsible for both the hardware and the function of
the cell state activation. LSTMs were developed to deal with the vanishing gradient problem that can be encountered when training
traditional RNNs.

E. Analysis
In our system for analysis we have used the root mean squared error method . The error of the difference between the target and
predicted value is minimized by the RMSE value . The use of RMSE is highly common. It makes an excellent general purpose error
metric . Compared to the similar Mean Absolute Error, RMSE amplifies and severely punishes large errors.

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3179
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

III. DATASET
The dataset that we have used is of 5 tech giants in the NASDAQ market . The dataset used are of Apple ,Amazon , Google ,
Microsoft and Tesla .The different columns or as we refer to them as features are as followed

Here the values are as followed :-


1) Date: Date of which prices are listed.
2) Open: Opening price of stock on that date .
3) High: Highest value of the stock on that date.
4) Low: Lowest prices of the stock on that date .
5) Close: The closing price of the stock
6) Adj, Close: Adjusted close is the price of the stock after dividends and other related manipulation .
7) Volume: Volume of stock traded on that day .

The main model was created using the dataset for Apple

IV. PROPOSED SYSTEM


A. System Components

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3180
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

B. System Chart

C. Collaboration Diagram

V. EDA AND DATA PRE-PROCESSING


A. Data Cleaning
The dataset is not in the right format to use directly with the model hence data preprocessing is required . In our model we did a few
steps as followed :
1. Dropping the null rows

2. Changing the data types of the column / features .

3. Sorting the data by date.

4. Dropping older data

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3181
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

B. EDA
We plotted the closing value of the stock to check the trends.

Moving Average for 10 , 20 and 50 days :

VI. DEFINING CUSTOM LEARNING RATE


A. Code
We created a scheduler function that takes in the number of epochs and sets a custom learning rate and then we passed on the
Learning rate scheduler function of keras via the tensorflow module . The code for the scheduler is as follows .

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3182
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

B. Plotting the Learning Rate

VII. MODEL CREATION


A. Splitting the dataset
For model creation we split the data for training and testing based on the period / date the stock price was recorded . We defined a
function that splits the dataset . The function divided the dataset in training and testing and further into the training dependent and
independent variables. We then split the data based on time as this is a time series based problem .

B. Fitting the Model


The model that we created was compiled using the Adam optimizer that we imported from Keras . The loss function used for mse
and the metric for evaluation that we used is RMSE as defined above that was also used from the keras metric function of keras .

We fit the model using the training split of the dataset by passing the dependent and the independent variables . We passed the
testing dataset in the validation dataset and passed the callback function that we made defining the learning rate scheduler .

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3183
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IV Apr 2022- Available at www.ijraset.com

VII. EXPERIMENTAL ANALYSIS


A. Loss and Error
We recorded the loss and error that we realised came down as the number of epoch kept increasing . The loss and error is as follows
for the model we created .

B. Prediction Of The Future Price Using Testing Dataset


We used the the predict function of the model that was created compiled and fitted using the training dataset and we passed on the
testing dataset to find the prediction . The predicted and the target value was plotted and the results are as shown below.

VIII. CONCLUSION
The popularity of stock market trading is growing rapidly between the domestic and international marker , which is encouraging
researchers to find new methods for prediction using new techniques and using more and more of the historical dataset with time as
it goes on increasing .
The forecasting technique is not only helping the researchers but it also helps investors and any individual dealing with the stock
market. In order to help predict the stock indices, a forecasting model with good accuracy is required.
In our work, we have used one of the most precise forecasting technologies using Recurrent Neural Network and LSTM unit which
will help investors, analysts or any person interested in investing in the stock market by providing them a good knowledge of the
future situation of the stock market of domestic and international markets .

REFERENCES
[1] Prediction of Stock Market Using Recurrent Neural Network - Sadman Bin Islam; Mohammad Mahabubul Hasan; Mohammad Monirujjaman Khan - 27-30
Oct. 2021.
[2] Stock market prediction using LSTM Recurrent Neural Network - Adil Moghar, Mahmed Hamiche -April 6-9, 2020 .
[3] Comparison of Predictive Algorithms: Backpropagation, SVM,LSTM and Kalman Filter for Stock Market - Divit Karmiani ,Ruman Kazi,Ameya Nambisan,
Aastha Shah, Vijaya Kamble.
[4] Predicting Stock Market Price: A Logical Strategy using Deep Learning - Milon Biswas; Atanu Shome; Md. Ashraful Islam; Arafat Jahan Nova; Shamim
Ahmed - 3-4 April 2021 .
[5] Deep Learning-Based Stock Price Prediction Using LSTM and Bi-Directional LSTM Model - Md. Arif Istiake Sunny; Mirza Mohd Shahriar Maswood;
Abdullah G. Alharbi - 24-26 Oct. 2020

©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 3184

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy