Comparison of LSTM and Transformer Models in Predicting NVIDIA Stock Closing Prices and the Application of Rule-based Trading Strategies
Abstract
This study evaluates the effectiveness of two deep learning models—Long Short-Term Memory (LSTM) and Transformer—in predicting NVIDIA (NVDA) stock prices using historical data from June 7, 2021 to June 7, 2025, with an 80% training and 20% testing data split. The results show that the LSTM model achieved a Root Mean Squared Error (RMSE) of 2.7703 on the training data and 7.3796 on the testing data, while the Transformer model produced an RMSE of 5.3573 (training) and 10.8563 (testing). A hybrid model demonstrated improved prediction accuracy with an RMSE of 3.5643 (training) and 8.6727 (testing), although it still did not outperform LSTM. The model also indicated a moderately declining trend in stock prices over the projected 30-day period. Gaussian noise augmentation was applied during training to improve model generalization. This study also explores investment strategy development by analyzing rule-based trading signals, generating buy (long) and sell (short) signals based on predicted price movements. Additionally, risks such as market volatility and potential overfitting were evaluated, alongside the influence of non-technical factors such as market sentiment. The primary focus of the research is to compare the performance of the LSTM and Transformer models in forecasting NVIDIA’s closing stock prices and applying a simple rule-based trading strategy. For future work, the use of methods such as Prophet, ARIMA, and hybrid ensemble approaches is recommended to enhance prediction accuracy, improve market adaptability, and deliver a more robust stock forecasting system leveraging advanced machine learning techniques for more optimal investment decisions.
Keywords
Full Text:
PDFReferences
S. Wu, “Predicting Stock Prices in the Electric Vehicle and Technology Sectors using Long Short-Term Memory Models,” Advances in Economics Management and Political Sciences, Vol. 94, No. 1, pp. 148–156, 2024, doi: 10.54254/2754-1169/94/2024ox0183.
H. Li, “Optimizing Stock Price Prediction: Exploring LSTM Architectural Parameters in Financial Forecasting,” Highlights in Science Engineering and Technology, Vol. 85, pp. 1095–1099, 2024, doi: 10.54097/40px3f62.
Y. Yan, X. Nie, M. Wang, and Y. Chen, “LSTM-based Stock Price Prediction Model using News Sentiments,” Advances in Economics and Management Research, Vol. 6, pp. 57–65, 2023, doi: 10.56028/aemr.6.1.57.2023.
L. Mochurad and A. Dereviannyi, “An Ensemble Approach Integrating LSTM and ARIMA Models for Enhanced Financial Market Predictions,” R Soc Open SCI, Vol. 11, pp. 1–15, 2024, doi: 10.1098/rsos.240699.
A. Zeng, M. Chen, L. Zhang, and Q. Xu, “Are Transformers Effective for Time Series Forecasting?,” The Thirty-Seventh AAAI Conference on Artificial Intelligence (AAAI-23), Vol. 37, pp. 11121–1128, 2023, [Online]. Available: www.aaai.org
Z.-Y. Peng and P.-C. Guo, “A Data Organization Method for LSTM and Transformer when Predicting Chinese Banking Stock Prices,” Discrete Dyn Nat Soc, Vol. 2022, pp. 1–9, 2022, doi: 10.1155/2022/7119678.
S. Tariq, “Evaluation of Stock Closing Prices using Transformer Learning,” Engineering Technology & Applied Science Research, Vol. 13, pp. 11635–11642, 2023, doi: 10.48084/etasr.6017.
M. Ghudafa Taufik Akbar, S. Panggabean, and M. Noor, “Perbandingan Prediksi Harga Saham dengan menggunakan LSTM GRU dengan Transformer,” Vol. 11, No. 1, 2022.
R. Wang, M. Sun, and L. Wang, “From News to Trends: A Financial Time Series Forecasting Framework With LLM-Driven News Sentiment Analysis and Selective State Spaces,” Journal of Intelligent Information System, pp. 1–28, Apr. 2025, doi: 10.21203/rs.3.rs-6277319/v1.
J. Qiu, B. Wang, and C. Zhou, “Forecasting Stock Prices with Long-Short Term Memory Neural Network based on Attention Mechanism,” PLoS One, Vol. 15, No. 2, pp. 1–15, 2020, doi: 10.1371/journal.pone.0227222.
T. Li, Z. Liu, Y. Shen, X. Wang, H. Chen, and S. Huang, “MASTER: Market-Guided Stock Transformer for Stock Price Forecasting,” Computational Engineering, Finance, and Science, Vol. 1, pp. 1–11, 2024, [Online]. Available: www.aaai.org
Z. Yang and Z. Wang, “The Research of NVIDIA Stock Price Prediction based on LSTM and ARIMA Model,” 2024. doi: 10.54097/dndygw34.
P. Dash, J. Mishra, and S. Dara, “LSTM-based Temporal Analysis of Nifty 50: Accuracy Dynamics Across Varied Time Frames,” Proceedings of the International Conference on Computational Innovations and Emerging Trends (ICCIET- 2024), Vol. 2024 ICCET, pp. 1164–1172, 2024, doi: 10.2991/978-94-6463-471-6_111.
J. Tan, “NVIDIA Stock Price Prediction by Machine Learning,” Highlights in Business Economics and Management, Vol. 24, pp. 1072–1076, 2024, doi: 10.54097/dsz8ns50.
A. Zeng, M. Chen, L. Zhang, and Q. Xu, “Are Transformers Effective for Time Series Forecasting?,” Computer Science, Vol. 37, pp. 1–15, 2022, doi: 10.48550/arxiv.2205.13504.
Z. Lin, “Comparative Study of LSTM and Transformer for A-Share Stock Price Prediction,” Proceedings of the 2023 2nd International Conference on Artificial Intelligence, Internet and Digital Economy (ICAID 2023), Vol. 9, pp. 72–82, 2023, doi: 10.2991/978-94-6463-222-4_7.
A. Sujjada and F. Sembiring, “Prediksi Harga Bitcoin menggunakan Algoritma Long Short Term Memory,” Vol. 9, No. 1, p. 2024.
A. Slamet Riyadi, I. Puspa Wardhani, and dan Andi Perdana, “Aplikasi Perbandingan Prediksi Harga Bitcoin menggunakan Deep Learning dengan Metode ARIMA, SARIMA, LSTM, dan Gradient Boosting Regressor,”Seminar Nasional Teknologi Informasi dan Komunikasi STI&K (SeNTIK), Vol. 7, No. 1, pp. 1–2, Jun. 2023.
X. Zhang, “Exploring the Synergy: Combining Improved Sparrow Search Optimization with Long Short-Term Memory (LSTM) for Enhanced Stock Price Prediction,” Highlights in Business Economics and Management, Vol. 2022, No. 1, hindawi, pp. 1–11, 2024. doi: 10.54097/6mytfm47.
S. J. Pipin, R. Purba, and H. Kurniawan, “Prediksi Saham menggunakan Recurrent Neural Network (RNN-LSTM) dengan Optimasi Adaptive Moment Estimation,” Journal of Computer System and Informatics (JoSYC), Vol. 4, No. 4, pp. 806–815, Aug. 2023, doi: 10.47065/josyc.v4i4.4014.
J. Brzeszczyński, J. Gajdka, T. Schabek, and A. M. Kutan, “How Much do the Central Bank Announcements Matter on Financial Market? Application of the Rule-based Trading System Approach,” Expert Syst Appl, Vol. 182, p. 115201, 2021, doi: 10.1016/J.ESWA.2021.115201.
A. G. Isaac and V. Ramaswamy, “Rule-based Trading on an Order-Driven Exchange: a Reassessment,” Vol. 23, No. 12, pp. 1871–1886, 2023, doi: 10.1080/14697688.2023.2270711.
H. Emami, X.-H. Dang, Y. Shah, and P. Zerfos, “Modality-Aware Transformer for Financial Time Series Forecasting,” Computer Science, Machine Learning, Vol. 2024, Oct. 2023, [Online]. Available: http://arxiv.org/abs/2310.01232
R. Gal, E. Haber, B. Irwin, M. Mouallem, B. Saleh, and A. Ziv, “Using Deep Neural Networks and Derivative Free Optimization to Accelerate Coverage Closure,” 2021 ACM/IEEE 3rd Workshop on Machine Learning for CAD (MLCAD), Vol. 2021, pp. 1–9, 2021, doi: 10.1109/MLCAD52597.2021.9531234.
Y. Gu, T. Shibukawa, Y. Kondo, S. Nagao, and S. Kamijo, “Prediction of Stock Performance using Deep Neural Networks,” Applied Sciences, Vol. 10, p. 8142, 2020, doi: 10.3390/app10228142.
E. Patriya, A. Latif, and H. Handayani, “Peramalan Harga Saham Penutupan Indeks Harga Saham Gabungan (IHSG) menggunakan Algoritma Long Short Term Memory (LSTM),” Jurnal Ilmiah Ekonomi Bisnis, Vol. 28, Research Gate, pp. 304–314, 2023. doi: 10.35760/eb.2023.v28i2.7964.
G. Mu, J. Li, Z. Liao, and Z. Yang, “An Enhanced IHHO-LSTM Model for Predicting Online Public Opinion Trends in Public Health Emergencies,” Sage Open, Vol. 14, No. 2, pp. 1–16, 2024, doi: 10.1177/21582440241257681.
F. Poernamawatie, I. N. Susipta, and D. Winarno, “Sharia Bank of Indonesia Stock Price Prediction using Long Short-Term Memory,” Journal of Economics Finance and Management Studies, Vol. 07, No. 07, pp. 4777–4782, 2024, doi: 10.47191/jefms/v7-i7-94.
S. Gupta, C. S. Kudarihal, and M. Gupta, “Time Series Analysis of AMI Data and Comparative Energy Demand Forecasting using Deep Learning Models in a Smart Grid Scenario,” Engineering Research Express, Vol. 7,2025, 2025, doi: 10.1088/2631-8695/adc350.
R. F. Hadi, S. Sa’adah, and D. Adytia, “Forecasting of GPU Prices using Transformer Method,” Jurnal Sisfokom (Sistem Informasi dan Komputer), Vol. 12, No. 1, pp. 136–144, Mar. 2023, doi: 10.32736/sisfokom.v12i1.1569.
Hazsanah Fadzriani Mutiara Nurul, “Analisis Perbandingan Model Long Short Term Memory dan Transformer untuk Prediksi Saham BRI,” Universitas Katolik Parahyangan, 2024.
T. R. B. den Haan, K. W. Chau, M. van der Schans, and C. W. Oosterlee, “Rule-based Strategies for Dynamic Life Cycle Investment,” Eur Actuar J, Vol. 12, No. 1, pp. 189–213, Jun. 2022, doi: 10.1007/s13385-021-00283-0.
S. K. Inani, H. Pradhan, S. Kumar, and B. Biswas, “Navigating the Technical Analysis in Stock Markets: Insights from Bibliometric and Topic,” Investment Management and Financial Innovations, Vol. 21, No. 1, pp. 275–288, 2024, doi: 10.21511/imfi.21(1).2024.21.
DOI: https://doi.org/10.32520/stmsi.v14i5.5445
Article Metrics
Abstract view : 45 timesPDF - 12 times
Refbacks
- There are currently no refbacks.

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