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: One of the primary objectives for investors and traders in financial markets is understanding stock price behavior. Accurate price predictions can assist individuals in making informed decisions about buying, selling, or holding stocks, thereby maximizing potential profits or minimizing losses through effective transaction timing. Due to the nonlinear behavior of prices and their dependence on various factors, predicting stock prices is challenging. To address this, the research employs deep learning models, a subset of machine learning models known for their capability to handle large datasets. Their structure, featuring multiple layers and interconnected nodes (neurons), allows for recognizing patterns and relationships, facilitating more accurate price predictions.
Method: This study utilizes two proposed models, LSTM-CNN and CNN-LSTM, to predict stock prices in the Tehran Stock Exchange. These models are optimized through hyperparameter tuning using the PSO algorithm, a population-based optimization technique, along with model enhancement techniques such as adversarial training, attention mechanism, and residual blocks. The proposed models are compared with CNN, LSTM, and CNN-LSTM models. Data from 10 stocks, spanning September 11, 2013, to September 11, 2023, were analyzed. The input data include adjusted stock prices, indicators, oscillators, the free market US dollar price, and the inflation rate.
Findings: Comparative results of evaluation metrics, including RMSE, MAE, R-squared, and MAPE, indicate that the two proposed models outperform other models. The LSTM-CNN model, in particular, has demonstrated the best performance. Evaluation of the proposed models, with and without the PSO algorithm, reveals that the algorithm aids in optimizing the models. Furthermore, strategy analysis based on the proposed models, applied to five stocks from five different industries over four time periods, shows superior financial performance. In essence, the LSTM-CNN and CNN-LSTM models have achieved notable success in terms of financial returns and the Sharpe ratio compared to other strategies, with the LSTM-CNN model showing the most favorable performance.
Conclusion: Hyperparameters are critical as they impact model outcomes, and varying these parameters can produce different results, which may be either suitable or unsuitable. These parameters are not learned during training and must be set before training. The findings suggest that hyperparameter optimization can fine-tune models based on stock behavior, leading to more accurate price predictions. Additionally, the LSTM-CNN model excels in feature extraction and understanding dependencies within the data compared to the CNN-LSTM model, thereby enhancing prediction accuracy. In summary, leveraging deep learning models, specifically LSTM-CNN and CNN-LSTM, optimized with PSO and advanced techniques, significantly improves stock price prediction in the Tehran Stock Exchange. The results indicate that these models, particularly the LSTM-CNN, offer superior performance in financial return metrics and prediction accuracy. This approach provides a robust framework for investors and traders seeking to make informed decisions in financial markets, highlighting the importance of advanced machine learning techniques in enhancing predictive analytics.

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 .