Presenting an Optimized CNN-LSTM Model for Stock Price Forecasting in the Tehran Stock Exchange

Document Type : Original Article

Authors

1 MSc. Student In Financial Engineering , Amirkabir University of Technology, Tehran, Iran.

2 Associate Professor, Department of Industrial Engineering & Management Systems, Amirkabir University of Technology, Tehran, Iran

Abstract

Purpose: Understanding stock price behavior is one of the primary objectives for investors and traders in financial markets. Accurate price predictions enable informed decisions about buying, selling, or holding stocks, thereby optimizing transaction timing to maximize profits or minimize losses. Stock price prediction is inherently challenging due to the nonlinear nature of price movements and their dependence on various factors. To address these challenges, this study employs deep learning models, a subset of machine learning techniques known for their capability to handle large datasets effectively. The layered architecture and interconnected nodes (neurons) of these models enable advanced pattern recognition and relationship analysis, resulting in more precise price forecasts.
Method: This study proposes two optimized deep learning models, LSTM-CNN and CNN-LSTM, for predicting stock prices in the Tehran Stock Exchange. The models are fine-tuned through hyperparameter optimization using the Particle Swarm Optimization (PSO) algorithm, a population-based method widely recognized in machine learning. Additionally, advanced techniques such as adversarial training, attention mechanisms, and residual blocks are employed to enhance the models’ performance. The proposed models are benchmarked against conventional approaches, including CNN, LSTM, and CNN-LSTM models without optimization. The dataset includes information from 10 selected stocks traded in the Tehran Stock Exchange over a 10-year period, spanning from September 11, 2013, to September 11, 2023. Input variables include adjusted stock prices, financial indicators, oscillators, the free market US dollar price, and inflation rates, providing a comprehensive representation of factors influencing stock price behavior.
Findings: The evaluation metrics used in this study—RMSE, MAE, R-squared, and MAPE—reveal that the proposed deep learning models significantly outperform traditional approaches. Among these, the LSTM-CNN model demonstrates superior performance across all metrics, achieving higher prediction accuracy compared to the CNN-LSTM model. Analysis of the models with and without the PSO algorithm confirms that incorporating PSO significantly enhances model optimization. Strategy-based evaluations conducted on five selected stocks from five different industries, over four distinct time periods, further validate the superior financial performance of the proposed models. Specifically, the LSTM-CNN and CNN-LSTM models excel in terms of financial return metrics and the Sharpe ratio. Among the two, the LSTM-CNN model consistently achieves the most favorable outcomes, demonstrating its reliability and robustness for stock price forecasting.
Conclusion: Hyperparameters, which must be set before training, significantly influence the performance of deep learning models. The findings emphasize that hyperparameter optimization tailors models to stock-specific behaviors, enabling more accurate price predictions. The LSTM-CNN model outperforms the CNN-LSTM model in feature extraction and identifying dependencies within the data, resulting in improved accuracy. By integrating advanced techniques such as adversarial training, attention mechanisms, and the PSO algorithm, the proposed models provide a robust framework for stock price forecasting in the Tehran Stock Exchange. These results underscore the critical role of deep learning in financial markets, offering investors and traders tools for more informed decision-making. The LSTM-CNN model, in particular, demonstrates exceptional performance in prediction accuracy and financial metrics, making it a valuable approach for enhancing predictive analytics in the capital market.

Keywords


Abdi,Nasimeh; Moradzadeh Fard ,mehdi ; Ahmadzadeh,Hamid & Khoddam ,Mahmoud (2022). A Hybrid Model for Portfolio Optimization Based on Stock Price Forecasting with LSTM Recurrent Neural Network using Cardinality Constraints and Multi-Criteria Decision Making Methods (Case study of Tehran Stock Exchange). Journal of Financial Management Perspective, 11(36),119-136. (in Persian)
Christian, Szegedy. Wojciech, Zaremba. Ilya, Sutskever. Joan Bruna, Dumitru Erhan. Ian, Goodfellow.& Rob, Fergus.(2014). Intriguing properties of neural networks. In ICLR.
Diebold, F,X.& and R,S, Mariano. (1995). Comparing Predictive Accuracy. Journal of Business and Economic Statistics, 13: 253-63.
Ding, X. Zhang, Y. Liu, T.& Duan, J.(2015). Deep learning for event-driven stock prediction. Artificial Intelligence, Buenos Aires, Argentina,2327-2333.
Eghtesad, Amirali. & Mohammadi, Emran. (2023). Portfolio optimization with return prediction using LSTM, Random forest, and ARIMA. Journal of Financial Management Perspective, 13(43), 9 - 28. (in Persian)
F, Kamalov.(2020). Forecasting significant stock price changes using neural networks.Neural Computing and Applications.
Gao, Penglei. Zhang, Rui.& Yang, Xi.(2020). The Application of Stock Index Price Prediction with Neural Network. Mathematical and Computational Applications, 25(3).
Ghazi Asgari Naeini, Saba; Neshat, Najmeh & Jafari Nodoushan, Abbasali (2022). Sustainable Policy-Making of Financial Systems in Crisis Situations With Modelling Based on Artificial Neural Networks. Journal of Financial Management Perspective, 12(38), 103 - 129. (in Persian)
Hamayel, M.J.& Owda, A,Y.(2021). A Novel Cryptocurrency Price Prediction Model Using GRU, LSTM and bi-LSTM Machine Learning Algorithms. AI , 2, 477–496.
He, K. Zhang, X. Ren, S.& Sun, J.(2016). Deep residual learning for image recognition. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 770-778.
Hochreiter, S.(1998). The Vanishing Gradient Problem During Learning Recurrent Neural Nets and Problem Solutions, International Journal of Uncertainty Fuzziness and Knowledge-Based, 6(2):107-116.
Khaidem,L. Saha,S. &  Roy Dey,S.(2016). Predicting the direction of stock market prices using random forest. in Applied Mathematical Finance,1-2.
Kim, T.& Kim, H, Y .(2019). Forecasting stock prices with a feature fusion LSTM-CNN model using different representations of the same data. PloS one.                                                                                    
Lakshminarayanan, S,K.,& McCrae, J.(2019). A comparative study of svm and lstm deep learning algorithms for stock market prediction .Artificial Intelligence and Cognitive Science,Galway, Ireland,5–6.
Lee,S,W.& H,Y, Kim.(2020). Stock market forecasting with super-high dimensional time-series data using ConvLSTM, trend sampling, and specialized data augmentation.Expert Systems with Applications,161:113704.
Li, P. Song, Y. McLoughlin, I.V, Guo,W&. Dai, L.-R.(2018). An Attention Pooling based Representation Learning Method for Speech Emotion Recognition. In Proceedings of the Interspeech ,Hyderabad, India.
Livieris, I.E., Kyriakidou, N., Stavroyiannis, S.,Pintelas, P. (2021). An Advanced CNN-LSTM Model for Cryptocurrency Forecasting. Electronics, MDPI. 2021.
Nelson, D,M,Q. Pereira, A,C,M. &  De Oliveira, R,A).2017). Stock market’s price movement prediction with LSTM neural Networks. Proceedings of the International Joint Conference on Neural Networks.
Nikou, M. Mansourfar, G.& Bagherzadeh, J.(2019). Stock price prediction using DEEP learning algorithm and its comparison with machine learning algorithms. Intell,26, 164–174.
Patil, P. Wu, C, S. Potika, K.& Orang, M.(2020). Stock market prediction using ensemble of graph theory, machine learning and deep learning models. Engineering and Information Management,Sydney, Australia, 12–15.
Tae-Young Kim.& Sung-Bae Cho.(2021). Optimizing CNN-LSTM neural networks with PSO for anomalous query access control. Neurocomputing,666-677.
Taye, M.M.(2023). Understanding of Machine Learning with Deep Learning: Architectures,Workflow,Applications and Future Directions.Computers, 12, 91.
Wenjie, Lu. Jiazheng, Li. Yifan, Li. Aijun, Sun.& Jingyang, Wang.(2020). A CNN-LSTM-Based Model to Forecast Stock Prices, Complexity,  6622927.
Yann, LeCun.& Yoshua, Bengio.(1995). Convolutional networks for images, speech, and time series.in The Handbook of Brain Theory and Neural Networks.
Zhao, Y.& Khushi, M.(2020). Wavelet denoised-ResNet CNN and LightGBM method to predict forex rate of change.IEEE International, Sorrento, Italy, 11–17 .