Decoding Stock Trends: A Comparative Study of GRU, LSTM, and Transformer Models in Tech Sector Prediction
DOI:
https://doi.org/10.14738/tmlai.1303.18843Keywords:
GRU, LSTM, Transformer, stock prediction, machine learning, financial forecasting, AI in financeAbstract
This study investigates the predictive capabilities of three state-of-the-art neural network architectures—Long Short-Term Memory (LSTM), Gated Recurrent Unit (GRU), and Transformer models—in forecasting stock prices for five leading technology companies: Apple Inc. (AAPL), Cisco Systems, Inc. (CSCO), Meta Platforms, Inc. (META), Microsoft Corporation (MSFT), and Tesla, Inc. (TSLA). The dataset spans from July 2019 to July 2023, with models evaluated using key performance metrics such as Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), and R-squared (R²) values. The results show that GRU models consistently achieve the lowest MAE, indicating superior precision in stock price prediction. In contrast, LSTM models, while showing slightly higher error rates, are particularly effective in capturing long-term trends and the variance in stock prices, as evidenced by higher R² values. Transformer models, which utilize self-attention mechanisms, showed promise in handling complex relationships but struggled with the volatility of certain stocks, such as TSLA, leading to higher errors and lower R². These findings provide valuable insights for financial analysts and investment professionals, offering guidance on selecting the most suitable deep learning models based on specific market conditions and forecasting needs. This study also lays the groundwork for further exploration into model optimization and hybrid approaches for more robust financial forecasting.
References
Lin et al., (2021) and Abu-Mostafa, Y. S., & Atiya, A. F. (1996). Introduction to financial forecasting. Applied Intelligence, 6(3), 205–213. https://doi.org/10.1007/BF00126626
Ali, M., Khan, D. M., Alshanbari, H. M., & El-Bagoury, A. A.-A. H. (2023). Prediction of Complex Stock Market Data Using an Improved Hybrid EMD-LSTM Model. Applied Sciences, 13(3), 1429. https://doi.org/10.3390/app13031429
Beniwal, M., Singh, A., & Kumar, N. (2024). Forecasting multistep daily stock prices for long-term investment decisions: A study of deep learning models on global indices. Engineering Applications of Artificial Intelligence, 129, 107617. https://doi.org/10.1016/j.engappai.2023.107617
Chung, J., Gulcehre, C., Cho, K., & Bengio, Y. (2014). Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling (Version 1). arXiv. https://doi.org/10.48550/ARXIV.1412.3555
Ghosh, P., Neufeld, A., & Sahoo, J. K. (2022). Forecasting directional movements of stock prices for intraday trading using LSTM and random forests. Finance Research Letters, 46, 102280. https://doi.org/10.1016/j.frl.2021.102280
Henrique, B. M., Sobreiro, V. A., & Kimura, H. (2019). Literature review: Machine learning techniques applied to financial market prediction. Expert Systems with Applications, 124, 226–251. https://doi.org/10.1016/j.eswa.2019.01.012
Hu, J. (2021). Local-constraint transformer network for stock movement prediction. International Journal of Computational Science and Engineering, 24(4), 429. https://doi.org/10.1504/IJCSE.2021.117030
Jia, Y. (2019). Attention Mechanism in Machine Translation. Journal of Physics: Conference Series, 1314(1), 012186. https://doi.org/10.1088/1742-6596/1314/1/012186
Li, C., & Qian, G. (2022). Stock Price Prediction Using a Frequency Decomposition Based GRU Transformer Neural Network. Applied Sciences, 13(1), 222. https://doi.org/10.3390/app13010222
Lin, Y., Yan, Y., Xu, J., Liao, Y., & Ma, F. (2021). Forecasting stock index price using the CEEMDAN-LSTM model. The North American Journal of Economics and Finance, 57, 101421. https://doi.org/10.1016/j.najef.2021.101421
Lu, W., Li, J., Li, Y., Sun, A., & Wang, J. (2020). A CNN-LSTM-Based Model to Forecast Stock Prices. Complexity, 2020, 1–10. https://doi.org/10.1155/2020/6622927
Mian, T. S. (2023). Evaluation of Stock Closing Prices using Transformer Learning. Engineering, Technology & Applied Science Research, 13(5), 11635–11642. https://doi.org/10.48084/etasr.6017
Qiao, R., Chen, W., & Qiao, Y. (2022). Prediction of stock return by LSTM neural network. Applied Artificial Intelligence, 36(1), 2151159. https://doi.org/10.1080/08839514.2022.2151159
Shahi, T. B., Shrestha, A., Neupane, A., & Guo, W. (2020). Stock Price Forecasting with Deep Learning: A Comparative Study. Mathematics, 8(9), 1441. https://doi.org/10.3390/math8091441
Tao, Z., Wu, W., & Wang, J. (2024). Series decomposition Transformer with period-correlation for stock market index prediction. Expert Systems with Applications, 237, 121424. https://doi.org/10.1016/j.eswa.2023.121424
Wu, D., Wang, X., & Wu, S. (2022). Jointly modeling transfer learning of industrial chain information and deep learning for stock prediction. Expert Systems with Applications, 191, 116257. https://doi.org/10.1016/j.eswa.2021.116257
Yu, X., Wu, W., Liao, X., & Han, Y. (2023). Dynamic stock-decision ensemble strategy based on deep reinforcement learning. Applied Intelligence, 53(2), 2452–2470. https://doi.org/10.1007/s10489-022-03606-0
Yu, Y., & Kim, Y.-J. (2019). Two-Dimensional Attention-Based LSTM Model for Stock Index Prediction. Journal of Information Processing Systems, 15(5), 1231–1242. https://doi.org/10.3745/JIPS.02.0121
Zhou, F., Zhang, Q., Zhu, Y., & Li, T. (2023). T2V_TF: An adaptive timing encoding mechanism based Transformer with multi-source heterogeneous information fusion for portfolio management: A case of the Chinese A50 stocks. Expert Systems with Applications, 213, 119020. https://doi.org/10.1016/j.eswa.2022.119020
Downloads
Published
How to Cite
Issue
Section
License
Copyright (c) 2025 Asaad Sendi, Foyzul Hoque, Md Tamjidul Hoque

This work is licensed under a Creative Commons Attribution 4.0 International License.