Stock Price Prediction By Using Deep Learning
*Note: Sub-titles are not captured in Xplore and should not be used
SAI KRISHNA REDDY RESEARCH SAI KUMAR REDDY
BHIMVARAPU BAPTALA, INDIA VENDIDENDALA
DEPT.COMPUTER SCIENCE AND LAKSHMIPATHIRAJU6881@GMAI DEPT.COMPUTER SCIENCE AND
ENGINEERING L.COM ENGINEERING
VIGNAN FOUNDATION FOR VIGNAN FOUNDATION FOR
SCICENCE,TECHNOLOGY AND MR.T.R.RAJESH SCICENCE,TECHNOLOGY AND
RESEARCH ASSISTANT PROFESSOR IN THE RESEARCH
GUNTUR, INDIA SCHOOL OF COMPUTER SCIENCE GUNTUR, INDIA
[email protected] ENGINEERING
[email protected] OM VIGNAN FOUNDATION FOR
LAKSHMI PATHI RAJU SCICENCE,TECHNOLOGY AND
PENUMETCHA RESEARCH
DEPT.COMPUTER SCIENCE AND GUNTUR, INDIA
ENGINEERING
VIGNAN FOUNDATION FOR
SCICENCE,TECHNOLOGY AND
Abstract—Stock price prediction is one of the difficult task its memory cell, which acts as a computational unit. The
in now a days because lot of companies stocks are available in primary objective of the paper is to forecast stock prices
the market where huge number of the people are investing on using LSTM. The main goal of forecasting is to reduce
the stocks for maximizing their income through investments in uncertainty when making investment decisions.
different stocks but they did not know the trends in the stocks
and their predictions will be wrong in some cases so, to avoid II. EXISTING METHODS
these problems this paper will guide us to build a stock price
prediction forecasting using machine learning and deep Several machine learning models have been used for
learning techniques.This research suggests that historical value predicting future stock prices, including linear regression,
bears the impact of all previous market occurrences and can be KNN (k-nearest neighbour), and SVM (support vector
used to anticipate future movement. Machine machine). However, these models have certain limitations
Learning Insights and paradigms that can be used to create when processing large amounts of data. For instance, linear
surprisingly accurate predictions can be found using
regression can suffer from over-fitting or under-fitting,
techniques. We propose the LSTM (Long Short Term
Memory) model to examine the future price of a stock. In order while KNN's prediction stage may become slow with large
to make more knowledgeable and exact investment decisions, datasets. SVM is not suitable for large datasets and may not
this paper will attempt to forecast stock market prices. perform well with noisy data.
Keywords --- Deep Learning,LSTM model,Machine Learning. In this study, we propose a new approach that uses LSTM
(Long Short Term Memory), a type of recurrent neural
I. INTRODUCTION network that addresses the problem of long-term
The invention of financial markets is considered to be one of dependencies. The LSTM model contains memory cells that
the most significant advancements of our time due to its store information for a longer time, giving it a significant
impact on various aspects such as business, education, advantage in processing large amounts of data. According to
employment, technology, and the economy. Stock market the study, when decision trees were utilized as a classifier,
forecasting has always been a subject of interest for analysts the prediction accuracies for "two levels," "three levels," and
and researchers. In the long run, the stock market operates "five levels" were 63.8%, 32.02%, and 12%, respectively.
more like a weighing machine than a voting machine,
enabling it to forecast market movements over an extended The LSTM model, with its ability to process and store vast
period. Violent fluctuations in the stock market necessitate amounts of data, is a better approach to predicting stock
the use of more complex financial indicators to predict prices. Recurrent Neural Networks (RNN) have recurring
prices. Price prediction is advantageous in maximizing properties, and there may be issues with vanishing or
purchase benefits while minimizing risks. Despite the exploding gradients. However, this new model shows
Efficient Market Hypothesis suggesting that the market promising results and suggests that stock prices can be
cannot be manipulated using available information, predicted with greater accuracy using LSTM than with other
historical data is used in the proposed model to forecast existing models.
future stock prices. Machine learning techniques have
become increasingly popular in recent years, inspiring many III. PROPOSED METHOD
analysts, researchers, and traders to use them to predict Accurate market forecasting is crucial, and while there
future stock prices, with LSTM being the preferred are several algorithms available, selecting the right
architecture.
one is key to achieving optimal results. This study
LSTM is an architecture that is frequently used in proposes a new stock market forecasting system that
predicting, processing, and classifying statistical data due to combines informative input variables with Recurrent
XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE
Neural Networks (RNNs) to create an effective and
reliable forecasting model. RNNs have an attached
memory that distinguishes them from feed-forward
neural networks. They clone the output and forward it
to the recurrent networks, learning the
contemporaneous input and output from previous
inputs. RNNs use their internal state memory to
process a sequence of inputs, unlike feed-forward
neural networks, where inputs are independent of
each other. Additionally, a novel stock market price
prediction model based on Long Short Term Memory
(LSTM) using deep learning and stock market basic Input gate : The role of the input gate is to determine
data is proposed, validated, and assessed for which pertinent information from the current step can
effectiveness. Figure 1 depicts the architecture be incorporated.
diagram of the LSTM model, illustrating how it works
and stores useful data in its memory cells.
3.1 ABOUT LSTM
The architecture of Long Short-Term Memory (LSTM)
networks is significantly different from traditional
RNN and neural network structures. Unlike traditional
networks, which treat all neurons equally, LSTM
networks connect past information to the current task
through each neuron, serving as a "memory cell".
Instead of using artificial neurons in the hidden layer
of the network, LSTM networks employ memory cells
as computation units. This enables the network to
Output gate :The next hidden state's values are
gradually connect to its memory and input, resulting
determined by the output gate
in a higher predictive capacity that is better suited to
the temporal nature of knowledge. This approach
addresses the vanishing gradient problem commonly
encountered in RNNs, resulting in more reliable and
accurate predictions. The integration of LSTM
networks in stock market forecasting systems
facilitates more precise predictions and trend
identification over time, leading to better decision-
making and improved investment outcomes.
3.2 ARCHITECTURE
4.METHODOLOGIES
The data used here is from TINGO. TINGO is an enterprise-
grade API that enables users to download financial data.
Through TINGO it is possible to access end-of-day (EOD)
stock price data, or we can use Yahoo finance for the Real
Time dataset for stocks. So, we are using TINGO here.
Which includes, open, close, high, low volume values of
particular companies. This model uses close price to
estimate the future stock price. Every Machine Learning or
Fig.1.LSTM Architecture
Deep Learning models can follow several steps to prepare a
good model. They are:
There are three different gates in an LSTM cell They
are Forget gate,Input gate and output gate. 4.1. DATA COLLECTION:
Forget gate : LSTM goes to forget gate and it forgets
For a model we require data to train or test the model. So,
information that is not useful. we will use Pandas Data-Reader library which is a tool for
importing financial data into a Pandas Data-Frame and day and estimate average values for the following day. This
working with it in python. can provide investors, analysts, or anyone with an interest in
the stock market with valuable insights for making informed
4.2 DATA PRE PROCESSING: decisions. Overall, by carefully considering the strengths
and weaknesses of different activation functions and
Data pre -processing is a process of preparing the raw data
incorporating LSTM, the predictive model can provide
and making it suitable for a machine learning model. There accurate and reliable information for the stock market.
are few Pre-processing steps they are: Data quality To evaluate the performance of a neural network model,
assessment, Data cleaning, Data transformation, Data various tests are conducted and several criteria are
reduction. LSTM are sensitive to the scale of the data. So, measured. These tests are essential to assess the accuracy
we apply Min-max scale which converts all the values and reliability of the model's predictions. The most
between 0 to 1 range. After that we will split the data into commonly used metrics for evaluating the performance of a
training and testing where we will use 70% data for training regression model are Mean Squared Error (MSE), Mean
and 30% for testing. Absolute Error (MAE), Root Mean Squared Error (RMSE),
and R-squared.
4.3. CREATING LSTM MODEL: MSE measures the average squared difference between the
predicted and actual values, while MAE calculates the
LSTM model is included in the libraries of TENSORFLOW
average absolute difference between them. RMSE is the
and KERAS. So, we require to import Sequential, Dense,
square root of the MSE, and it indicates the average
LSTM libraries from the TENSORFLOW, KERAS, then we magnitude of the error. Finally, R-squared measures the
will create model for LSTM. proportion of the variance in the dependent variable that is
4.4. TRAINING NURAL NETWORK: explained by the independent variable.
These metrics provide valuable insights into the accuracy
By inputting data, our model assigns random biases and and reliability of the model, and they help to identify any
weights. The network is trained to make predictions using areas where the model may need to be improved. By
the existing neural network. The neural network in our carefully analyzing these criteria, the model can be
model contains four levels: an input layer, two LSTM layers optimized to provide the best possible performance and
(hidden layers), and an output layer. Forecasting Model. accuracy in regression analysis.
• Mean Absolute Error (MAE):
Each unit in a layer connects to all units in neighbouring
• MAE = (1/n) * Σ|j=1 to n| |Yj - Y|
layers. There are 46 LSTM nerve entities in the LSTM layer.
• Mean Squared Error (MSE):
The output layer, which consists of just one unit, creates the • MSE = (1/n) * Σ|j=1 to n| (Yj - Y)^2
completely connected layer.Three different activation • Root Mean Squared Error (RMSE):
functions, namely Rectified Linear Unit (ReLU), hard • RMSE = sqrt[(1/n) * Σ|j=1 to n| (Yj - Y)^2]
sigmoid, and tanh, are employed in the stock price • R-squared (R2):
prediction prototype. • R2 = 1 - [(1/n) * Σ|j=1 to n| (Yj - Y)^2] / [(1/n) * Σ|
j=1 to n| (Yj - Ȳ)^2]
4.5. OUTPUT GENERATION:
where Ȳ is the mean of the dependent variable.So, here we
The output value, which was produced by our model's are using RMSE(Root Mean Square Error ) as the metrics
output layer, is being compared to the goal value. The bias for evaluating the quality of predictions.Here we are
of a network is determined using a back propagation applying the RMSE for the AAPL data set where we get the
RMSE value as 1.97 .
algorithm, which is used to identify errors and discrepancies
that relate the targeted and received output values and are
minimized by changing its weights. 6.RESULTS
5.ANALYSIS
To create a predictive model for stock index, it's crucial to
minimize the error in processing input data. One popular
activation function used in this model is Rectified Linear
Unit (ReLU). By setting any negative values to zero, ReLU
effectively removes the issue of vanishing gradients that can
occur with other activation functions like sigmoid or tanh. It
also has linear properties that can speed up the computation
compared to stochastic gradient methods. However, when
the threshold is set to zero, ReLU can cause the neuron to Fig .3.Stock closing and ending price
become "lazy" and not respond to certain data points,
leading to a loss of accuracy in the model. Additionally, if
the gradient flow is consistently directed towards weight
gain, the neuron can become permanently deactivated,
resulting in a weakened model.
To address these issues, the model can use Long Short-Term
Memory (LSTM) to predict unfamiliar values for the next
extracting relevant information through additional
input gates, while discarding noise from low-
correlated factors controlled by mainstream factors.
Overall, the use of advanced forecasting techniques
such as LSTM can provide valuable insights into stock
market trends, helping investors and individuals make
informed decisions about their investments.
References
[1].Kavinnilaa J, Hemalatha E, Minu susan Jacob,
Fig.4.Stocks actual value and predicted values for future
Dhanalakshmi R,”Stock price prediction based on lstm
deep learning model”, International Conference on
7.CONCLUSION: System,IEEE 2021.
It is true that the stock market's popularity has been [2]. Md. Arif Istiake Sunny, Mirza Mohd Shahriar
increasing rapidly in recent years, and there is a Maswood, Abdullah G. Alharbi ,”deep learning-based
growing interest in developing new forecasting stock price prediction using lstm and bi-directional
methods to predict stock indices. The use of ethical lstm model”,2nd novel intelligent and leading
and accurate forecasting technology can help emerging sciences conference(2020).
researchers, investors, and individuals make informed [3]. Haorui Zhang , International School of Business
decisions in the stock market. and Finance, Sun Yat-sen University , Guangzhou ,
One such method is the Long Short-Term Memory China(2022), Stock price prediction using linear
(LSTM) model, which has been found to outperform regression and LSTM model MLISE conference.
other models due to its ability to learn long-term [4]. Thalita R. Silva, Audeliano W. Li & Edson
O.Pamplona ,(2020)“Automated Trading System for
dependencies. LSTM is an improvement over the
Stock Index Using LSTM Neural Networks and Risk
Recurrent Neural Network (RNN) model, as it has a
Management”,International conference ,UK.
more effective way of updating, erasing, and recalling
[5]. Bairavel S and Dr. M. Krishnamurthy (2020). User
information.
Preference and Reviews Analysis with Neural Networks
Using accurate precision forecasting techniques can for Travel Recommender Systems. International Journal
help investors, analysts, and individuals make better of Engineering Research and Technology, 13(8): 1896-
decisions in the stock market by providing them with 1900. Impact Factor: 0.15, Q3 Journal.
valuable insights into future market trends. The use of [6]. Hishan Mohmood and Mohammad Safayet Hossain
an LSTM model with multiple inputs can further (2020),”Short-Term Load Forecasting Using an LSTM
improve the accuracy of these predictions by Neural Network”, IEEE Network.