LSTM Stock Price Prediction Study
LSTM Stock Price Prediction Study
Keywords: Deep Learning, Machine Learning, LSTM, Stock Price Prediction, Relative Strength Index
1
future, it can effectively predict the trends of selected
Computer Science and Engineering Department, Suresh Gyan Vihar
University, Jaipur, Rajasthan, INDIA stocks. There is a possibility of historic pattern repetition
ORCID ID: 0000-0003-1317-7414 [15]. This study contributes to the growing sector of the
2
Computer Science and Engineering Department, Suresh Gyan Vihar
stock market and artificial intelligence, with the ultimate
University, Jaipur, Rajasthan, INDIA
ORCID ID: 0000-0002-1280-7907 goal of providing valuable outcomes for stock market
* Corresponding Author Email: dhokanerahul@gmail.com participants and stakeholders. The proposed research
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1169
combines technical analysis indicators and LSTM neural observed. The findings show that there are significant
networks to develop a predictive model for stock price relationships between inflation rate and exchange rate
forecasting and trend identification. For this research, we volatility and stock market returns, especially during the
have selected the RSI, MACD, and Bollinger bands as the COVID-19 pandemic [22]. In 2020, Moghar and Hamiche
technical indicators. This research article is divided into six used the daily opening prices of two stocks (Google and
sections. Section 1 introduces a brief idea related to stock Nike) from the New York Stock Exchange as the data for
price forecasting. Section 2 provides a literature review of the model and compared the results of different numbers of
the current work related to stock price prediction. A epochs for training. The paper concludes that the LSTM
research gap is identified in this section. Section 3 model shows promising results and can trace the evolution
introduces the methodology used in this research article. of opening prices for both stocks [23]. In 2023, Shaban et
Section 4 reports the results and findings of the proposed al. proposed a new system for predicting stock market
LSTM model. Section 5 discusses the importance of prices using deep learning. Two stages, data preprocessing
technical indicators, the future research direction of the and stock price prediction, are performed using a
proposed system, and the limitations of the proposed combination of LSTM and BiGRU models. The proposed
system. Section 6 concludes the work proposed in this system outperforms other existing methods in terms of
research article. accuracy, error rate, and correlation coefficient [24].
Srivastava et al. (2023) introduced research in which the
2. Literature Review direction of Nifty50 stocks in India was predicted. For the
time series data, different algorithms such as LSTM, KNN,
Shen and Shafiq (2020) proposed a comprehensive
SVM, Random Forest, and gradient boosting are applied to
solution that combines dimensionality reduction, feature
get better accuracy in predictions. Additional data, like
engineering, and a customized LSTM model for predicting
financial news tweets related to stocks, is also used to
short-term price trends of Chinese stocks. The results show
enhance efficiency. The result shows that the model
that the proposed solution outperforms the other methods
reduces major investor losses [25].
in terms of accuracy, precision, recall, and F1-score [16].
Mehtab et al. (2021) introduced a study in which the 2.1. Research Gap
Nifty50 index value was considered for analysis. He used
Many researchers have focused on stock prices and simple
LSTM along with basic OLHC data. The findings show
OHLC features, along with machine learning algorithms
that the most accurate model is the LSTM-based univariate
such as RNN, LSTM, SVM, and linear regression
model, which predicts the open value of the NIFTY 50
algorithms. Some researchers have focused on the volume
time series for the coming week using data from one week
traded for the selected stocks. With these basic features,
ago as input [17]. Jin et al. (2019) added trader sentiment
technical indicators can also play an important role in
to the LSTM-RNN model. The trader's sentiment analysis,
feature engineering. In this research, we have selected the
with the help of the LSTM-RNN algorithm, provides the
RSI, Bollinger Band, and MACD indicators, which are
next day's closing price of stock. The attention layer
popular for technical analysis of stocks, along with basic
continuously monitors crucial information related to the
OHLC features and LSTM. By using this combination, we
stock [18]. In their research, Usmani and Shamsi (2023)
can predict the closing price and the trend (uptrend or
added the weighted category of news related to finance.
downtrend) of a selected stock effectively.
The selected news is combined with the LSTM model, and
this combination of news and machine learning using
LSTM is used for prediction purposes [19]. In their
3. Methodology
research, Mehtab and Sen (2021) chose a hybrid approach 3.1. Long-Short-Term-Memory (LSTM) algorithm
in which machine learning and deep learning were
Fig. 1. Shows the structure of LSTM cell state. (Ct ) is the
combined. The CNN algorithm is used to fine-tune the
current state and (Ct−1 ) is the previous state of the LSTM.
validation loss. The results showed that the CNN-based
model is more useful for predicting stocks effectively [20].
Qiao et al. (2022) introduced a study in which Shanghai
stock market trends, such as uptrends and downtrends,
were identified. In this study, LSTM is combined with
basic features such as open, high, low, and close values of
stocks, which are ranked according to average income.
With the help of LSTM, the results are more accurate in
terms of the RMSE, MSE, and MAPE [21]. In 2023,
Sreenu introduced a strategy in which the inflation rate and
exchange rate volatility effects on the stock market are Fig. 1. LSTM Structure.
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1170
stock prices to check the accuracy and reliability of the
model.
Forget gate (ft ) looks at (ht−1 ) and(xt ). The activation
function used is sigmoid (σ) for outputs between 0 and 1.
The value 0 means completely forget and 1 means keep for
the next state.
ft = σ(Wf ∙ [ht−1 , xt ] + bf ) − − − − − − − −(1)
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1171
num_features). After that, an LSTM layer with a specified Table 2 lists the performance metrics on the testing dataset,
number of units is added, e.g., 150. Finally, a dense layer which accounts for 20% of the total dataset. The testing
with a single unit is added for output. The model is dataset is completely new to the model because the model
compiled using an optimizer (e.g., Adam) and the mean is trained using the training dataset, so we have chosen the
squared error loss function. data from Table 2. The R2 score further confirms the
model's ability to capture the variance in stock prices. The
8. Train the LSTM model:
average R2 score value from Table 2 is 0.878. An R2 score
The model was fit to the training data. The batch size and value for the selected stocks of 0.85<R2<1 indicates the
30 number of epochs are specified. The training data were strong predictive power of our model. Equation (7)
shuffled, and a validation split of 0.1 was used to monitor represents the formula used to calculate the R2 score.
the model's performance.
𝑠𝑢𝑚 𝑠𝑞𝑢𝑎𝑟𝑒𝑑 𝑟𝑒𝑔𝑟𝑒𝑠𝑠𝑖𝑜𝑛 (𝑆𝑆𝑅)
𝑅2 = 1 − −−−−
9. Make predictions: 𝑡𝑜𝑡𝑎𝑙 𝑠𝑢𝑚 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒𝑠 (𝑆𝑆𝑇)
The trained model is used to make predictions based on the − (7)
testing data. Conversely, the predicted and actual values The average MAPE of the testing dataset is 2.206 from
are scaled to their original ranges, and the trends are Table 2. The lower value of MAPE indicates the better
identified such as uptrend or downtrend. performance of the proposed model. Equation (8)
10. Evaluate the model's performance: represents the formula for calculating the MAPE.
𝑛
Metrics such as the MAPE, R2 Score, and RMSE were 1 𝐴𝑡 − 𝐹𝑡
𝑀𝐴𝑃𝐸 = ∑ | | − −𝑤ℎ𝑒𝑟𝑒, 𝐴𝑡 = 𝐴𝑐𝑡𝑢𝑎𝑙, 𝐹𝑡
calculated between the predicted and actual values. The 𝑛 𝐴𝑡
𝑡=1
predicted and actual values were plotted for visual = 𝑃𝑟𝑒𝑑𝑖𝑐𝑡𝑒𝑑, 𝑛
analysis. The trend identification accuracy is measured = 𝑁𝑜. 𝑜𝑓 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛 − −(8)
with the help of the confusion matrix.
The RMSE metric shows the model's prediction errors,
4. Results And Findings which are relatively small for all selected stocks, indicating
good overall performance. The average RMSE value of the
The experimental results demonstrate that the proposed testing dataset is 42.791. Equation (9) represents the
approach, which combines technical indicators with formula for calculating the RMSE.
OHLC, volume, and LSTM neural networks, can
effectively predict the next day's closing stock prices and 𝑛
(𝑃𝑟𝑒𝑑𝑖𝑐𝑡𝑒𝑑𝑖 − 𝐴𝑐𝑡𝑢𝑎𝑙𝑖 )2
trends. The model achieved low MAPE, RMSE, and 𝑅𝑀𝑆𝐸 = √∑ − −𝑊ℎ𝑒𝑟𝑒, 𝑛
improved R2 scores for all the selected stocks, indicating 𝑛
𝑖=1
good performance of the model and efficient predictions of
= 𝑇𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑜𝑏𝑠𝑒𝑟𝑣𝑎𝑡𝑖𝑜𝑛𝑠. −
the next day's closing price and trends. Table 1 shows
− (9)
performance metrics for the training dataset, which is 80%
of the total dataset. Table 2. Performance Metrics for Testing Dataset.
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1172
The graph of the “Asian Paint” sample stock, in which the
predicted and tested values are plotted, is shown in Fig. 3.
This indicates that the model can predict stock prices
efficiently. The plotted chart shows 20% of the total
dataset, which was reserved for testing purposes.
e) KOTAK BANK
Fig. 4. Confusion Matrix of stocks selected for study
purposes a) ASIAN PAINTS b) RELIANCE c)
HINDUSTAN UNILEVER d) INFOSYS e) KOTAK
BANK
Table 3. Accuracy, Precision, Recall, Specificity, and F1
Score of Selected Stocks.
Fig. 3. Prediction of testing data for ASIAN PAINTS stock
Accurac Precisio Specifici F1
Our proposed model can predict the next day's trend in the Name of Stock Recall
y n ty Score
stock. There are two types of trends: uptrends (Positive)
and downtrends (Negative). Fig. 4 represents the confusion ASIAN
matrix of the selected stocks for the period from June 19th, 0.60 0.67 0.40 0.80 0.50
PAINTS
2023, to July 4th, 2023. A total of 10 trading-day readings
related to stock trends were taken using the model. A RELIANCE 0.60 0.67 0.40 0.80 0.50
confusion matrix is a matrix used in classification to assess
the performance of a machine learning model, where each HINDUSTAN
0.70 0.67 0.50 0.83 0.57
column represents the predicted class and each row UNILEVER
represents the actual class. In our model, there are two
INFOSYS 0.70 0.83 0.71 0.67 0.77
classes: positive (P) and negative (N). A positive (P)
represents an uptrend in the stock, and a negative (N) KOTAK
represents a downtrend in the stock. 0.70 0.80 0.67 0.75 0.73
BANK
5. Discussion
The findings of this research paper highlight the potential
of utilizing technical indicators and LSTM neural networks
c) HINDUSTAN d) INFOSYS for stock price prediction.
UNILEVER 5.1. Importance of Technical Indicators:
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1173
The inclusion of technical indicators, such as Bollinger architectures to enhance prediction accuracy. Alternative
Bands (Fig. 5), MACD, and RSI (Fig. 6), enhances the technical indicators can be used as features to improve the
model's ability to capture market trends and patterns. accuracy and performance of the model. Additionally, the
research can be extended to multiple stocks or broader
market indices such as forex, cryptocurrency, and
commodities for comprehensive market analysis and
forecasting.
5.3. Limitations of Proposed System:
LSTM-based stock price prediction models generally face
overfitting issues. The model may perform well on training
data but struggle with unseen data, indicating overfitting.
Fig. 5. Bollinger Bands for Asian Paints Stock. Sudden and unexpected market changes might challenge
With its ability to learn and model sequential data, the the model's ability to adapt quickly. The performance of
LSTM neural network effectively predicts the next day's the model could be sensitive to hyperparameter choices,
closing price and trends. The research also emphasizes the requiring fine-tuning for optimal results. While technical
importance of data preprocessing, feature engineering, and indicators and LSTM networks are powerful, their
model evaluation in developing accurate and reliable complexity might make them computationally expensive
predictive models for stock price forecasting. The or challenging to interpret.
application of this research extends beyond stock price
prediction to various other financial forecasting tasks such 6. Conclusion
as forex, cryptocurrency, and commodities. In conclusion, this research provides valuable insights into
the application of technical indicators and LSTM neural
networks for stock price and trend prediction. When the
performance metric MAPE is reduced, and the R2-Score is
between 0.85<R2<1, and the RMSE is reduced, indicating
that the model works well in predicting the closing price of
the selected stock for the next day. Trend identification is
measured by using the confusion matrix. Sample stock
readings show that the accuracy of INFOSYS, KOTAK
Fig. 6. RSI indicator of Asian Paints Stock
BANK, and HINDUSTAN UNILEVER are remarkably
good, i.e., 70%. Good Precision and F1 values in KOTAK
BANK and INFOSYS indicate that the model's predictions
The combination of technical indicators and LSTM neural
for positive instances are accurate. The high Specificities
networks can be utilized in portfolio management, trading
of HINDUNILVR, ASIANPAINT, and RELIANCE
strategies, and risk assessment. Fig. 7 shows the validation
indicate that the model's predictions for negative instances
and training loss of the model after 30 epochs, which
are accurate and the number of false positives is reduced.
indicates that the model is trained effectively.
The results add to the body of knowledge in the field of
financial market forecasting and offer useful
recommendations for investors, traders, and financial
organizations looking to enhance their stock market
decision-making procedures.
6.1. Acknowledgment
I would like to express my gratitude to Suresh Gyan Vihar
University, Jaipur, Rajasthan, India for their support and
for providing research facilities.
Author contributions
Fig. 7. Training and Validation Losses for OHLC,
Mr. Rahul Maruti Dhokane: Data collection,
Bollinger Bands, RSI and MACD
conceptualization, methodology, software development,
5.2. Future Research Directions: and original draft writing were conducted for this
manuscript.
Further research can explore the incorporation of
additional features and alternative deep learning Dr. Sohit Agarwal: For this manuscript, software
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1174
validation, visualization, investigation, and reviewing and (ESCI), Mar. 2023, Published, doi:
editing were performed. 10.1109/esci56872.2023.10099791.
Conflicts of interest [10] L. N. Mintarya, J. N. M. Halim, C. Angie, S.
Achmad, and A. Kurniawan, “Machine learning
The authors declare no conflicts of interest.
approaches in stock market prediction: A systematic
literature review,” Procedia Computer Science, vol.
References
216, pp. 96–102, 2023, doi:
[1] S. S. Roy, D. Mittal, A. Basu, and A. Abraham, 10.1016/j.procs.2022.12.115.
“Stock Market Forecasting Using LASSO Linear
[11] D. Bhuriya, G. Kaushal, A. Sharma, and U. Singh,
Regression Model,” Advances in Intelligent Systems
“Stock market predication using a linear regression,”
and Computing, pp. 371–381, 2015, doi:
2017 International conference of Electronics,
10.1007/978-3-319-13572-4_31.
Communication and Aerospace Technology (ICECA),
[2] X. Zhong and D. Enke, “Predicting the daily return Apr. 2017, Published, doi:
direction of the stock market using hybrid machine 10.1109/iceca.2017.8212716.
learning algorithms,” Financial Innovation, vol. 5,
[12] J. M. Sangeetha and K. J. Alfia, “Financial stock
no. 1, Jun. 2019, doi: 10.1186/s40854-019-0138-0.
market forecast using evaluated linear regression
[3] S. Selvin, R. Vinayakumar, E. A. Gopalakrishnan, V. based machine learning technique,” Measurement:
K. Menon, and K. P. Soman, “Stock price prediction Sensors, vol. 31, p. 100950, Feb. 2024, doi:
using LSTM, RNN and CNN-sliding window 10.1016/j.measen.2023.100950.
model,” 2017 International Conference on Advances
[13] H. He, J. Chen, H. Jin, and S.-H. Chen, “Trading
in Computing, Communications and Informatics
Strategies Based on K-means Clustering and
(ICACCI), Sep. 2017, Published, doi:
Regression Models,” Computational Intelligence in
10.1109/icacci.2017.8126078.
Economics and Finance, pp. 123–134, doi:
[4] M. Li, Y. Zhu, Y. Shen, and M. Angelova, 10.1007/978-3-540-72821-4_7.
“Clustering-enhanced stock price prediction using
[14] Y. Chen, J. Wu, and Z. Wu, “China’s commercial
deep learning,” World Wide Web, vol. 26, no. 1, pp.
bank stock price prediction using a novel K-means-
207–232, Apr. 2022, doi: 10.1007/s11280-021-
LSTM hybrid approach,” Expert Systems with
01003-0.
Applications, vol. 202, p. 117370, Sep. 2022, doi:
[5] Y. Wu, Z. Fu, ·Xiaoxuan Liu, and ·Yuan Bing, “A 10.1016/j.eswa.2022.117370.
hybrid stock market prediction model based on GNG
[15] R. Corizzo and J. Rosen, “Stock market prediction
and reinforcement learning,” Expert Systems with
with time series data and news headlines: a stacking
Applications, vol. 228, p. 120474, Oct. 2023, doi:
ensemble approach,” Journal of Intelligent
10.1016/j.eswa.2023.120474.
Information Systems, vol. 62, no. 1, pp. 27–56, Jul.
[6] X. Zhong and D. Enke, “A comprehensive cluster and 2023, doi: 10.1007/s10844-023-00804-1.
classification mining procedure for daily stock market
[16] J. Shen and M. O. Shafiq, “Short-term stock market
return forecasting,” Neurocomputing, vol. 267, pp.
price trend prediction using a comprehensive deep
152–168, Dec. 2017, doi:
learning system,” Journal of Big Data, vol. 7, no. 1,
10.1016/j.neucom.2017.06.010.
Aug. 2020, doi: 10.1186/s40537-020-00333-6.
[7] K. Liagkouras and K. Metaxiotis, “Stock Market
[17] S. Mehtab, J. Sen, and A. Dutta, “Stock Price
Forecasting by Using Support Vector Machines,”
Prediction Using Machine Learning and LSTM-
Learning and Analytics in Intelligent Systems, pp.
Based Deep Learning Models,” Communications in
259–271, 2020, doi: 10.1007/978-3-030-49724-8_11.
Computer and Information Science, pp. 88–106,
[8] R. K. Dash, T. N. Nguyen, K. Cengiz, and A. 2021, doi: 10.1007/978-981-16-0419-5_8.
Sharma, “Fine-tuned support vector regression model
[18] Z. Jin, Y. Yang, and Y. Liu, “Stock closing price
for stock predictions,” Neural Computing and
prediction based on sentiment analysis and LSTM,”
Applications, vol. 35, no. 32, pp. 23295–23309, Mar.
Neural Computing and Applications, vol. 32, no. 13,
2021, doi: 10.1007/s00521-021-05842-w.
pp. 9713–9729, Sep. 2019, doi: 10.1007/s00521-019-
[9] R. M. Dhokane and O. P. Sharma, “A Comprehensive 04504-2.
Review of Machine Learning for Financial Market
[19] S. Usmani and J. A. Shamsi, “LSTM based stock
Prediction Methods,” 2023 International Conference
prediction using weighted and categorized financial
on Emerging Smart Computing and Informatics
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1175
news,” PLOS ONE, vol. 18, no. 3, p. e0282234, Mar.
2023, doi: 10.1371/journal.pone.0282234.
[20] S. Mehtab and J. Sen, “Stock Price Prediction Using
Convolutional Neural Networks on a Multivariate
Time Series,” Aug. 2021, Published, doi:
10.36227/techrxiv.15088734.v1.
[21] R. Qiao, W. Chen, and Y. Qiao, “Prediction of stock
return by LSTM neural network,” Applied Artificial
Intelligence, vol. 36, no. 1, Dec. 2022, doi:
10.1080/08839514.2022.2151159.
[22] N. Sreenu, “Effect of Exchange Rate volatility and
inflation on stock market returns Dynamics -
evidence from India,” International Journal of
System Assurance Engineering and Management, vol.
14, no. 3, pp. 836–843, May 2023, doi:
10.1007/s13198-023-01914-3.
[23] A. Moghar and M. Hamiche, “Stock Market
Prediction Using LSTM Recurrent Neural Network,”
Procedia Computer Science, vol. 170, pp. 1168–
1173, 2020, doi: 10.1016/j.procs.2020.03.049.
[24] W. M. Shaban, E. Ashraf, and A. E. Slama, “SMP-
DL: a novel stock market prediction approach based
on deep learning for effective trend forecasting,”
Neural Computing and Applications, vol. 36, no. 4,
pp. 1849–1873, Nov. 2023, doi: 10.1007/s00521-023-
09179-4.
[25] S. Srivastava, M. Pant, and V. Gupta, “Analysis and
prediction of Indian stock market: a machine-learning
approach,” International Journal of System
Assurance Engineering and Management, vol. 14, no.
4, pp. 1567–1585, Jul. 2023, doi: 10.1007/s13198-
023-01934-z.
[26] “Understanding LSTM Networks -- colah’s blog,”
Understanding LSTM Networks -- colah’s blog.
https://colah.github.io/posts/2015-08-Understanding-
LSTMs/ (accessed Feb. 15, 2024).
[27] “Yahoo Finance - Stock Market Live, Quotes,
Business & Finance News,” Yahoo Finance - Stock
Market Live, Quotes, Business & Finance News.
https://finance.yahoo.com/ (accessed Feb. 15, 2024).
International Journal of Intelligent Systems and Applications in Engineering IJISAE, 2024, 12(3), 1169–1176 | 1176