0% found this document useful (0 votes)
131 views12 pages

Enhancing Stock Market Prediction A Robust LSTM-DNN Model Analysis On 26 Real-Life Datasets

Uploaded by

banavathshilpa
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
0% found this document useful (0 votes)
131 views12 pages

Enhancing Stock Market Prediction A Robust LSTM-DNN Model Analysis On 26 Real-Life Datasets

Uploaded by

banavathshilpa
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/ 12

Received 2 July 2024, accepted 17 July 2024, date of publication 29 July 2024, date of current version 11 September 2024.

Digital Object Identifier 10.1109/ACCESS.2024.3434524

Enhancing Stock Market Prediction: A Robust


LSTM-DNN Model Analysis on 26
Real-Life Datasets
KHORSHED ALAM , (Member, IEEE), MAHBUBUL HAQ BHUIYAN ,
INJAMAM UL HAQUE , MD FAHAD MONIR , (Member, IEEE),
AND TAREM AHMED , (Senior Member, IEEE)
Department of Computer Science and Engineering, Independent University, Bangladesh (IUB), Dhaka 1212, Bangladesh
Corresponding author: Tarem Ahmed ([email protected])

ABSTRACT Predicting the closing price of the stock market with accuracy is highly uncertain and
volatile. Deep learning (DL) can analyze vast amounts of historical stock data to identify patterns and
correlations, aiding in predictive modeling. By learning from past market behavior, deep learning algorithms
can potentially forecast future price movements with some degree of accuracy. This research presents a
hybrid Long Short-Term Memory (LSTM) and Deep Neural Network (DNN) model designed to tackle
the complexities of stock market prediction, including market volatility and intricate patterns. Initially the
proposed model is being trained on Bajaj’s stock dataset. Getting noteworthy performance in single dataset
does not prove robustness of the model. The research validates the model’s robustness and scalability through
rigorous comparative analysis on 26 company’s stock datasets, achieving an average R-squared (R2) score
of 0.98606, a Mean Absolute Error (MAE) of 0.0210, and a Mean Squared Error (MSE) of 0.00111.
To assess the contribution of our proposed model, we retrained previously used deep learning models
alongside our new approach, utilizing a shared dataset for validation. Additionally, we provide ablation
study of LSTM-DNN model which provides insights into the individual contributions of each component
towards detecting closing price of stocks, offering valuable information for optimizing future stock market
prediction models. The model’s exceptional performance sets a new standard in stock market prediction,
offering promising implications for investors, traders, and financial analysts. Making our work available
open-source on https://github.com/codewithkhurshed/SMP-IUB can enhance its accessibility and promote
future research opportunities in stock market price prediction.

INDEX TERMS Neural networks, regression model, stock market analysis, stock market prediction, LSTM,
DNN.

I. INTRODUCTION intrinsically unexpected. Others disagree, and those that share


Stock market prediction is the attempt to predict the future this viewpoint have a range of strategies and technologies that
value of a company’s stock or other financial instrument apparently allow them to predict future pricing.
traded on an exchange [1]. An correct projection of a stock’s Predicting stock market trends demands intricate analysis
future price could result in a significant profit. According as it depends on multifaceted variables [2]. Its complexity
to efficient-market theory, stock prices accurately reflect all attracts attention due to its pivotal role in shaping financial
currently known information, and any price changes that decisions, yet its elusive nature underscores the challenge of
are not based on recently disclosed information are thus achieving consistent accuracy. Creating a prediction model
using deep learning for stock markets is challenging due to the
The associate editor coordinating the review of this manuscript and inherent volatility, non-linear patterns, and limited historical
approving it for publication was Sajid Ali . data’s inability to capture all market dynamics accurately.

2024 The Authors. This work is licensed under a Creative Commons Attribution 4.0 License.
VOLUME 12, 2024 For more information, see https://creativecommons.org/licenses/by/4.0/ 122757
K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

Additionally, market sentiment and external events further • By training and evaluating the LSTM-DNN model on a
complicate modeling. broader set of company stocks, the research contributes
In the realm of time series prediction analysis, numerous to the generalizability of its findings. This contrasts
conventional strategies rooted in statistical modeling have with previous studies that focus on a limited number
been introduced. Among these strategies are linear regres- of companies, thereby enhancing the applicability of
sion, auto-regression, and moving average, commonly encap- the proposed approach. To ensure contribution we
sulated in the Auto Regressive Moving Average (ARMA) compare our model’s performance with widely used
framework [6], [7]. ARMA emerges as a powerful tool DL approaches having a common dataset highlighted in
for handling time series data that unfolds over successive Table 3.
instances. This model amalgamates distinct features of the • Unlike previous studies focused solely on daily changes,
data through its auto-regressive component, which addresses this research extends the prediction timeframe to capture
one aspect, and the moving average component, which tends longer-term trends in stock prices by developing the
to another feature. Notable mentions include Auto Regres- proposed model on nifty 50 dataset (2000-2021). This
sive Conditional Heteroskedasticity (ARCH), Long-Short addresses a limitation highlighted in previous studies
Term Memory (LSTM) [3], [4], Bidirectional Long-Short and enhances the usefulness of the model for investors
Term Memory (BiLSTM), Convolutional Neural Network- and traders.
Bidirectional Long-Short Term Memory (CNN-BiSLSTM) • The research systematically addresses several limita-
based hybrid model [5] and Generalized Auto Regres- tions highlighted in section II. By conducting a thorough
sive Conditional Heteroskedasticity (GARCH) models [8]. comparative analysis, the study fills a critical gap
These models cater to the nuanced fluctuations in time identified by previous researchers who lacked such
series data. Consequently, a range of models has been comprehensive evaluations. This contributes to a more
proposed that demonstrate particular efficacy in forecast- nuanced understanding of the effectiveness of different
ing and dissecting volatility patterns [9]. This array of prediction models and techniques.
models play a pivotal role in learning time series data The paper is organized into several key sections that sys-
dynamics. tematically present the research findings and methodology.
We propose a LSTM-DNN model based custom architec- In Section II, we discuss previous work and their limita-
ture for predicting close to reality stock closing prices and tions. Section III covers the methodology of this research.
achieve a noteworthy accuracy on predicting stock prices on Furthermore, Section IV describes the performance of the
test data. The decision to use LSTM-DNN models for stock proposed model. In Section V, we discuss the connection
market prediction is driven by their ability to capture complex between potential profitability and our proposed model. In the
patterns, achieve superior predictive accuracy, demonstrate next section, we describe how our proposed model deals
robustness and scalability, and potentially be applied in real- with market volatility and intricate patterns. In Section VII,
time scenarios. DNNs are great at spotting complex, tricky we provide a discussion on why the LSTM-DNN model is
patterns in data, while LSTM networks are excellent at suitable for addressing application issues in stock market
figuring out what comes next in a sequence, which is perfect prediction. In Section VIII, we address limitations, and in
for time-based data like stock market data. When we combine Section IX, we discuss future work. Finally, we conclude our
these two together, we get the best of both models, allowing research in Section X.
us to find all the complex variable to predict future stock
price efficiently. The contribution of this study includes the II. PREVIOUS WORK
following: Predicting stock market trends and movements is a chal-
• The paper introduces a novel approach to stock market lenging task that has garnered significant attention due to
prediction by combining LSTM networks with DNNs. its potential implications in financial decision-making. The
This hybrid model capitalizes on the strengths of both study [10] proposes LSTM based prediction model for stock
architectures to enhance predictive accuracy. market prediction using nifty fifty datasets and achieves
• We propose a DNN-LSTM based custom architecture 83.88% accuracy. However, the study does not mention
for predicting stock prices which accurately on 26 com- comparisons with other forecasting models or methods.
pany’s datasets with an average of R-squared (R2) This makes it challenging to determine whether the LSTM
score of 0.98606, a MAE of 0.0210, and a MSE of model is genuinely superior to existing techniques. The
0.00111 shown in Table 2. Predicting stock closing price paper [11] presents a novel outlier mining algorithm is
which is close to reality in 26 real life datasets is unseen proposed to detect anomalies on the basis of volume sequence
with such notable performance in any previous studies. of high frequency tick-by tick data of stock market. Author
We validated this information from recent IEEE Access compared the algorithm’s performance with a traditional
review paper [18] which reviewed the performance of cluster analysis (like k-means) is a good step, but it does not
previous work related to stock market prediction domain guarantee that the novel algorithm is superior in all cases or
until September 2023. for all stocks.

122758 VOLUME 12, 2024


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

Authors in [12] propose an SVM based model to predict RNNs, specifically LSTM models, along with stock data and
stock price based on the efficient market hypothesis. They technical indicators for stock closing price prediction. PCA is
fetch the stock comments information from social media and used for dimension reduction, and optimization strategies like
then preprocessing the data to emotion vectors. However, Adam and Glorot uniform initialization are applied. The faces
the social media data can be noisy, containing irrelevant or challenges in accurately predicting stock market prices due
misleading information. It is crucial to ensure the data quality to high volatility. Authors from [27] and [28] uses machine
and address noise before drawing conclusions. Another learning approaches to predict stock market. However, these
paper [13] uses the Elman network to predict the opening models were trained on limited data samples which can
price of the stock market. The authors use a self-adapting not promise the robustness in terms of prone to sudden
form of the PSO method to improve network weights changes.
and thresholds. The optimized data, referred to as the
starting weight and threshold value, is then sent into the A. DEALING WITH LIMITATIONS
Elman network for training, resulting in the formation of a Our work addresses several limitations highlighted in previ-
prediction model for stock market opening prices based on the ous studies on stock market prediction. Firstly, we conduct
self-adapting variation PSO-Elman network. Although the a comparative analysis, contrasting our hybrid architecture
model’s fault tolerance is discussed, the study should focus based on LSTM-DNN model with existing techniques,
on how well the model performs when confronted with noisy addressing the concern raised by [10], which lacked such
or unpredictable data. comparisons. This comparison helps establish the superiority
The study [14] aimed to predict the daily price changes of of our proposed model. Secondly, while [11] focuses on
three major stocks traded on the Borsa Istanbul 100 index. outlier mining algorithms, our research emphasizes the
Technical indicators calculated using stock prices and importance of data quality and noise handling, particularly
dollar-gold prices were used as features for prediction. in the context of utilizing 26 real life company’s stock data
Class labels representing price changes were determined for stock market prediction. This ensures the robustness
based on the closing prices of the stocks. Two different and reliability of our predictive model, a point of concern
Convolutional Neural Network (CNN) models were trained raised by [12]. Moreover, our research extends the prediction
and evaluated using accuracy and Macro-average F1-score timeframe beyond just daily changes, aiming to capture
metrics. However, the study focused on daily price changes, longer-term trends in stock prices, thus addressing a limita-
which might not fully capture longer-term trends or sudden tion highlighted by [13]. Additionally, our work offers predic-
market movements. Another study at [15] suggests a method tions not only for daily price changes but also for longer-term
for predicting the closing price of stocks using autoencoder trends, addressing a limitation of studies that focus solely
long short-term memory (AE-LSTM) networks. However, on short-term predictions, as noted by [14]. By aiming to
the paper mentions predicting ‘‘daily’’ prices. If the model predict price movements over a longer period, our research
is only capable of short-term predictions, its usefulness could enhances the usefulness of our model for investors and
be limited for investors and traders looking to make longer- traders, contrary to the limited scope of prediction highlighted
term decisions. The study conducted in [20] examines Stock in [15]. Furthermore, our hybrid LSTM-DNN model is
Market Analysis and Prediction utilizing an LSTM-based trained and evaluated on a broader set of company stocks,
Approach. It reveals a considerable disparity between the contributing to the generalizability of its findings compared
predicted and actual stock prices. to studies that focus on a limited number of companies,
The study [23] proposes CNN-BiSLSTM based stock such as [20] and [23]. By conducting a comparative analysis
market price prediction model. However, it only predicts the on 26 company stocks, our research aims to enhance the
closing price of stock for the next trading day, limiting its generalizability of its findings compared to studies that
reference value for investment. Investors prefer to predict the focus on a limited number of companies, as mentioned
price and trend of the stock over a longer period, suggesting in [24]. Overall, our work provides a comprehensive approach
a limitation in the study’s timeframe for prediction. Authors to stock market prediction, addressing various limitations
from [24] proposed machine learning models (KNN, RF, observed in prior studies and contributing to a more robust
LR, GB) to predict the next day’s closing price of stocks understanding of predictive modeling in finance.
from three different companies, with evaluation based on
R2, RMSE, and MAE. The study [24] only focused on III. METHODOLOGY
three companies, which may limit the generalizability of Long Short-Term Memory (LSTM) [16] and Deep Neural
the findings to a broader range of companies in the stock Network (DNN) [17] based hybrid custom architecture is
market. The study [25] utilized Artificial Neural Network and used to develop for achieving this framework. This hybrid
Random Forest techniques for stock closing price prediction, approach It analyzes information in complex ways using
using financial data to create new variables as inputs, and advanced math modeling. Our framework is divided into the
evaluating the models with RMSE and MAPE. However, following three parts.
lack of discussion on specific limitations of machine learning The first one is Dataset Formation where we gather
models. The methodology proposed by [26] involves using stock market data from various datasets. Second one is
VOLUME 12, 2024 122759
K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

FIGURE 1. Comprehensive stock market prediction methodology.

FIGURE 2. Illustration of the sliding window approach for LSTM.


Data Preprocessing. In this part, to make the best out
of datasets, we preprocess our data with rolling window
TABLE 1. Model architecture.
approach algorithm. Last one is Model Development where
we develop a LSTM-DNN based deep learning model for
framework shown in Fig. 1.

A. DATASET FORMATION
In this study, we have collected Google’s Stock market data
from Kaggle, and we collected 25 company’s Data from
NIFTY-50 [13] Stock Market Data (2000 - 2021) Kaggle
repository. All of the stock data have 5303 data points in each
dataset. The data spans from 1st January 2000 to 30th April
2021.

B. DATA PREPROCESSING
The sliding window method in time series data preprocessing
involves iteratively segmenting the data into fixed-sized
windows shown in Fig 2. This method aids in capturing
changing patterns over time by creating overlapping or R-squared (R2) score of 0.981352, a Mean Absolute Error
non-overlapping segments, enabling analysis of temporal (MAE) of 0.0092, and a Validation MAE of 0.0114. Let us
dynamics and enhancing predictive modelling accuracy. begin by discussing the Model Architecture shown in Table 1.
The process involves creating input-output pairs from
historical data using a rolling window approach. Two lists 1) LONG SHORT-TERM MEMORY (LSTM)
store input and target sequences, respectively. The ‘‘window A Long Short-Term Memory network is a type of recurrent
size’’ variable is set to define the length of the rolling neural network that can hold over long-term input data
window. An outer loop iterates over data indices, forming sequences. LSTM is good for those problems where we rely
pairs within each window. The baseline value is stored for on long input data sequences.
normalization. An inner loop constructs the input sequence by In figure 3, ct−1 is the previous cell state where ct is the
calculating percentage changes for each data point. ‘‘temp2’’ next cell state. ht−1 is the previous hidden state and ht is the
calculates the percentage change for the next data point after next hidden state. xt are our current inputs. In our case it is
the window. The input and output sequences are appended to accelerometer data and timestamps.
lists as NumPy arrays, forming pairs for model training. Forget gate is a type of state where cell decides which
information must be keep or forget by taking the weights
C. MODEL DEVELOPMENT and biases with respect to xt in sigmoid activation function.
We propose a LSTM-DNN based hybrid model for predicting So that it can return values from 0 to 1. The closer to zero
future closing price of stock market and that ensures a means forget and the closer to 1 means keep.

122760 VOLUME 12, 2024


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

FIGURE 3. LSTM cell diagram.


FIGURE 4. Dense layer.

market price patterns from data. The dense layer also applies
Forget gate:
a linear transformation to the input data by multiplying it
ft = σ wfh · ht−1 + wfx · xt + bf

(1) by a weight and adding a bias, as shown in equation (8),
where w is the weight, x is the input data, and b is the
Input Gate: bias [30].
it = σ (wih · ht−1 + wix · xt + bi ) (2) y = xn · wn + bn (8)
Input Node: For the output layer, we utilize the SoftMax activation
gt = tanh wgh · ht−1 + wgx · xt + bg

(3) function layer demonstrated in equation (9), which is a
popular logistic function that accepts values 0 to 1. The
cti = it · gt (4) value closest to 1 approaches the final outcome. The z
ct = cti + ctf (5) represents the value of neurons derived from the output
layer.
Output gate:
ezi
ot = σ (woh · ht−1 + wox · xt + bo ) (6) softmax(zi ) = P zj (9)
je
ht = tanh(ct ) · ot (7)
The Flatten layer is mostly used to prepare data for
the Dense levels that follow. The Flatten layer handles
In the case of LSTM, the process is characterized by this conversion by ‘‘flattening’’ the output, yielding a one-
selective memory enhancement. It starts with the current dimensional representation. We use a linear activation to keep
cell state, denoted as ct . To determine this new cell state, outputs unscaled, optimizes learning with the Adam method,
LSTM considers various factors, including the input states and measures performance with Mean Squared Error (MSE)
xt and ht−1 , which represent the incoming data and context and Mean Absolute Error (MAE). The model is trained for
from the previous time step. Crucially, LSTM leverages a 100 epochs on batches of 50 examples, with progress tracked
forget gate that outputs cti and a corresponding forget gate and reported. We use Adaptive Moment Estimation (Adam)
signal ft . These components enable LSTM to decide which [31] optimizer as it is a popular optimization algorithm
information from the previous cell state should be retained widely used in training deep neural networks. It combines the
and which should be discarded. By adding cti & ft the next cell concepts of momentum and adaptive learning rates to achieve
state ct is obtained. Additionally, LSTM calculates an input faster convergence during training. The batch size is set to 64.
gate it and an input node gt using sigmoid and tanh activation Batch size refers to the number of training examples used in
functions, respectively, to determine what new information a single iteration or update of the model’s parameters during
should be added to the cell state. The output state ot is the optimization process. The epoch is set to 100 and ut refers
derived by considering the inputs xt and ht−1 , followed by to a single pass through the entire training dataset during the
the next hidden state ht , which is generated by applying a tanh optimization process.
activation function to the current cell state ct and combining
it with the output gate ot . This intricate process allows LSTM IV. PERFORMANCE ANALYSIS
to selectively update calendar information by fine-tuning the Based on our analysis, our model performs better in
cell state while maintaining the context. predicting future closing price of stock market in 26 stock
market datasets and that ensures an average of R-squared
2) DEEP NEURAL NETWORK (DNN) (R2) score of 0.98606, a MAE of 0.0210, and a MSE of
The DNN part of our model consists of Dense, Activation 0.00111. To validate this performance, we run our trained
layers. Dense layers are commonly used to turn input train model against test data to see if it is sufficiently capable to
data into a high-dimensional feature space. It helps in the predict proper labels from unseen data. Table 2 serves as
effective learning of complex features of underlying stock compelling evidence of the robustness of the LSTM-DNN

VOLUME 12, 2024 122761


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

prices with lower errors and greater accuracy. The high


R2 score demonstrates its superior predictive power and
efficiency in handling the dataset. By improving these
metrics, the proposed model likely offers a more reliable
and robust tool for investors and analysts in predicting
stock market trends. This can lead to more informed
decision-making and potentially higher investment returns.
In Fig. 5, the MSE score of all 26 datasets are shown.
Tables 4 - 8 in the provided data showcase the actual versus
predicted stock prices for various companies using neural
network models. Table 4 details predictions for Google’s
stock, showing that the model’s estimates closely match
FIGURE 5. MSC score accorss 26 datasets. the actual trading prices, indicating effective predictive
accuracy for this dataset. In Table 5, the actual and predicted
model in stock market prediction. The performance metrics prices for Asian Paints are also closely aligned, albeit the
displayed in the table, including Mean Squared Error (MSE), predictions are slightly higher, demonstrating good model
Mean Absolute Error (MAE), R-squared (R2) score, and performance. Table 6, which pertains to HDFC Bank, follows
Max Error, demonstrate the model’s ability to accurately a similar trend with predictions modestly overestimating
forecast stock prices across a diverse range of datasets the actual prices. Table 7 for Bharat Petroleum Corporation
from different companies. The consistently low MSE and Limited (BPCL) and Table 8 for Hero MotoCorp exhibit
MAE values indicate that the model effectively minimizes minimal deviations between predicted and actual prices,
errors in its predictions, showcasing its precision and with the model generally tending to slightly overestimate.
reliability in capturing the underlying patterns in the data. Overall, these tables collectively demonstrate the capability
Moreover, the high R2 scores across multiple datasets of neural network models to generate relatively accurate
signify that a significant proportion of the variance in stock stock price forecasts, albeit with room for fine-tuning to
prices is explained by the model, highlighting its strong further minimize the differences between predicted and actual
predictive capabilities and ability to generalize well to unseen values.
data.
Furthermore, the relatively low Max Error values suggest A. PERFORMANCE METRICS
that the model performs well even in scenarios where the We use Mean Square Error, R-squared score, Mean Absolute
prediction deviates from the actual value, showcasing its Error and Maximum error as performance metrics [29]. The
resilience to outliers and extreme fluctuations in stock prices. rationale behind using Mean Absolute Error (MAE), Mean
By achieving impressive results across various datasets, Squared Error (MSE), R-squared (R2) Score, and Maximum
the LSTM-DNN model demonstrates its adaptability and Error metrics to evaluate the model’s performance in stock
effectiveness in handling different market conditions and market prediction lies in their complementary nature in
company-specific trends. This consistency in performance assessing different aspects of the model’s predictive capabili-
underscores the model’s robustness and its potential to ties. MAE provides a straightforward measure of the average
provide valuable insights for investors and traders seeking prediction error, offering insights into the model’s accuracy in
accurate and reliable stock market predictions. The overall predicting stock prices. MSE, on the other hand, emphasizes
aim of these graphs in Fig. 6 and 7 are likely to assess the the squared errors, giving more weight to larger deviations
performance of a stock price prediction model. The closeness between predicted and actual values and providing a measure
of the predicted prices to the actual prices indicates the of overall variance. The R2 score indicates how well the
model’s accuracy. In each case, the yellow line (predicted model explains the variability in stock prices, offering a
price) attempts to follow the green line (actual price), and the measure of the model’s goodness of fit. Additionally, the
degree of overlap would typically be used to evaluate how Maximum Error metric highlights the worst-case scenario in
well the model is performing. terms of prediction accuracy, identifying potential outliers
Table 3 and Fig. 8 presents a comparative performance or extreme errors. By considering these metrics together,
analysis of various neural network models used in past study researchers can gain a comprehensive understanding of the
to predict stock market trends, specifically using the Asian model’s performance, including accuracy, variance, goodness
Paint’s stock market dataset. The models compared include a of fit, and outlier detection, which collectively contribute to
CNN-BiLSTM model, a standard LSTM model, a BiLSTM assessing the model’s effectiveness in predicting stock market
model, and the proposed model by the authors. The metrics trends accurately and reliably. Let us discuss the performance
used for comparison are Mean Squared Error (MSE), Mean matrix one by one. Mean Square Error (MSE) is a common
Absolute Error (MAE), R2 Score, and Maximum Error. metric used to evaluate the accuracy of a predictive model.
The proposed model provides a significant improvement It is particularly popular in regression analysis, where the
in both MSE and MAE, suggesting it can predict stock goal is to predict a continuous outcome. MSE measures the

122762 VOLUME 12, 2024


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

TABLE 2. Performance analysis of our model with other datasets.

TABLE 3. Performance analysis of our model with other neural network TABLE 6. Actual vs predicted in HDFC Bank’s stock dataset.
models in asian paint’s stock market dataset.

TABLE 4. Actual vs predicted in GOOGLE’s stock dataset.

TABLE 7. Actual vs predicted in BPCL’s stock dataset.

TABLE 5. Actual vs predicted in ASIAN PAINT’s stock dataset.

MSE.
n
1X
MSE = (actual − predicted)2 (10)
n
i=1
The R-squared (R2) score is a statistical measure that
represents the proportion of the variance in the dependent
average squared difference between the predicted values and variable (target) that is explained by the independent variables
the actual values. We use this equation (10) to calculate (features) in a regression model. It is a measure of how

VOLUME 12, 2024 122763


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

TABLE 8. Actual vs predicted in HERO MOTORS CO’s stock dataset.

FIGURE 7. Actual vs predicted stock price (lr=0.001, batch=100,


opt=adam).

FIGURE 6. Actual vs predicted stock price (lr=0.001, batch=100,


opt=adam).

well the independent variables explain the variability of


the dependent variable. We calculate R2 score by using
equation (11). The R2 score ranges from 0 to 1, where: FIGURE 8. R2 score and Max error score (proposed model vs widely used
models).
• 0 indicates that the model does not explain any of the
variability in the target variable.
• 1 indicates that the model perfectly explains the performance metrics presented in Table 2 of this paper,
variability in the target variable. which includes Mean Squared Error (MSE), Mean Absolute
Pn Error (MAE), R-squared (R2) Score, and Maximum Error.
2 (actual − predicted)2 These metrics serve as key indicators of the model’s
R = 1 − Pn i=1 2
(11)
i=1 (actual − mean of actual)
potential profitability by assessing its ability to make
precise predictions and minimize errors in forecasting stock
MAE, or Mean Absolute Error, is a metric commonly used
prices.
to evaluate the accuracy of a predictive model, particularly
Moreover, a deeper insight into the model’s profitability
in regression analysis. It measures the average absolute
can be gained by examining the actual versus predicted stock
difference between the predicted values and the actual values.
prices in Tables 4, 5, 6, 7, and 8. Table 4 illustrates the close
The formula for MAE is as follows equation (12):
alignment between predicted and actual prices for Google’s
n
1X stock dataset, indicating the model’s accuracy in forecasting.
MAE = |actual − predicted| (12) Similarly, Table 5 shows consistent predictions for Asian
n
i=1 Paints’ stock, although slightly higher, suggesting good
model performance and potential profitability. In Table 6,
V. UNDERSTANDING THE PROFITABILITY POTENTIAL OF focusing on HDFC Bank’s stock dataset, the model’s
PROPOSED MODEL predictions modestly overestimate actual prices, yet maintain
The potential profitability of the proposed LSTM-DNN a reasonable level of accuracy, highlighting its profitabil-
model in stock market prediction can be supported by the ity potential. Table 7 for Bharat Petroleum Corporation

122764 VOLUME 12, 2024


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

Limited (BPCL) and Table 8 for Hero MotoCorp exhibit combination enables the model to effectively capture the
minimal deviations between predicted and actual prices, distinct features of market volatility and intricate patterns,
with the model generally slightly overestimating, further leading to more accurate and reliable predictions in stock
emphasizing its reliability and profitability in stock market market forecasting from real life company stock data. This
forecasting. combination allows the model to adapt to volatile market
The impressive performance metrics in Table 2, such as conditions, identify complex patterns in the data, and make
low MSE and MAE values alongside high R2 scores, indicate informed predictions that account for the intricacies of stock
the model’s capability to generate accurate predictions with market dynamics.
minimal deviation from actual stock prices, essential for
profitable trading decisions. The model’s resilience to outliers VII. DISCUSSION
and extreme fluctuations, as evidenced by low Maximum The LSTM-DNN model stands out as a highly effective
Error values, further enhances its profitability potential by solution for tackling the intricate challenges involved in
ensuring reliable forecasts in dynamic market conditions. predicting stock market movements. This hybrid architecture
By combining the robust performance metrics from Table 2 combines the strengths of LSTM networks, renowned
with the actual versus predicted stock prices in Tables 4-8, for their capability to capture temporal dependencies and
stakeholders can gain a comprehensive understanding of patterns over time, with DNNs, which excel in extracting
the LSTM-DNN model’s profitability and effectiveness complex features and patterns from extensive datasets.
in guiding investment decisions. The model’s accuracy, Stock market data is inherently nonlinear and influenced
consistency in predictions, and ability to minimize errors by numerous factors, including economic indicators, market
underscore its potential to provide valuable insights for sentiment, and geopolitical events. LSTM networks are
investors and traders seeking profitable opportunities in the particularly well-suited for this task due to their ability
stock market. to learn and retain long-term dependencies in sequential
data.
VI. DEALING WITH MARKET VOLATILITY AND INTRICATE In the realm of stock market prediction, where accurate
PATTERNS forecasting is crucial for informed decision-making, the
The LSTM-DNN proposed model effectively addresses LSTM-DNN model’s ability to capture these sequential
market volatility and intricate patterns in stock market dependencies plays a pivotal role. By discerning subtle
prediction through its advanced architecture and training trends and seasonal variations in stock prices, the model
methodology. Specifically, the LSTM component of the enhances predictive accuracy and provides valuable insights
model plays a crucial role in capturing and retaining into market dynamics. This is underscored by its robust
long-term dependencies in the data, allowing the model to performance across 26 real-life company datasets, achieving
remember important information over extended periods. This an average R-squared (R2) score of 0.98606, Mean Absolute
capability is particularly valuable in the context of market Error (MAE) of 0.0210, and Mean Squared Error (MSE)
volatility, where sudden and significant price fluctuations of 0.00111. Such results highlight the model’s reliability
occur. By utilizing LSTM networks, the model can effectively and effectiveness in handling diverse market conditions and
learn and adapt to these volatile market conditions, enabling dataset complexities.
it to make more informed predictions even in the presence of Moreover, the LSTM-DNN model addresses key lim-
rapid changes. itations observed in previous research. Unlike traditional
Additionally, the DNN component of the model excels at methods that often struggle with noise in data or fail to capture
identifying complex patterns within the data as described in long-term trends effectively discussed in Section II-A,
Section III-C, including subtle trends and correlations that this hybrid approach extends prediction timeframes and
may not be immediately apparent. This aspect is essential emphasizes robust data handling techniques. By utilizing the
for handling intricate patterns in stock market data, where complementary strengths of LSTM networks for sequential
multiple variables and factors can influence price movements. pattern recognition and DNNs for feature extraction from
The DNN component’s ability to analyze large datasets and large-scale datasets, the model demonstrates superior gen-
extract meaningful features allows the model to uncover eralizability and performance consistency across different
hidden relationships and make more accurate predictions stocks and market scenarios.
based on these intricate patterns.
Furthermore, the integration of LSTM and DNN archi- VIII. LIMITATIONS
tectures in a hybrid model combines the strengths of Despite the promising results of our custom hybrid archi-
both approaches, enhancing the model’s overall predictive tecture based on LSTM and DNN model, it is impor-
capabilities. The LSTM component provides the model tant to acknowledge its limitations. Although the model
with the ability to understand temporal dynamics and long- demonstrates considerable robustness across a wide range of
term dependencies, while the DNN component enhances its datasets, its performance is still susceptible to variations in
pattern recognition and feature extraction capabilities. This the quality and granularity of the input data. For instance,

VOLUME 12, 2024 122765


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

the presence of anomalies in market data, such as missing market conditions, offering valuable insights for investors and
values, inaccuracies in financial reports, or inconsistencies traders.
in historical records can significantly hamper the model’s
predictive accuracy. X. CONCLUSION
In financial markets, data integrity is most important. This research on enhancing stock market prediction through
Inconsistency or errors in data can arise from various sources, a hybrid LSTM-DNN based custom architecture represents
including reporting delays, typographical errors in financial a significant advancement in the field of financial analytics.
statements, and gaps in data collection. When such issues By introducing an innovative hybrid model that combines
are present, the model’s ability to generate reliable forecasts the strengths of LSTM and DNN architectures, the study
may be compromised. This is because machine learning has demonstrated remarkable adaptability and consistency
models, including our hybrid LSTM-DNN, heavily rely on across diverse datasets and company-specific trends. Through
the assumption that the input data is both accurate and rigorous evaluation using metrics such as MAE, MSE,
complete. Any deviation from this assumption can lead to R2 Score, and Maximum Error, the model has showcased
erroneous predictions. its accuracy, variance explanation, goodness of fit, and
Furthermore, the granularity of the data also plays a crucial outlier resilience, highlighting its robust performance in
role. High-frequency trading data, for example, provides predicting stock prices. The research not only addresses
a very different landscape compared to end-of-day market limitations observed in previous studies but also extends the
summaries. If the model is trained on one type of data but prediction timeframe to capture longer-term trends, offering
deployed on another, discrepancies in performance may arise. valuable insights for investors and traders. By comparing the
The temporal resolution of input data–whether it is minute- proposed model with existing neural network approaches and
by-minute, hourly, or daily–can affect the model’s ability to showcasing significant improvements in predictive accuracy,
capture relevant patterns and trends, thereby impacting its the study underscores the model’s potential for guiding prof-
overall efficacy. itable investment decisions in dynamic market conditions.
In conclusion, while our hybrid LSTM-DNN model shows Overall, the research contributes to a deeper understanding
significant potential and robustness in diverse applications, of predictive modeling in finance, emphasizing the model’s
careful consideration must be given to the quality and adaptability, consistency, and profitability potential in stock
granularity of the input data. Ensuring high data quality and market forecasting.
appropriate temporal resolution is essential for maintaining
the model’s predictive power and reliability in real-world DATASET OBTAINED
financial forecasting. 1) https://www.kaggle.com/datasets/rohanrao/nifty50-
stock-market-data
IX. FUTURE WORK 2) https://www.kaggle.com/datasets/varpit94/google-
Implementing real-time prediction capabilities and adaptive stock-data
learning mechanisms for the hybrid LSTM-DNN model
involves several critical steps. Firstly, integrating real-time REFERENCES
data streams from financial data providers through APIs [1] Stock Market Prediction. Accessed: May 10, 2024. [Online]. Available:
and employing an event-driven architecture will ensure https://en.wikipedia.org/wiki/Stock_market_prediction
efficient handling of incoming market data. Developing a [2] Y. Li, L. Chen, C. Sun, G. Liu, C. Chen, and Y. Zhang, ‘‘Accurate
stock price forecasting based on deep learning and hierarchical frequency
robust data preprocessing pipeline will allow for real-time decomposition,’’ IEEE Access, vol. 12, pp. 49878–49894, 2024, doi:
cleaning and normalization. Deploying the model on scalable 10.1109/ACCESS.2024.3384430.
platforms like TensorFlow Serving or AWS SageMaker [3] A. Ruke, S. Gaikwad, G. Yadav, A. Buchade, S. Nimbarkar, and
A. Sonawane, ‘‘Predictive analysis of stock market trends: A
will enable low-latency predictions, supported by optimiza- machine learning approach,’’ in Proc. 4th Int. Conf. Data Eng.
tion techniques such as model quantization and hardware Commun. Syst. (ICDECS), Bangalore, India, Mar. 2024, pp. 1–6,
acceleration. Incorporating incremental learning and sliding doi: 10.1109/icdecs59733.2023.10503557.
[4] M. Yang and J. Wang, ‘‘Adaptability of financial time series prediction
window approaches will facilitate continuous model updates based on BiLSTM,’’ Proc. Comput. Sci., vol. 199, pp. 18–25, Jan. 2022,
with new data, ensuring adaptability to changing market doi: 10.1016/j.procs.2022.01.003.
trends. Continuous monitoring of performance metrics and [5] X. Zheng, ‘‘Stock price prediction based on CNN-BiLSTM utilizing
sentiment analysis and a two-layer attention mechanism,’’ Adv. Econ.,
automated retraining mechanisms will help maintain high Manage. Political Sci., vol. 47, no. 1, pp. 40–49, Dec. 2023, doi:
predictive accuracy. Additionally, leveraging cloud services 10.54254/2754-1169/47/20230369.
and distributed computing frameworks will ensure scalable [6] Y. Chen, J. Liu, Y. Gao, W. He, H. Li, G. Zhang, and H. Wei,
infrastructure, while real-time dashboards and alert systems ‘‘A new stock market analysis method based on evidential reasoning
and hierarchical belief rule base to support investment decision mak-
will provide valuable insights and timely notifications. ing,’’ Frontiers Psychol., vol. 14, Feb. 2023, Art. no. 1123578, doi:
Ensuring robust data security and compliance with financial 10.3389/fpsyg.2023.1123578.
regulations will be essential for ethical and legal use of [7] Y. Tong, J. Liu, L. Yu, L. Zhang, L. Sun, W. Li, X. Ning, J. Xu,
H. Qin, and Q. Cai, ‘‘Technology investigation on time series classification
the predictive models. This comprehensive approach will and prediction,’’ PeerJ Comput. Sci., vol. 8, p. 982, May 2022, doi:
enable the hybrid model to respond effectively to dynamic 10.7717/peerj-cs.982.

122766 VOLUME 12, 2024


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

[8] X. Zhang, ‘‘Research on CSI 300 index volatility based on GARCH [27] P. Amal, J. Rodrigues, R. R. Naik, K. M. C. Kumar, and P. Shetgaonkar,
model,’’ in Proc. 12th Int. Conf. Intell. Comput. Technol. Autom. ‘‘Stock market prediction using machine learning—A survey,’’ in Proc.
(ICICTA), Xiangtan, China, Oct. 2019, pp. 77–80, doi: 10.1109/ici- 3rd Int. Conf. Innov. Technol. (INOCON), Bangalore, India, Mar. 2024,
cta49267.2019.00023. pp. 1–7, doi: 10.1109/inocon60754.2024.10511901.
[9] E. Liu, ‘‘Comparison of stock price prediction ability based on GARCH [28] S. Dinushan and M. C. Wijegunasekara, ‘‘Machine learning-driven
and BP_ANN,’’ in Proc. 2nd Int. Conf. Comput. Data Sci. (CDS), sri Lankan stock market prediction: Harnessing economic indicators
Stanford, CA, USA, Jan. 2021, pp. 90–93, doi: 10.1109/cds52072.2021. and sentiment analysis,’’ in Proc. 4th Int. Conf. Adv. Res. Com-
00021. put. (ICARC), Belihuloya, Sri Lanka, Feb. 2024, pp. 61–66, doi:
[10] P. S. Sisodia, A. Gupta, Y. Kumar, and G. K. Ameta, ‘‘Stock market 10.1109/icarc61713.2024.10499774.
analysis and prediction for Nifty50 using LSTM deep learning approach,’’ [29] C. Sammut and G. I. Webb, Encyclopedia of Machine Learning. Berlin,
in Proc. 2nd Int. Conf. Innov. Practices Technol. Manag. (ICIPTM), Germany: Springer, 2010, doi: 10.1007/978-0-387-30164-8.
vol. 2, Gautam Buddha Nagar, India, Feb. 2022, pp. 156–161, doi: [30] V. E. Balas, S. S. Roy, D. Sharma, and P. Samui, Handbook of
10.1109/ICIPTM54933.2022.9754148. Deep Learning Applications. Berlin, Germany: Springer, 2019, doi:
[11] L. Zhao and L. Wang, ‘‘Price trend prediction of stock market 10.1007/978-3-030-11479-4.
using outlier data mining algorithm,’’ in Proc. IEEE 5th Int. Conf. [31] D. P. Kingma and J. Ba, ‘‘Adam: A method for stochastic optimization,’’
Big Data Cloud Comput., Dalian, China, Aug. 2015, pp. 93–98, doi: 2014, arXiv:1412.6980.
10.1109/BDCLOUD.2015.19.
[12] Y. Wang and Y. Wang, ‘‘Using social media mining technology to
assist in price prediction of stock market,’’ in Proc. IEEE Int. Conf.
Big Data Anal. (ICBDA), Hangzhou, China, Mar. 2016, pp. 1–4, doi:
10.1109/ICBDA.2016.7509794.
[13] Z. Zhang, Y. Shen, G. Zhang, Y. Song, and Y. Zhu, ‘‘Short-term
prediction for opening price of stock market based on self-adapting variant
PSO-Elman neural network,’’ in Proc. 8th IEEE Int. Conf. Softw. Eng.
Service Sci. (ICSESS), Beijing, China, Nov. 2017, pp. 225–228, doi:
10.1109/ICSESS.2017.8342901.
[14] H. Gunduz, Z. Cataltepe, and Y. Yaslan, ‘‘Stock market direction
prediction using deep neural networks,’’ in Proc. 25th Signal Process.
Commun. Appl. Conf. (SIU), Antalya, Turkey, May 2017, pp. 1–4, doi: KHORSHED ALAM (Member, IEEE) received
10.1109/SIU.2017.7960512. the B.Sc. degree in CSE from East Delta Univer-
[15] M. Faraz, H. Khaloozadeh, and M. Abbasi, ‘‘Stock market prediction-by- sity. He is currently pursuing the M.Sc. degree in
prediction based on autoencoder long short-term memory networks,’’ in
CSE with United International University. He is
Proc. 28th Iranian Conf. Electr. Eng. (ICEE), Tabriz, Iran, Aug. 2020,
currently a Software Engineering Enthusiast. He is
pp. 1–5, doi: 10.1109/ICEE50131.2020.9261055.
also a Research Assistant with Independent Uni-
[16] Y. Liu, Z. Su, H. Li, and Y. Zhang, ‘‘An LSTM based classification
method for time series trend forecasting,’’ in Proc. 14th IEEE Conf. versity, Bangladesh. His passion lies in exploring
Ind. Electron. Appl. (ICIEA), Xi’an, China, Jun. 2019, pp. 402–406, doi: the possibilities of artificial intelligence, signal
10.1109/ICIEA.2019.8833725. processing, human–computer interaction, med-
[17] S. K. Sarvepalli, ‘‘Deep learning in neural networks: The science behind tech, and software engineering. He is a driven and
an artificial brain,’’ 2015, doi: 10.13140/RG.2.2.22512.71682. dedicated individual who is eager to make a positive impact in the world of
[18] R. Vopani. Nifty-50 Stock Market Data (2000–2021). Accessed: Aug. 29, technology and contribute his skills and knowledge to the dynamic field of
2023. [Online]. Available: https://www.kaggle.com/datasets/rohanrao/ software development and research.
nifty50-stock-market-data
[19] P. Singh, M. Jha, M. Sharaf, M. A. El-Meligy, and T. R. Gadekallu,
‘‘Harnessing a hybrid CNN-LSTM model for portfolio performance: A
case study on stock selection and optimization,’’ IEEE Access, vol. 11,
pp. 104000–104015, 2023, doi: 10.1109/access.2023.3317953.
[20] Q. Li, J. Tan, J. Wang, and H. Chen, ‘‘A multimodal event-driven
LSTM model for stock prediction using online news,’’ IEEE Trans.
Knowl. Data Eng., vol. 33, no. 10, pp. 3323–3337, Oct. 2021, doi:
10.1109/TKDE.2020.2968894.
[21] E. Koo and G. Kim, ‘‘A hybrid prediction model integrating GARCH
models with a distribution manipulation strategy based on LSTM networks
for stock market volatility,’’ IEEE Access, vol. 10, pp. 34743–34754, 2022,
doi: 10.1109/ACCESS.2022.3163723. MAHBUBUL HAQ BHUIYAN received the
[22] S. Wang, ‘‘A stock price prediction method based on BiLSTM and Bachelor of Science degree in computer science
improved transformer,’’ IEEE Access, vol. 11, pp. 104211–104223, 2023, and engineering from Independent University,
doi: 10.1109/ACCESS.2023.3296308. Bangladesh. He is currently pursuing the Master
[23] H. Wang, J. Wang, L. Cao, Y. Li, Q. Sun, and J. Wang, ‘‘A stock closing of Science degree in computer science and engi-
price prediction model based on CNN-BiSLSTM,’’ Complexity, vol. 2021, neering with United International University.
pp. 1–12, Sep. 2021, doi: 10.1155/2021/5360828. He is currently an Emerging Scholar in the
[24] D. S. A. Elminaam, A. E. Tanany, M. A. Salam, and M. A. E. Fattah, field of AI and ML, with a keen focus on signal
‘‘CPSMP_ML: Closing price prediction of stock market using processing and software engineering. He is also
machine learning models,’’ in Proc. 2nd Int. Mobile, Intell.,
an Adjunct Lecturer with the Department of CSE,
Ubiquitous Comput. Conf. (MIUCC), May 2022, pp. 251–255, doi:
Independent University, Bangladesh. He is known for his dedication
10.1109/miucc55081.2022.9781756.
to fostering research skills among undergraduate students. He actively
[25] M. Vijh, D. Chandola, V. A. Tikkiwal, and A. Kumar, ‘‘Stock closing
price prediction using machine learning techniques,’’ Proc. Comput. encourages young minds to delve into the world of research, highlighting
Sci., vol. 167, pp. 599–606, Jan. 2020, doi: 10.1016/j.procs.2020. its importance in the evolving tech landscape. He is deeply involved
03.326. in mentoring and supervising numerous student-led research projects,
[26] T. Gao and Y. Chai, ‘‘Improving stock closing price prediction using facilitating their exploration of innovative ideas in AI, ML, and ed-tech. His
recurrent neural network and technical indicators,’’ Neural Comput., approach in the classroom is characterized by a blend of practical insights,
vol. 30, no. 10, pp. 2833–2854, Oct. 2018, doi: 10.1162/neco_a_ a question-based approach alongside theoretical knowledge, aimed at
01124. preparing students for the challenges of modern technological advancements.

VOLUME 12, 2024 122767


K. Alam et al.: Enhancing Stock Market Prediction: A Robust LSTM-DNN Model

INJAMAM UL HAQUE was born in Dhaka, TAREM AHMED (Senior Member, IEEE)
Bangladesh, in 2002. He is currently pur- received the Graduate degree (summa cum laude)
suing the B.Sc. degree in computer science in physics and in economics from the Middlebury
with Independent University, Bangladesh. He College, USA, master’s degree in electrical
passionately explores cutting-edge technologies, engineering from the Ivy League University of
specializing in image processing, computer vision, Pennsylvania, USA, and the Doctorate degree
AI for healthcare, quantum machine learning, and in computer science from International Islamic
deep learning. In image processing, he manipu- University Malaysia, Malaysia. During various
lates visual data to advance our understanding of stages in his career, he has worked in industrial
images, while his work in computer vision aims product development in the silicon valley area of
to bridge the gap between computers and human perception. Committed CA, USA, and in academic research with McGill University, Canada, and
to societal betterment, he leverages AI for healthcare to revolutionize ETH Zurich, Switzerland, before returning to his native city of Dhaka,
medical diagnostics and treatment. In quantum machine learning, he explores Bangladesh. He has presented in research workshops at various international
quantum computing’s potential to enhance machine learning algorithms, universities, such as the University of Naples Federico II, Italy, and École
showcasing forward-thinking. In deep learning, he contributes to unraveling Normale Supérieure (ENS), France, and was an Erasmus+ Visiting Scholar
neural networks’ intricacies, staying dedicated to technological innovation. with Middle East Technical University, Turkey.
His diverse research interests include significant impact as he navigates the
dynamic world of technology in pursuit of knowledge and advancement.

MD FAHAD MONIR (Member, IEEE) received


the B.Eng. degree (Hons.) in communication
engineering from International Islamic University
Malaysia (IIUM), Malaysia, in 2014, the M.Sc.
degree in information technology from the KTH
Royal Institute of Technology, Sweden, in 2016,
and the M.Eng. degree in communication engi-
neering from the University of Trento, Italy,
in 2017. From 2017 to 2018, he was a Research
Assistant in exploiting wireless links diversity in
software-defined 802.11-based enterprise WLAN with Fondazione Bruno
Kessler (FBK), Italy. From 2018 to 2019, he was a full-time Lecturer with
American International University of Bangladesh. Since 2019, he has been a
Senior Lecturer with the Department of Computer Science and Engineering,
Independent University, Bangladesh. His current research interest includes
software-defined networking.

122768 VOLUME 12, 2024

You might also like