Projects 2021 C9
Projects 2021 C9
Projects 2021 C9
Submitted by
Somaraju Dinesh - 317126510170
ACKNOWLEDGEMENT
We would like to express our deep gratitude to our project guide N D S S KIRAN
RELANGI, Assistant Professor, Department of Computer Science and Engineering,
ANITS, for his/her guidance with unsurpassed knowledge and immense encouragement.
We are grateful to Dr.R.Sivaranjani, Head of the Department, Computer Science and
Engineering, for providing us with the required facilities for the completion of the project
work.
We are very much thankful to the Principal and Management, ANITS, Sangivalasa, for
their encouragement and cooperation to carry out this work.
We express our thanks to Project Coordinator Dr.V.Usha Bala, for her Continuous
support and encouragement. We thank all teaching faculty of Department of CSE, whose
suggestions during reviews helped us in accomplishment of our project. We would like to
thank S. Sajahan of the Department of CSE, ANITS for providing great assistance in
accomplishment of our project.
We would like to thank our parents, friends, and classmates for their encouragement
throughout our project period. At last but not the least, we thank everyone for supporting
us directly or indirectly in completing this project successfully.
PROJECT STUDENTS
This is to certify that the project report entitled “STOCK PRICE PREDICTION”
submitted by Somaraju Dinesh (317126510170), Adduri Maruthi Siva Rama Raju
(318126510L25), Sasumana Rahul (317126510167), Oruganti Naga Sandeep
(318126510L29) in partial fulfillment of the requirements for the award of the degree of
Bachelor of Technology in Computer Science Engineering of Anil Neerukonda
Institute of technology and sciences (A), Visakhapatnam is a record of bonafide work
carried out under my guidance and supervision.
DECLARATION
We, SOMARAJU DINESH, ADDURI MARUTHI SIVA RAMA RAJU,
SASUMANA RAHUL, OORUGANTI NAGA SANDEEP, of final semester B.Tech., in
the department of Computer Science and Engineering from ANITS,
Visakhapatnam, hereby declare that the project work entitled STOCK PRICE
PREDICTION is carried out by us and submitted in partial fulfillment of the
requirements for the award of Bachelor of Technology in Computer Science
Engineering , under Anil Neerukonda Institute of Technology & Sciences(A) during the
academic year 2017-2021 and has not been submitted to any other university for the
award of any kind of degree.
ABSTRACT
There are two types of stocks. You may know of intraday trading by the commonly
used term "day trading." Interday traders hold securities positions from at least one day to
the next and often for several days to weeks or months. LSTMs are very powerful in
sequence prediction problems because they’re able to store past information. This is
important in our case because the previous price of a stock is crucial in predicting its
future price. While predicting the actual price of a stock is an uphill climb, we can build a
model that will predict whether the price will go up or down.
Keywords: LSTM, CNN, ML, DL, Trade Open, Trade Close, Trade Low, Trade High
CONTENTS
ABSTRACT v
LIST OF FIGURES ix
LIST OF TABLES x
LIST OF ABBREVATIONS xi
CHAPTER 1 INTRODUCTION 01
1.1 Motivation for work
1.2 Problem statement
CHAPTER 2 LITERATURE SURVEY 03
CHAPTER 3 METHODOLOGY 10
REFERENCES 58
LIST OF SYMBOLS
Xt Input at current state
X(t-1) Input at Previous state
Ct Current Cell State C(t-1) Previous Cell State ht Current
hidden/output State h(t-1) Previous hidden/output State
σ Sigmoid Function
tanh Hyperbolic tangent function
LIST OF FIGURES
LIST OF TABLES
Table No. Topic Name Page No.
1 Min and Max of columns in Google Dataset 49 2 Min and Max of columns in
Nifty50 Dataset 50
3 Min and Max of columns in Reliance Dataset 50
4 Sample input 50
5 Epochs for Google Dataset using LSTM 55
6 Epochs for Nifty50 Dataset using LSTM 55
7 Epochs for Reliance Dataset using LSTM 55
8 Epochs for Google Dataset using LSTM with LMS 56
9 Epochs for Nifty50 Dataset using LSTM with LMS 56 10 Epochs for
Reliance Dataset using LSTM with LMS 56
LIST OF ABBREVATIONS
LSTM Long Short-Term Memory
ATS Automated Trading System
GRU Gated Recurrent Unit
ML Machine Learning
SVM Support Vector Machine
EMH Efficient Market hypothesis
AI Artificial Intelligence
NN Neural Networks
ARMA Autoregressive Moving Average
DRL Deep Reinforcement Learning
LMS Least Mean Square
UML Unified modelling Language
MSE Mean Squared Error
RMSE Root Mean Squared Error
CHAPTER 1 INTRODUCTION
The financial market is a dynamic and composite system where people can buy
and sell currencies, stocks, equities and derivatives over virtual platforms supported by
brokers. The stock market allows investors to own shares of public companies through
trading either by exchange or over the counter markets. This market has given investors
the chance of gaining money and having a prosperous life through investing small initial
amounts of money, low risk compared to the risk of opening new business or the need of
high salary career. Stock markets are affected by many factors causing the uncertainty and
high volatility in the market. Although humans can take orders and submit them to the
market, automated trading systems (ATS) that are operated by the implementation of
computer programs can perform better and with higher momentum in submitting orders
than any human. However, to evaluate and control the performance of ATSs, the
implementation of risk strategies and safety measures applied based on human judgements
are required. Many factors are incorporated and considered when developing an ATS, for
instance, trading strategy to be adopted, complex mathematical functions that reflect the
state of a specific stock, machine learning algorithms that enable the prediction of the
future stock value, and specific news related to the stock being analysed.
1
1.1 MOTIVATION FOR WORK
Businesses primarily run over customer’s satisfaction, customer reviews about their
products. Shifts in sentiment on social media have been shown to correlate with shifts in
stock markets. Identifying customer grievances thereby resolving them leads to customer
satisfaction as well as trustworthiness of an organization. Hence there is a necessity of an
un biased automated system to classify customer reviews regarding any problem. In
today’s environment where we’re justifiably suffering from data overload (although this
does not mean better or deeper insights), companies might have mountains of customer
feedback collected; but for mere humans, it’s still impossible to analyse it manually
without any sort of error or bias. Oftentimes, companies with the best intentions find
themselves in an insights vacuum. You know you need insights to inform your decision
making and you know that you’re lacking them, but don’t know how best to get them.
Sentiment analysis provides some answers into what the most important issues are, from
the perspective of customers, at least. Because sentiment analysis can be automated,
decisions can be made based on a significant amount of data rather than plain intuition.
2.1 INTRODUCTION
"What other people think” has always been an important piece of information for
most of us during the decision-making process. The Internet and the Web have now
2
(among other things) made it possible to find out about the opinions and experiences of
those in the vast pool of people that are neither our personal acquaintances nor well-
known professional critics — that is, people we have never heard of. And conversely,
more and more people are making their opinions available to strangers via the Internet.
The interest that individual users show in online opinions about products and services, and
the potential influence such opinions wield, is something that is driving force for this area
of interest. And there are many challenges involved in this process which needs to be
walked all over in order to attain proper outcomes out of them. In this survey we analysed
basic methodology that usually happens in this process and measures that are to be taken
to overcome the challenges being faced.
3
the historical prices of an asset. This means that the market behaves as a random walk and
as a result makes forecasting impossible. Furthermore, financial forecasting is a difficult
task due to the intrinsic complexity of the financial system. The objective of this work was
to use artificial intelligence (AI) techniques to model and predict the future price of a
stock market index. Three artificial intelligence techniques, namely, neural networks
(NN), support vector machines and neuro-fuzzy systems are implemented in forecasting
the future price of a stock market index based on its historical price information. Artificial
intelligence techniques have the ability to take into consideration financial system
complexities and they are used as financial time series forecasting tools.
4
subtle differences in their surface realizations. To address this issue, this paper proposes to
leverage external common-sense knowledge about the intent and sentiment of the event.
5
Traditionally and in order to predict market movement, investors used to analyse the stock
prices and stock indicators in addition to the news related to these stocks. Hence, the
importance of news on the stock price movement. Most of the previous work in this
industry focused on either classifying the released market news as (positive, negative,
neutral) and demonstrating their effect on the stock price or focused on the historical price
movement and predicted their future movement. In this work, we propose an automated
trading system that integrates mathematical functions, machine learning, and other
external factors such as news’ sentiments for the purpose of achieving better stock
prediction accuracy and issuing profitable trades. Particularly, we aim to determine the
price or the trend of a certain stock for the coming end-of-day considering the first several
trading hours of the day. To achieve this goal, we trained traditional machine learning
algorithms and created/trained multiple deep learning models taking into consideration the
importance of the relevant news. Various experiments were conducted, the highest
accuracy (82.91%) of which was achieved using SVM for Apple Inc. (AAPL) stock.
6
as the intents and emotions of the event participants, which are useful for distinguishing
event pairs when there are only subtle differences in their surface realizations. To address
this issue, this paper proposes to leverage external common-sense knowledge about the
intent and sentiment of the event. Experiments on three event-related tasks, i.e., event
similarity, script event prediction and stock market prediction, show that our model
obtains much better event embeddings for the tasks, achieving 78% improvements on hard
similarity task, yielding more precise inferences on subsequent events under given
contexts, and better accuracies in predicting the volatilities of the stock market.
7
debugging. In this paper, we introduce a DRL library FinRL that facilitates beginners to
expose themselves to quantitative finance and to develop their own stock trading
strategies. Along with easily-reproducible tutorials, FinRL library allows users to
streamline their own developments and to compare with existing schemes easily.
Within FinRL, virtual environments are configured with stock market datasets,
trading agents are trained with neural networks, and extensive back testing is analysed via
trading performance. Moreover, it incorporates important trading constraints such as
transaction cost, market liquidity and the investor’s degree of risk-aversion. FinRL is
featured with completeness, hands-on tutorial and reproducibility that favors beginners: (i)
at multiple levels of time granularity, FinRL simulates trading environments across
various stock markets, including NASDAQ-100, DJIA, S&P 500, HSI, SSE 50, and CSI
300; (ii) organized in a layered architecture with modular structure, FinRL provides
finetuned state-of-the-art DRL algorithms (DQN, DDPG, PPO, SAC, A2C, TD3, etc.),
commonly used reward functions and standard evaluation baselines to alleviate the
debugging workloads and promote the reproducibility, and (iii) being highly extendable,
FinRL reserves a complete set of user-import interfaces. Furthermore, we incorporated
three application demonstrations, namely single stock trading, multiple stock trading, and
portfolio allocation. The FinRL library will be available on GitHub at link
https://github.com/AI4Finance-LLC/FinRL-Library.
8
stocks. We demonstrate research contributions in IMMT for neural network-based
financial analysis. 2.2.11 An Intelligent Technique for Stock Market Prediction
Stock market is all about prediction and rapid decision making about
investment, which cannot be done without thorough analysis of the market. If we can
predict the stock market by analysing historical data properly, we can avoid the
consequences of serious market collapse and to be able to take necessary steps to make
market immune to such situations.
CHAPTER 3 METHODOLOGY
9
layer LSTM, support vector machine, recurrent neural network, etc. They used Long
short-term memory network (LSTM).
Working of LSTM:
LSTM is a special network structure with three “gate” structures.
Three gates are placed in an LSTM unit, called input gate, forgetting gate and output gate.
While information enters the LSTM’s network, it can be selected by rules. Only the
information conforms to the algorithm will be left, and the information that does not
conform 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.
• Used Long Short-term Memory (LSTM) with embedded layer and the LSTM
neural network with automatic encoder.
• LSTM is used instead of RNN to avoid exploding and vanishing gradients.
• In this project python is used to train the model, MATLAB is used to reduce
dimensions of the input. MySQL is used as a dataset to store and retrieve data.
• The historical stock data table contains the information of opening price, the
highest price, lowest price, closing price, transaction date, volume and so on.
• The accuracy of this LSTM model used in this project is 57%.
LMS filter:
The LMS filter is a kind of adaptive filter that is used for solving linear
problems. The idea of the filter is to minimize a system (finding the filter coefficients) by
minimizing the least mean square of the error signal.
10
Fig. 1: LMS Inputs and Outputs Fig 2: LMS updating weights
In general, we don’t know exactly if the problem can be solved very well with
linear approach, so we usually test a linear and a non-linear algorithm. Since the internet
always shows non-linear approaches, we will use LMS to prove that stock market
prediction can be done with linear algorithms with a good precision.
11
But this filter mimetizes a system, that is, if we apply this filter in our data, we
will have the filter coefficients trained, and when we input a new vector, our filter
coefficients will output a response that the original system would (in the best case).
So we just have to do a tricky modification for using this filter to predict data.
The system:
First, we will delay our input vector by l positions, where l would be the quantity
of days we want to predict, this l new positions will be filled by zeros.
When we apply the LMS filter, we will train the filter to the first 178 data. After
that, we will set the error as zero, so the system will start to output the answers as the
original system to the last l values. We will call the tricky modification as the LMSPred
algorithm.
12
Results
13
LSTM Architecture
Forget Gate:
A forget gate is responsible for removing information from the cell state.
• The information that is no longer required for the LSTM to understand things or
the information that is of less importance is removed via multiplication of a filter.
• This is required for optimizing the performance of the LSTM network.
• This gate takes in two inputs; h_t-1 and x_t. h_t-1 is the hidden state from the
previous cell or the output of the previous cell and x_t is the input at that particular
time step.
Input Gate:
1. Regulating what values need to be added to the cell state by involving a sigmoid
function. This is basically very similar to the forget gate and acts as a filter for all
the information from hi-1 and x_t.
2. Creating a vector containing all possible values that can be added (as perceived
from h_t-1 and x_t) to the cell state. This is done using the tanh function, which
outputs values from -1 to +1.
3. Multiplying the value of the regulatory filter (the sigmoid gate) to the created
vector (the tanh function) and then adding this useful information to the cell state
via addition operation.
14
Output Gate:
The functioning of an output gate can again be broken down to three steps:
• Creating a vector after applying tanh function to the cell state, thereby scaling the
values to the range -1 to +1.
• Making a filter using the values of h_t-1 and x_t, such that it can regulate the
values that need to be output from the vector created above. This filter again
employs a sigmoid function.
• Multiplying the value of this regulatory filter to the vector created in step 1, and
sending it out as a output and also to the hidden state of the next cell.
• # LSTM
• Inputs: dataset
• Outputs: RMSE of the forecasted data
•
• # Split dataset into 75% training and 25% testing data
• size = length(dataset) * 0.75
• train = dataset [0 to size]
• test = dataset [size to length(dataset)]
•
• # Procedure to fit the LSTM model
• Procedure LSTMAlgorithm (train, test, train_size, epochs)
• X = train
• y = test
• model = Sequential ()
• model.add(LSTM(50), stateful=True)
• model.compile(optimizer='adam', loss='mse')
• model.fit(X, y, epochs=epochs, validation_split=0.2)
• return model
•
• # Procedure to make predictions
• Procedure getPredictonsFromModel (model, X)
• predictions = model.predict(X)
• return predictions
•
• epochs = 100
• neurons = 50
• predictions = empty
15
• # Fit the LSTM model
• model = LSTMAlgorithm (train, epoch, neurons)
•
• # Make predictions
• pred = model.predict(train)
•
• # Validate the model
• n = len(dataset)
•
• error = 0
• for i in range(n): error += (abs(real[i] - pred[i])/real[i]) * 100
• accuracy = 100 - error/n
Hardware Requirements:
• RAM: 4 GB
• Storage: 500 GB
• CPU: 2 GHz or faster
• Architecture: 32-bit or 64-bit
Software Requirements:
• Python 3.5 in Google Colab is used for data pre-processing, model training and
prediction.
• Operating System: windows 7 and above or Linux based OS or MAC OS
Functional requirements
Functional requirements describe what the software should do (the functions). Think about
the core operations.
16
Non-Functional requirements
Product properties
• Usability: It defines the user interface of the software in terms of simplicity of
understanding the user interface of stock prediction software, for any kind of stock
trader and other stakeholders in stock market.
• Efficiency: maintaining the possible highest accuracy in the closing stock prices in
shortest time with available data.
Performance: It is a quality attribute of the stock prediction software that describes the
responsiveness to various user interactions with it.
2) Overall Architecture
17
4.1 Structure Chart
A structure chart (SC) in software engineering and organizational theory is a
chart which shows the breakdown of a system to its lowest manageable levels. They are
used in structured programming to arrange program modules into a tree. Each module is
represented by a box, which contains the module's name.
18
4.2 UML Diagrams
A UML diagram is a partial graphical representation (view) of a model of a
system under design, implementation, or already in existence. UML diagram contains
graphical elements (symbols) - UML nodes connected with edges (also known as paths or
flows) - that represent elements in the UML model of the designed system. The UML
model of the system might also contain other documentation such as use cases written as
templated texts.
The kind of the diagram is defined by the primary graphical symbols shown on
the diagram. For example, a diagram where the primary symbols in the contents area are
classes is class diagram. A diagram which shows use cases and actors is use case diagram.
A sequence diagram shows sequence of message exchanges between lifelines.
UML specification does not preclude mixing of different kinds of diagrams, e.g.
to combine structural and behavioral elements to show a state machine nested inside a use
case. Consequently, the boundaries between the various kinds of diagrams are not strictly
enforced. At the same time, some UML Tools do restrict set of available graphical
elements which could be used when working on specific type of diagram.
Structure diagrams show the static structure of the system and its parts on
different abstraction and implementation levels and how they are related to each other.
The elements in a structure diagram represent the meaningful concepts of a system, and
may include abstract, real world and implementation concepts.
Behavior diagrams show the dynamic behavior of the objects in a system, which
can be described as a series of changes to the system over time.
19
4.2.1 Use Case Diagram
In the Unified Modelling Language (UML), a use case diagram can summarize the
details of your system's users (also known as actors) and their interactions with the
system. To build one, you'll use a set of specialized symbols and connectors. An effective
use case diagram can help your team discuss and represent:
Fig. 8: Using LMS, LSTM and LSTM with LMS in the system
20
developers and business professionals to understand requirements for a new system or to
document an existing process. Sequence diagrams are sometimes known as event
diagrams or event scenarios.
21
Fig. 10: Execution based on algorithm selection
22
collaboration are used by designers to define and clarify the roles of the objects that
perform a particular flow of events of a use case. They are the primary source of
information used to determining class responsibilities and interfaces.
23
Fig. 12: Flow of execution
24
Component diagrams are used in modeling the physical aspects of object-
oriented systems that are used for visualizing, specifying, and documenting component-
based systems and also for constructing executable systems through forward and reverse
engineering. Component diagrams are essentially class diagrams that focus on a system's
components that often used to model the static implementation view of a system.
25
5.1.1 Hardware Requirements:
• RAM: 4 GB
• Storage: 500 GB
• CPU: 2 GHz or faster
• Architecture: 32-bit or 64-bit
26
LMS
27
28
29
LSTM
30
EpochPrintingCallback
31
LSTM Algorithm
32
33
getPredictonsFromModel
34
35
Flask Code
36
37
38
Frontend Pages
Common Header
39
40
Common Navbar
41
Home page
42
Training
43
44
45
46
47
Predictions
48
49
50
5.3 Sample Input and Output:
Google
51
Nifty50
Input:
52
5.4 Website Pages
Home Page
Training Page
53
Fig.16: Training Page: After Selecting the dataset
54
Fig. 18: Training Page: Training Completed
Predictions Page
55
Fig. 20: Predictions Page: After selecting the model
Team Page
56
5.5 Performance Measure
5.5.1 LSTM
5.5.1.1 Google
5.5.1.2 Nifty50
5.5.1.3 Reliance
57
5.5.2.1 Google
5.5.2.2 Nifty50
5.5.2.3 Reliance
Table 10: Epochs for Reliance Dataset using LSTM with LMS
58
6.1 Conclusion
In this project, we are predicting closing stock price of any given organization,
we developed a web application for predicting close stock price using LMS and LSTM
algorithms for prediction. We have applied datasets belonging to Google, Nifty50, TCS,
Infosys and Reliance Stocks and achieved above 95% accuracy for these datasets.
REFERENCES
[1] Stock Price Prediction Using LSTM on Indian Share Market by Achyut Ghosh,
Soumik Bose1, Giridhar Maji, Narayan C. Debnath, Soumya Sen
59
International Conference on Advances in Computing, Communications and
Informatics, 2017.
[3] Murtaza Roondiwala, Harshal Patel, Shraddha Varma, “Predicting Stock Prices
Using LSTM” in Undergraduate Engineering Students, Department of Information
Technology, Mumbai University, 2015.
[4] Xiongwen Pang, Yanqiang Zhou, Pan Wang, Weiwei Lin, “An innovative neural
network approach for stock market prediction”, 2018
[5] Ishita Parmar, Navanshu Agarwal, Sheirsh Saxena, Ridam Arora, Shikhin Gupta,
Himanshu Dhiman, Lokesh Chouhan Department of Computer Science and
Engineering National Institute of Technology, Hamirpur – 177005, INDIA - Stock
Market Prediction Using Machine Learning.
[8] V Kranthi Sai Reddy Student, ECM, Sreenidhi Institute of Science and
Technology, Hyderabad, India - Stock Market Prediction Using Machine Learning.
[9] Asset Durmagambetov currently works at the mathematics, CNTFI. Asset does
research in Theory of Computation and Computing in Mathematics, Natural
Science, Engineering and Medicine. Their current project is 'The Riemann
Hypothesis-Millennium Prize Problems' - stock market predictions.
[11] Manh Ha Duong Boriss Siliverstovs June 2006 - The Stock Market and
Investment.
60
[13] Lufuno Ronald Marwala A dissertation submitted to the Faculty of Engineering
and the Built Environment, University of the Witwatersrand, Johannesburg, in
fulfilment of the requirements for the degree of Master of Science in Engineering -
Forecasting the Stock Market Index Using Artificial Intelligence Techniques.
[16] Xiao Ding, Kuo Liao, Ting Liu, Zhongyang Li, Junwen Duan Research Center for
Social Computing and Information Retrieval Harbin Institute of Technology,
China - Event Representation Learning Enhanced with External Commonsense
Knowledge.
[18] Hyeong Kyu Choi, B.A Student Dept. of Business Administration Korea
University Seoul, Korea = Stock Price Correlation Coefficient Prediction with
ARIMA-LSTM Hybrid Model.
61
[21] M. Mekayel Anik · M. Shamsul Arefin (B) Department of Computer Science and
Engineering, Chittagong University of Engineering and Technology, Chittagong,
Bangladesh - An Intelligent Technique for Stock Market Prediction.
Batch no: 9C
Team members:
(N D S S KIRAN RELANGI)
Abstract
Predicting stock market is one of the most difficult tasks in the field of computation. There are many factors
involved in the prediction – physical factors vs. physiological, rational and irrational behavior, investor
sentiment, market rumors,etc. All these aspects combine to make stock prices volatile and very difficult to
predict with a high degree of accuracy. We investigate data analysis as a game changer in this domain.As
per efficient market theory when all information related to a company and stock market events are instantly
available to all stakeholders/market investors, then the effects of those events already embed themselves in
the stock price. So, it is said that only the historical spot price carries the impact of all other market events
and can be employed to predict its future movement. Hence, considering the past stock price as the final
manifestation of all impacting factors we employ Machine Learning (ML) techniques on historical stock
price data to infer future trend. ML techniques have the potential to unearth patterns and insights we didn’t
see before, and these can be used to make unerringly accurate predictions. We propose a framework using
LSTM (Long Short- Term Memory) model and companies’ net growth calculation algorithm to analyze as
well as prediction of future growth of a company.
1 Introduction
Data analysis have been used in all business for data-driven decision making. In share market, there are
many factors that drive the share price, and the pattern of the change of price is not regular. This is why it is
tough to take a robust decision on future price. Artificial Neural Network (ANN) has the capability to learn
from the past data and make the decision over future. Deep learning networks
Q. Yuan, Y. Shi, L. Miller, G. Lee, G. Hu and T. Goto (eds.), CAINE 2019 (EPiC Series in Computing, vol. 63), pp.
101–110
63
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
such as Convolutional Neural Network (CNN), Recurrent Neural Network (RNN) etc. works great with
multivariate time series data. We train our model from the past stock data and calculate the future price of
that stock. This future price use to calculate the future growth of a company. Moreover, we found a future
growth curve from different companies. Thus we can analyze and investigate the similarity of one
company’s future curve over another. Stock price of a listed company in a stock exchange varies every time
an order is placed for sell or buy and a transaction completes. An exchange collects all sell bids with
expected price per stock (normally it is more than the price paid while bought by the investor) and all buy
bids with or without a price limit (normally an investor expects the future price of the stock will be more
than the current price he is paying now) and a buy- sell transaction is committed when both bids have a
match i.e. selling bid price is same with buying bid price of some buy-bid Fama in 1970 [1] proposed
efficient market hypothesis which says that in an efficient market (where all events are known to all
stakeholders as an when it happens) the effect all market events are already incorporated in stock prices
hence it is not possible to predict using past events or prices. The stock price of a company depends on many
intrinsic as well as extrinsic attributes. Macro-economic conditions too play an important role in growth or
decline of a sector as a whole. Some of the intrinsic factors could be company’s net profit, liabilities,
demand stability, competion in market, technically advanced assembly line, surplus cash for adverse
situations, stakes in raw material supplier and finished product distributors etc. Those factors that are beyond
the control of the company such as crude oil price, dollar exchange rate, political stability, government
policy decision etc. come under extrinsic attribute. Many researchers have tried using the historical stock
prices as the basis for time series analysis to forecast future stock prices. Many different statistical models
were applied since long like moving average (MA), autoregression (AR), weighted moving average,
ARIMA, CARIMA etc. Later some non linear models were also tried like GARCH. Recently different
neural network models, evolutionary algorithms wre being applied for stock prediction with success. Deep
neural networks like CNN, RNN are also used with different parsmeter settings and features. In this paper
we shall explore a special type of RNN known as LSTM to predict future company growth based on past
stock prices.
64
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
3 Related Studies
There are lots of research work in stock market prediction as well as in LSTM. Almost every data mining
and prediction techniques were applied for prediction of stock prices. Many different features and attributes
were used for the same purpose. There are three main categories of stock market analysis and prediction
such as (a) Fundamental analysis, (b) Technical analysis and (c) Time series analysis. Most of the stock
forecasting techniques with time series data normally use either a linear such as AR, MA, ARIMA, ARMA,
CARIMA, etc. [1],[2] or non-linear models (ARCH, GARCH, ANN, RNN, LSTM, etc.).Authors in [3] have
analyzed many different macro-economic factors by designing a data warehouse that affects share price
movement such as crude oil price, exchange rate, gold price, bank interest rate, political stability, etc.
Researchers in [4] employed frequent itemset mining technique to find a lagged correlation between price
movement between different sectorial index in Indian share market. Roondiwala et al. in [5] has used RNN-
LSTM model on NIFTY-50 stocks with 4 features (high/close/open/low price of each day). They have used
21 days window to predict the next day price movement. A total of 5 years data has been used for prediction
and RMSE as error metric to minimize with backpropagation.
Kim et al. in [6] proposed a model, ‘the feature fusion long short-term memory-convolutional neural
network
(LSTM-CNN) model’. They have used CNN to learn the features from stock chart images. They found that
the candlestick charts are the best candidate for predicting future stock price movement. Next they employed
LSTM and fed with historical price data. They have tested on minute-wise stock price and used 30 minute
sliding window to forecast 35 th minute price. They have tested on S&P 500 ETF data with stock price and
trade volume using CNN. They use the CNN and LSTM individually on different representation of the same
data and then used the combined feature fusion model for the same purpose. It is observed that the combined
model outperforms individual models with less prediction error. Thus this work establishes the fact that
different representation of the same data (raw stock price and trade volume and stock chart image) with
combined models where each individual model is optimized for separate data format can learn more intrinsic
data dynamics and features which is alalogous to looking on the same object from different perspective
angles that gives new insight. Hiransha et al.in their paper [7], employed three different deep learning
network achitectures such as RNN, CNN and LSTM to forecast stock price using day wise past closing
prices. They have considered two company from IT sector (TCS and Infosys) and one from Pharma
sector(Cipla) for experiment. The uniqueness of the study is that they have trained the models using data
from a single company and used those models to predict future prices of five different stocks from NSE and
NYSE (Newyork Stock Exchange). They argued that linear models try to fit the data to the model but in
deep networks underlying dynamic of the stock prices are unearthed. As per their results CNN outperformed
all other models as well as classical linear models. The DNN could forecast NYSE listed companies even
though the model has learned from NSE dataset. The reason could be the similar inner dynamics of both the
stock exchanges. Gers & Schmidhuber proposed a variation of LSTM by introducing “peephole
connections” [18]. In this model the gate layers can look into the cell state. In another case the model
coupled forget and input gates. In this case, decision to add new information or to forget it is taken together.
It forgets only when it needs to input something in its place. This architecture inputs new values to the cell
state when it forgets anything older. Cho, et al. [19] proposed another popular LSTM variation known as the
Gated Recurrent Unit ( GRU). It aggregates both the forget and input gates into an “update gate.” The cell
state and hidden state are merged along with a few other minor modifications to make the final model more
simple than the original LSTM. Due to the above reason this model is becoming popular day by day. These
65
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
are by no means an exhaustive list of modified-LSTMs. There are many other variants such as Depth Gated
LSTMs by Yao, et al. [20]. Koutnik, et al. [21] proposed ‘Clockwork RNNs’ to tackle long-term
dependencies in a completely different manner.
4 LSTM Architecture
4.1 An overview of Recurrent Neural Network (RNN)
In a classical neural network, final outputs seldom act as an output for the next step but if we pay attention to
a real-world phenomenon, we observe that in many situations our final output depends not only the external
inputs but also on earlier output. For example, when humans read a book, understanding of each sentence
depends not only on the current list of words but also on the understanding of the previous sentence or on
the context that is created using past sentences. Humans don’t start their thinking from scratch every second.
As you read this essay, you understand each word based on your understanding of previous words. This
concept of ‘context’ or ‘persistence’ is not available with classical neural networks. Inability to use context-
based reasoning becomes a major limitation of traditional neural network. Recurrent neural networks (RNN)
are conceptualized to alleviate this limitation.RNN are networked with feedback loops within to allow
persistence of information. The Figure 1Error! Reference source not found. shows a simple RNN with a
feedback loop and its unrolled equivalent version side by side.
Initially (at time step t) for some input X t the RNN generates an output of h t. In the next time step (t+1) the
RNN takes two input Xt+1 and ht to generate the output ht+1. A loop allows information to be passed from one
step of the network to the next.
RNNs are not free from limitations though. When the ‘context’ is from near past it works great towards the
correct output. But when an RNN has to depend on a distant ‘context’ (i.e. something learned long past) to
produce correct output, it fails miserably. This limitation of the RNNs was discussed in great detail by
Hochreiter [8] and Bengio, et al. [9]. They also traced back to the fundamental aspects to understand why
RNNs may not work in long-term scenarios. The good news is that the LSTMs are designed to overcome the
above problem.
66
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
4.2 LSTM Networks
Hochreiter & Schmidhuber [10] introduced a special type of RNN which is capable of learning long term
dependencies. Later on many other researchers improved upon this pioneering work in [11]
[12] [13] [14]. LSTMs are perfected over the time to mitigate the long-term dependency issue. The evolution
and development of LSTM from RNNs areexplained in [15] [16].
Recurrent neural networks are in the form of a chain of repeating modules of the neural network. In standard
RNNs, this repeating module has a simple structure like a single tanh layer as shown in Figure 2.
LSTMs follow this chain-like structure, however the repeating module has a different structure. Instead of
having a single neural network layer, there are four layers, interacting in a very special way as shown in
Figure 3.
In Figure 3, every line represents an entire feature vector, from the output of one node to the inputs of others.
The pink circles represent pointwise operations, like vector addition, while the yellow boxes are learned
67
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
neural network layers. Lines merging denote concatenation, while a line forking denotes its content being
copied and the copies going to different locations.
68
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
Figure 4: stock market closing prices of TCS over a time period and polynomial(degree 4) regression line
Regression is found not to be very much useful here to compute the error values. Also, we found a problem
with curve fitting. The above graphs are showing a poor result in terms of curve fitting. This has a clear
justification.For time series data, such as text, signals, stock prices, etc. LSTM is better suited to learn
temporal patterns in deep neural networks. An LSTM solves the ‘vanishing gradient’ problem that exists in a
RNN while learning long-term dependencies with time series dataset with the use of memory cell (states)
and
(input and forget) gates. So, LSTM may be a better option for future prediction of the company’s share price
as well as growth.
5.2 Methodology
The purpose of our framework is to analyze which is the best time span to predict the future share price of a
company from a particular sector. Our objective is to predict the future price and calculate the future growth
of the company in the different time span. Then we analyze the prediction error for each company of
different sector. Based on that we conclude which time span is best for future prediction of that particular
sector. We first predict the future closing price of 5 different companies from some pre-decided sectors with
the help of LSTM. This prediction will be done on historical data & the future prediction will be done for 3-
month, 6month, 1 year & 3 years. In these four different time spans (3 & 6 months, 1 & 3 years), we
calculate the growth of those companies. Then by analyzing the deviations of closing price for each time
span, we took the resultant time span which has maximum growth, i.e. less error for the particular sector,
e.g. companies A, B, C, D & E from a sector S1 has more growth in 3-months’ time span of prediction then
we draw an conclusion that for sector S1, our framework gives the best prediction for next 3-months for that
particular sector. In our analysis, let’s consider we are using the data for Months. Then the weight of a
company is defined as: weight = 1/ (P ∗(P+1)/2)
In our case, month-wise weight (Yi) will be calculated using the following algorithm:
N:= M
weight := 1/(M*(M+1)/2) FOR i = 1 to M
Begin
Yi := weight * N ; /* Yi is the weight of previous ith month*/ Q = Q - 1;
i := i + 1 End
69
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
End FOR
Suppose the growth rate between different time periods is Gri where i=1 to M, considering current year as
0th year. Therefore, Gri is the growth rate of (i-1)th time period w.r.t its immediate earlier year
i.e. ith year. To maximize the impact of current growth over the growth of older year, we would develop
a mathematical formula stated below. Suppose the growth rates of a company are Gr1; Gr2…Grm
respectively from present to M years earlier.
Then the Company Net Growth Rate (CNGR) by the following formula.
Where CNGRj is the Company Net Growth Rate of the jth company (where j=1 to m)
Step3: Feature Selection: In this step, data attributes are chosen that are going to be fed to the neural
network.In this study Date & Close Price are chosen as selected features.
Step 4: Train the NN model: The NN model is trained by feeding the training dataset. The model is initiated
using random weights and biases. Proposed LSTM model consists of a sequential input layer followed by 3
LSTM layers and then a dense layer with activation. The output layer again consists of a dense layer with a
linear activation function.
Step5: Output Generation: The RNN generated output is compared with the target values and error
difference is calculated. The Backpropagation algorithm is used to minimize the error difference by
adjusting the biases and weights of the neural network.
Step 6: Test Dataset Update: Step 2 is repeated for the test data set.
70
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
Step 7: Error and companies’ net growth calculation: By calculating deviation we check the percentage of
error of our prediction with respect to actual price.
Step 8: Visualization: Using Keras[21] and their function APIs the prediction is visualized.
Step 9: Investigate different time interval: We repeated this process to predict the price at different time
intervals. For our case, we took 2-month dataset as training to predict 3-month, 6-month, 1 year & 3 years of
close price of the share. In this different time span, we calculate the percentage of error in the future
prediction. This would be different for different sectors. So, this will help to find a frame for the particular
sector to predict future companies’ net growth.
6 Results
The proposed LSTM based model is implemented using Python. In Table 1 the Error value for different
companies belong to Banking Sector based on the historical data of 1 month, 3 month, 6 month, 1 Year, 3
Year span is shown.
71
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
7 Conclusions
In this paper, we analyze the growth of the companies from different sector and try to find out which is the
best time span for predicting the future price of the share. So, this draws an important conclusion that
companies from a certain sector have the same dependencies as well as the same growth rate. The prediction
can be more accurate if the model will train with a greater number of data set.
Moreover, in the case of prediction of various shares, there may be some scope of specific business analysis.
We can study the different pattern of the share price of different sectors and can analyze a graph with more
different time span to fine tune the accuracy. This framework broadly helps in market analysis and
prediction of growth of different companies in different time spans. Incorporating other parameters (e.g.
investor sentiment, election outcome, geopolitical stability) that are not directly correlated with the closing
price may improve the prediction accuracy.
References
[1] F. a. o. Eugene, "Efficient capital markets: a review of theory and empirical work," Journal of finance, vol.
25, no. 2, pp. 383-417, 1970.
[2] Z. A. Farhath, B. Arputhamary and L. Arockiam, "A Survey on ARIMA Forecasting Using Time Series
Model," Int. J. Comput. Sci. Mobile Comput, vol. 5, pp. 104-109, 2016.
[3] S. Wichaidit and S. Kittitornkun, "Predicting SET50 stock prices using CARIMA (cross correlation
ARIMA)," in 2015 International Computer Science and Engineering Conference (ICSEC), IEEE, 2015, pp.
1-4.
[4] D. Mondal, G. Maji, T. Goto, N. C. Debnath and S. Sen, "A Data Warehouse Based Modelling Technique
for Stock Market Analysis," International Journal of Engineering & Technology, vol. 3, no. 13, pp. 165-
170, 2018.
[5] G. Maji, S. Sen and A. Sarkar, "Share Market Sectoral Indices Movement Forecast with Lagged
Correlation and Association Rule Mining," in International Conference on Computer Information
72
Stock Price Prediction Using LSTM on Indian Share Market A. Ghosh et al.
Systems and Industrial Management, Bialystok, Poland, Sprigner, 2017, pp. 327-340.
[6] M. Roondiwala, H. Patel and S. Varma, "Predicting stock prices using LSTM," International Journal
of Science and Research (IJSR), vol. 6, no. 4, pp. 1754-1756, 2017.
[7] T. Kim and H. Y. Kim, "Forecasting stock prices with a feature fusion LSTM-CNN model using
different representations of the same data," PloS one, vol. 14, no. 2, p. e0212320, April 2019.
[8] S. Selvin, R. Vinayakumar, E. A. Gopalkrishnan, V. K. Menon and K. P. Soman, "Stock price
prediction using LSTM, RNN and CNN-sliding window model," in International Conference on
Advances in Computing, Communications and Informatics, 2017.
[9] S. Hochreiter, "Untersuchungen zu dynamischen neuronalen Netzen," Diploma, Technische
Universität München, vol. 91, no. 1, 1991.
[10] Y. Bengio, P. Simard, P. Frasconi and others, "Learning long-term dependencies with gradient
descent is difficult," IEEE transactions on neural networks, vol. 5, no. 2, pp. 157-166, 1994.
[11] S. Hochreiter and J. Schmidhuber, "LSTM can solve hard long time lag problems," in Advances in
neural information processing systems, NIPS, 1997, pp. 473--479.
[12] S. Hochreiter, "The vanishing gradient problem during learning recurrent neural nets and problem
solutions," International Journal of Uncertainty, Fuzziness and Knowledge-Based Systems, vol. 6,
no. 2, pp. 107-116, 1998.
[13] J. Schmidhuber, D. Wierstra, M. Gagliolo and F. Gomez, "Training recurrent networks by evolino,"
Neural computation, vol. 19, no. 3, pp. 757-779, 2007.
[14] L. Pasa and A. Sperduti, "Pre-training of recurrent neural networks via linear autoencoders," in
Advances in Neural Information Processing Systems, NIPS, 2014, pp. 3572-3580.
[15] J. Chen and N. S. Chaudhari, "Segmented-memory recurrent neural networks," IEEE transactions
on neural networks, vol. 20, no. 8, pp. 1267-1280, 2009.
[16] S. Hochreiter and J. Schmidhuber, "Long short-term memory," Neural computation, vol. 9, no. 8,
pp. 1735-1780, 1997.
[17] R. S. Sutton and A. G. Barto, Reinforcement learning: An introduction, MIT Press, 2018.
[18] F. A. Gers and J. Schmidhuber, "Recurrent nets that time and count," in Proceedings of the
IEEEINNS-ENNS International Joint Conference on Neural Networks. IJCNN 2000. Neural
Computing: New Challenges and Perspectives for the New Millennium, IEEE, 2000, pp. 189- 194.
70
Mukth Shabd Journal
ISSN NO: 2347-3150
Scientific Journal Impact Factor – 4.6
Dear Author,
With reference to your paper submitted “ STOCK PRICE PREDICTION USING LSTM” we are pleased to accept
the same for publication in MSJ Volume X, Issue VI, JUNE 2021.
Please send the scanned Copyright form and Registration form along with bank receipt of an online
maintenance/processing fee of 2000 INR Per paper. Please note that the amount we are charging is very nominal & only
an online maintenance and processing fee.
Note:
Paper will be published online with in 24 hours after receiving the fee.
*Fee Paid for the Publication of the paper does not refund under any circumstances
*In case of any query please do not hesitate to contact us at submitmsj@gmail.com Early reply is appreciated.
DATE
17-JUNE-2021
Sincerely,
Best regards,
M. ASHITOSH MEHATA
http://shabdbooks.com/
71
Mukt Shabd ISSN NO : 2347-3150
Abstract
Stock price prediction is the most significantly used in the financial sector. Stock market is volatile
in nature, so it is difficult to predict stock prices. This is a time series problem. Stock price
prediction is a difficult task where there are no rules to predict the price of the stock in the stock
market. There are so many existing methods for predicting stock prices. The prediction methods
are Logistic Regression Model, SVM, ARCH model, RNN, CNN, Backpropagation, Naïve Bayes,
ARIMA model, etc. In these models, Long Short-Term Memory (LSTM) is the most suitable
algorithm for time series problems. The main objective is to forecast the current market trends and
could predict the stock prices accurately. We use LSTM recurrent neural networks to predict the
stock prices accurately. The results show that prediction accuracy is over 93%.
Keywords: LSTM, CNN, ML, DL, Trade Open, Trade Close, Trade Low, Trade High.
1. INTRODUCTION
Stock market prediction means forecasting the current trends of a company and predict the value
of stocks whether it’s going up or down. Stock market is the place where a company’s shares are
traded. A stock is an investment in an institution where it represents ownership in a company.
Stock market is a place where those stocks are purchased. Purchasing a stock of a company is
owning a small share of an institution.
we are predicting the stock prices using the machine learning algorithm to develop a model which
forecasts the stock price effectively based on the current market trends. We have used LSTM
recurrent neural networks to predict the stock prices accurately. You would find two types of
stocks, one of them was Intraday trading, which is known to us by the term day trading. Intraday
trading is that which means all positions are squared-off before the market closes then and there
and there would be no possibility of changing the ownership after the day end. LSTM's are very
important, as they are very powerful in sequence prediction problems because they could store
previous or past information. This is very important in stock prediction as we need to store and
read the previous stock information as well to forecast the stock prices accurately in the future.
The rest of the paper is organized as follows. Section 2 introduces the research status of stock price
prediction. Section 3 introduces the methodologies. Section 4 consists of the experimental results
and the analysis of the results. Section 5 concludes the paper.
predict the trend in stock prices (Osman Hegazy et al. 2013 [20]; V Kranthi Sai Reddy, 2018 [8]; a
Banerjee et al. 2020 [21]; Lufuno Ronald Marwala [13]). Random Walk Hypothesis which is
proposed by Horne, j. C et al 1997 [27] which is used to predict stock prices, Horne j.c [27] said
that the stock values are changes random and the past price values are not dependent on current
values. EMH is different from the Random walk hypothesis but the EMH works mainly on Short
term patterns for predicting stock prices.
Manh Ha Duong Boris's Siliverstovs, 2006 [11] search the abstraction between equity prices and
combined finances in Key Eu nations like UK and Germany. Acceleration in Eu nations
investments is apt to results successful even Stronger correlation between the different Eu nations
and equity prices. This operation may also lead to a merge in financial development between EU
nations, if advancements in stock markets affect real financial instruments, such as investing and
Consuming. Fahad Almudhaf et al, 2012 [22], tests the weak-form market efficiency of CIVETS
over the period 2002–2012. The random walk hypothesis process is used in CIVETS. In an
efficient stock market, the equity values must follow a random walk hypothesis, when it comes to
the future price, the values are changing randomly and unpredictable. Everyday returns for rising
and improved markets have been tested for random walks.
LSTM algorithm consists of a Recurrent Neural network to encode data. The algorithm inputs are
economic news headings infusion From Bloomberg and Reuters. Long Short- term Memory with
embedded layer and the LSTM with the automatic encoder in the stock market for predicting stock
values. The Xiongwen Pang et al [4]. Used an automatic encoder and embedded layer to
vectorizing the values by using LSTM layers. Correlation coefficients in stocks are selected
randomly and predicted using ARIMA and the neural network approach. In this RNN and LSTM
algorithms are implemented. M. Nabipour et al [17]. Used different machine learning and deep
learning algorithms for predicting stock values such as random forest, decision tree and neural
networks. LSTM gives the most accurate results and it has the best ability to fit. LSTM gives the
best results while predicting stock prices with the least error rate (Hyeong Kya Choi,2018 [16];
Huicheng Liu, 2018 [15]; M. Nabipour et al,2020 [17]; Xiongwen Pang et al, 2020 [4]).
Recently, Pranab Bhat, 2020 used convolution neural networks for predicting stock values, in this
model learning is finished by computing the mean square blunder for each consequent perception
and a model is picked that has the least mistake and high prescient power. In this paper, they are
utilizing CNN for anticipating stocks and incentives for the following day. Mohammad Mekayel
Anik et al, 2020 [23], implemented a linear regression algorithm for future stock price prediction.
In this they achieved their goals in predicting accuracy of the model is very good and it might be
used for predicting stock values. Xiao Ding et al. 2020 [14] used an easy and effective interface to
add common sense knowledge to the process while learning of events.
The LMS filter is a type of adaptive filter which is used for solving linear problems. The idea of
the filter is to find the filter coefficients and to minimize a system by reducing the least mean
square of the error value (Asep Juarna, 2017 [24]; Eleftherios Giovanis, 2018 [25]). They used a
hybrid model for predicting the stock values by using deep learning and ML methodologies and
they built a model using deep regression based on CNN. Here they used CNN for parameters,
thereby increase the no of loops will stabilize the validation loss. They also tested using DL and a
hybrid ML algorithm for stock price prediction. Vivek Rajput and Sarika Bobde [26] used
sentiment analysis from online posts or multimedia and data mining is used. In sentiment analysis,
they are trying to get emotion either positive or negative based on the textual information available
on social networks. sentiment analysis for predicting the stock market to get more accurate and
efficient results.
3. DATA COLLECTION
For the experimental study, we downloaded live datasets namely google, nifty, reliance, etc. from the
Yahoo Finance website (https://finance.yahoo.com/).
Sample Input
Table 3.1 Sample Input
Trade Trade Low Trade High Trade
Date Open Close
11-Jun-2021
2,524.92 2,498.29 2,526.99 2,513.93
10-Jun-2021 2,494.01 2,494.00 2,523.26 2,521.60
09-Jun-2021 2,499.50 2,487.33 2,505.00 2,491.40
08-Jun-2021 2,479.90 2,468.24 2,494.50 2,482.85
07-Jun-2021 2,451.32 2,441.07 2,468.00 2,466.09
04-Jun-2021 2,422.52 2,417.77 2,453.86 2,451.76
03-Jun-2021 2,395.02 2,382.83 2,409.75 2,404.61
02-Jun-2021 2,435.31 2,404.20 2,442.00 2,421.28
4. METHODOLOGIES
As shown in Fig. 4.1.1, the inputs to the current cell state (C t) is the previous hidden state (h t-1),
previous cell state (Ct-1) and present input (Xt). The cell consists of three gates i.e. forget gate,
input gate and output gate.
Forget Gate:
A forget gate will remove unnecessary data from the cell state.
• The information that is less important or not required for the LSTM to understand things
is removed by performing multiplication of hidden state by a sigmoid function.
• This step is necessary to optimize the performance of the model.
• It takes two inputs i.e., h (t-1) and xt, where h(t-1) is the previous cell hidden state output and
xt is the current cell input.
Input Gate:
1. This cell is responsible for regulating the data that is added to the cell from the
input. Forget gate is used to filter some input.
2. A vector is created by adding all the possible values from the previous cell hidden
state h(t-1) and current cell input X t by using the tanh function. The output of the tanh
function in the ranges of [-1, 1].
3. Finally, the outputs of sigmoid and tanh functions are multiplied and the output is
added to the cell state.
Output Gate:
• Tanh function is applied to the cell state to create a vector with all possible values.
• Sigmoid function is applied to previous cell hidden state h (t-1) and current cell input
xt to filter necessary data from the previous cell.
• Now, the outputs of sigmoid and tanh functions are multiplied and this output is sent
as a hidden state of the next cell.
Intermediate cell state (Ct) is obtained by the multiplication of Forget gate (F t) with previous cell state
(Ct-1). Then this intermediate state is added to the output of the input gate.
Ct = Ft * Ct-1 + It
Current hidden/output state is obtained by multiplying output gate and tanh of cell state.
ht = Ot * tanh(Ct)
Data Selection: The first step is to select data for an organization and split the data into training and
testing. we have used 75% for training and 25% for testing purposes.
Pre-processing of data: In pre-processing, we are selecting attributes required for the algorithm
and the remaining attributes are neglected. The selected attributes are Trade Open, Trade High,
Trade Low, Trade Close, Trade Volume. In pre-processing, we are using normalization to get
values in a particular range.
Prediction using LSTM: In this system, we are using the LSTM algorithm for predicting stock
values. Initially, the training data is passed through the system and train the model. Then in the
testing phase, the predicted values are compared with the actual values.
Evaluation: In the evaluation phase we are calculating the Accuracy, Mean Square Error (MSE) and
Root Mean Square Error (RMSE) values for comparison.
5. EXPERIMENTAL RESULTS
5.1 Google
Table 5.1.2 Google Epochs
epochs Accuracy MSE RMSE
10 93.00717 207.6578 14.41034
20 94.01166 156.3873 12.50549
30 95.64188 105.3248 10.26279
40 95.59026 99.17409 9.958619
50 96.99466 62.24641 7.88964
Fig 5.1.1 Google Graph
In the results, as we have shown in Fig 5.1.1, the graph shows Trade Close value for the google dataset.
In this graph blue line indicates the training data and the yellow color
shown is the predicted values from the test data. Table 5.1.2 shows the accuracy, MSE and RMSE values
for no of iterations (epochs).
5.2 Reliance
Above graph 5.2.1 shows Trade Close value for the Reliance dataset and table 5.2.2 shows the MSE,
RMSE and accuracy values for the Reliance dataset.
CONCLUSION
we are predicting the closing stock price of any given organization, we have developed an
application for predicting close stock price using LSTM algorithm. We have used datasets
belonging to Google, Nifty50, TCS, Infosys and Reliance Stocks and achieved above 93%
accuracy for these datasets. In the future, we can extend this application for predicting
cryptocurrency trading and also, we can add sentiment analysis for better predictions.
REFERENCES
[1] Stock Price Prediction Using LSTM on Indian Share Market by Achyut Ghosh, Soumik Bose1,
Giridhar Maji, Narayan C. Debnath, Soumya Sen
[3] Murtaza Roondiwala, Harshal Patel, Shraddha Varma, “Predicting Stock Prices Using LSTM” in
Undergraduate Engineering Students, Department of Information Technology, Mumbai University,
2015.
[4] Xiongwen Pang, Yanqiang Zhou, Pan Wang, Weiwei Lin, “An innovative neural network approach for
stock market prediction”, 2018
[5] Ishita Parmar, Navanshu Agarwal, Sheirsh Saxena, Ridam Arora, Shikhin Gupta, Himanshu Dhiman,
Lokesh Chouhan Department of Computer Science and Engineering National Institute of Technology,
Hamirpur – 177005, INDIA - Stock Market Prediction Using Machine Learning.
[6] Pranav Bhat Electronics and Telecommunication Department, Maharashtra Institute of Technology,
Pune. Savitribai Phule Pune University - A Machine Learning Model for Stock Market Prediction.
[7] Anurag Sinha Department of computer science, Student, Amity University Jharkhand Ranchi,
Jharkhand (India), 834001 - Stock Market Prediction Using Machine Learning.
[8] V Kranthi Sai Reddy Student, ECM, Sreenidhi Institute of Science and Technology, Hyderabad, India -
Stock Market Prediction Using Machine Learning.
[9] Asset Durmagambetov currently works at the mathematics, CNTFI- 'The Riemann Hypothesis-
Millennium Prize Problems' - stock market predictions.
[10] Mariam Moukalled Wassim El-Hajj Mohamad Jaber Computer Science Department American
University of Beirut - Automated Stock Price Prediction Using Machine Learning.
[11] Manh Ha Duong Boriss Siliverstovs June 2006 - The Stock Market and Investment.
[12] Dharmaraja Selvamuthu, Vineet Kumar and Abhishek Mishra Department of Mathematics, Indian
Institute of Technology Delhi, Hauz Khas, New Delhi 110016, India - Indian stock market prediction
using artificial neural networks on tick data.
[13] Lufuno Ronald Marwala A dissertation submitted to the Faculty of Engineering and the Built
Environment, University of the Witwatersrand, Johannesburg, in fulfilment of the requirements for the
degree of Master of Science in Engineering - Forecasting the Stock Market Index Using Artificial
Intelligence Techniques.
[14] Xiao Ding, Kuo Liao, Ting Liu, Zhongyang Li, Junwen Duan Research Centre for Social Computing
and Information Retrieval Harbin Institute of Technology, China - Event Representation Learning
Enhanced with External Common-sense Knowledge.
[15] Huicheng Liu Department of Electrical and Computer Engineering Queen’s University, Canada -
Leveraging Financial News for Stock Trend Prediction with Attention-Based Recurrent Neural
Network.
[16] Hyeong Kyu Choi, B.A Student Dept. of Business Administration Korea University Seoul, Korea =
Stock Price Correlation Coefficient Prediction with ARIMA-LSTM Hybrid Model.
[17] M. Nabipour Faculty of Mechanical Engineering, Tarbiat Modares University, 14115-143 Tehran, Iran;
Mojtaba.nabipour@modares.ac.ir - Deep Learning for Stock Market prediction.
[18] Lavanya Ra SRM Institute of Science and Technology | SRM · Department of Computer Science -
Stock Market Prediction.
[19] M. Mekayel Anik · M. Shamsul Arefin (B) Department of Computer Science and Engineering,
Chittagong University of Engineering and Technology, Chittagong, Bangladesh - An Intelligent
Technique for Stock Market Prediction.
[20] Osman Hegazy, Omar S. Soliman and Mustafa Abdul Salam Faculty of Computers and Informatics,
Cairo University, Egypt - A Machine Learning Model for Stock Market Prediction
[21] Sharanya Banerjee, Neha Dabeeru, R. Lavanya SRM Institute of Science and Technology, Chennai in
Computer Science and Engineering - Stock Market Prediction
[22] Fahad Almudhaf, Yaser A. Alkulaib from Kuwait University - Are Civets Stock Markets Predictable?
[23] Mohammad Mekayel Anik, Mohammad Shamsul Arefin and M. Ali Akber Dewan, Department of
Computer Science and Engineering - An Intelligent Technique for Stock Market Prediction
[24] Asep Juarna, Departemen of Informatics, Gunadarma University, Jakarta-Indonesia - ONE YEAR
STOCK PRICE PREDICTION AND ITS VALIDITY USING LEAST SQUARE METHOD IN
MATLAB
[25] Giovanis, Eleftherios - Applications of Least Mean Square (LMS) Algorithm Regression in TimeSeries
Analysis
[26] Vivek Rajput and Sarika Bobde - Stock market prediction using hybrid approach
[27] James C. Van Horne and George G. C. Parker – The Random-walk Theory: An Empirical Test