Neural Network-Based Predictive Models for Stock Market Index Forecasting
Abstract
:1. Introduction
2. Literature Review
3. Materials and Methods
3.1. Models of Neural Networks
- is the i-th input
- is the weight from input i to neuron j in the hidden layer
- is the bias of neuron j in the hidden layer
- f is the activation function for the hidden layer (ReLU, sigmoid, tanh):
- is the output of neuron j in the hidden layer
- is the weight from neuron j in the hidden layer to neuron k in the output layer
- is the bias of neuron k in the output layer
- g is the activation function for the output layer (this can be different from the hidden layer’s activation function).
- represents the internal state of the network at time t
- is the input at time t
- is the output at time t
- U, V, W are weight matrices respectively corresponding to the inputs, outputs, and internal states
- b and c are bias terms
- f and g are activation functions, specifically, the hyperbolic tangent function (tanh).
- is the update gate at time t
- is the sigmoid function
- is the weight matrix for the update gate
- is the previous hidden state
- is the input at time t
- is the bias for the update gate
- is the final hidden state at time t
3.2. Performance Metrics
- (1)
- RMSE
- (2)
- MAPE
- Epsilon is a small value added to avoid division by zero; in this case, . The MAPE expresses the error as a percentage, making it easier to interpret in relative terms. It is particularly useful for understanding the magnitude of errors in a percentage context.
- (3)
- Directional Accuracy
- n is the number of data points in the time series.
- ytrue,i and ytrue,ytrue, are the actual values at the i-th and -th positions, respectively.
- ypred,i and ypred, are the predicted values at the i-th and -th positions, respectively.
- 1(condition) is an indicator function that returns 1 if the condition is true and 0 otherwise.
4. Results and Analysis
5. Discussion
6. Conclusions
Funding
Data Availability Statement
Conflicts of Interest
Appendix A
Algorithm: Time series forecasting using different neural networks. Input: data, window_size, epochs, batch_size |
Initialization: |
Import necessary libraries (Numpy, Pandas, pathlib, yfinance, Tensorflow, sklearn, matplotlib, seaborn, scipy). |
GPU devises availability and configure memory usage if a GPU is available. |
Define the path for saving results and ensure necessary directories exist. |
Data: |
Download financial data from Yahoo Finance (S&P 500 index). |
Describe the data. |
Use Close price. |
Normalize the ’Close’ price using MinMaxScaler. |
Plot the initial ’Close’ price data for visual inspection. |
Data Preparation: |
Transform the data to create a supervised learning structure with a specified window size. |
Split the data into training and testing sets. |
Model Construction: |
LSTM, CNN, ANN, RNN, and GRU. |
Compile the model with an appropriate optimizer and loss function. |
Model Training: |
Train the model on the training data using specified epochs and batch size. |
Implement callbacks for model saving and early stopping to optimize training. |
Graphic Epoch Rolling RMSE |
Performance Evaluation: |
Evaluate the model using the test data to predict future values. |
Sklearn metrics RMSE and MAPE; directional_accuracy |
Visualization: |
Scatterplot train predictions, and test prediction. |
References
- Abadi, Martín, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng Chen, Craig Citro, Greg S. Corrado, Andy Davis, Jeffrey Dean, Matthieu Devin, and et al. 2016. Tensorflow: Large-scale machine learning on heterogeneous distributed systems. arXiv arXiv:1603.04467. [Google Scholar]
- Abhyankar, Abhay, Laurence S. Copeland, and Woon Wong. 1997. Uncovering nonlinear structure in real-time stock-market indexes: The s&p 500, the dax, the nikkei 225, and the ftse-100. Journal of Business & Economic Statistics 15: 1–14. [Google Scholar]
- Aldhyani, Theyazn H. H., and Ali Alzahrani. 2022. Framework for predicting and modeling stock market prices based on deep learning algorithms. Electronics 11: 3149. [Google Scholar] [CrossRef]
- Atsalakis, George S., and Kimon P. Valavanis. 2009. Surveying stock market forecasting techniques—Part II: Soft computing methods. Expert Systems with Applications 36: 5932–41. [Google Scholar] [CrossRef]
- Ayyildiz, Nazif, and Omer Iskenderoglu. 2024. How effective is machine learning in stock market predictions? Heliyon 10: e24123. [Google Scholar] [CrossRef] [PubMed]
- Azoff, E. Michael. 1994. Neural Network Time Series Forecasting of Financial Markets. New York: John Wiley & Sons, Inc. [Google Scholar]
- Chen, Chunchun, Pu Zhang, Yuan Liu, and Jun Liu. 2020. Financial quantitative investment using convolutional neural network and deep learning technology. Neurocomputing 390: 384–90. [Google Scholar] [CrossRef]
- Chen, Tin-Chih Toly, Cheng-Li Liu, and Hong-Dar Lin. 2018. Advanced artificial neural networks. Algorithms 11: 102. [Google Scholar] [CrossRef]
- Chhajer, Parshv, Manan Shah, and Ameya Kshirsagar. 2022. The applications of artificial neural networks, support vector machines, and long–short term memory for stock market prediction. Decision Analytics Journal 2: 100015. [Google Scholar] [CrossRef]
- Cooper, Ilan, and Paulo Maio. 2019. Asset growth, profitability, and investment opportunities. Management Science 65: 3988–4010. [Google Scholar] [CrossRef]
- Cvilikas, Aurelijus. 2012. Bankinės rizikos valdymo ekonominio efektyvumo vertinimas mažmeninėje bankininkystėje. Doctoral dissertation, Kauno Technologijos Universitetas, Kaunas, Lithuania. [Google Scholar]
- Deng, Aqin. 2023. Database task processing optimization based on performance evaluation and machine learning algorithm. Soft Computing 27: 6811–21. [Google Scholar] [CrossRef]
- Encke, David. 2008. Neural network-based stock market return forecasting using data mining for variable reduction. In Data Warehousing and Mining: Concepts, Methodologies, Tools, and Applications. Pennsylvania: IGI Global, pp. 2476–93. [Google Scholar] [CrossRef]
- Erbas, Bahar Celikkol, and Spiro E. Stefanou. 2009. An application of neural networks in microeconomics: Input–output mapping in a power generation subsector of the us electricity industry. Expert Systems with Applications 36: 2317–26. [Google Scholar] [CrossRef]
- Eslamieh, Pegah, Mehdi Shajari, and Ahmad Nickabadi. 2023. User2vec: A novel representation for the information of the social networks for stock market prediction using convolutional and recurrent neural networks. Mathematics 11: 2950. [Google Scholar] [CrossRef]
- Fang, Zhen, Xu Ma, Huifeng Pan, Guangbing Yang, and Gonzalo R. Arce. 2023. Movement forecasting of financial time series based on adaptive lstm-bn network. Expert Systems with Applications 213: 119207. [Google Scholar] [CrossRef]
- Gao, Ya, Rong Wang, and Enmin Zhou. 2021. Stock prediction based on optimized lstm and gru models. Scientific Programming 2021: 4055281. [Google Scholar] [CrossRef]
- Hadavandi, Esmaeil, Hassan Shavandi, and Arash Ghanbari. 2010. Integration of genetic fuzzy systems and artificial neural networks for stock price forecasting. Knowledge-Based Systems 23: 800–808. [Google Scholar] [CrossRef]
- Hansun, Seng, and Julio Christian Young. 2021. Predicting lq45 financial sector indices using rnn-lstm. Journal of Big Data 8: 1–13. [Google Scholar] [CrossRef]
- Hæke, Christian, and Christian Helmenstein. 1996. Neural networks in the capital markets: An application to index forecasting. Computational Economics 9: 37–50. [Google Scholar] [CrossRef]
- Kim, Sungil, and Heeyoung Kim. 2016. A new metric of absolute percentage error for intermittent demand forecasts. International Journal of Forecasting 32: 669–79. [Google Scholar] [CrossRef]
- Kuan, Chung-Ming, and Halbert White. 1994. Artificial neural networks: An econometric perspective. Econometric Reviews 13: 1–91. [Google Scholar] [CrossRef]
- Kumar, Krishna, and Md Tanwir Uddin Haider. 2021. Enhanced prediction of intra-day stock market using metaheuristic optimization on rnn–lstm network. New Generation Computing 39: 231–72. [Google Scholar] [CrossRef]
- Leung, Mark T., Hazem Daouk, and An-Sing Chen. 2000. Forecasting stock indices: A comparison of classification and level estimation models. International Journal of Forecasting 16: 173–90. [Google Scholar] [CrossRef]
- Li, Haosong, and Phillip C.-Y. Sheu. 2022. A scalable association rule learning and recommendation algorithm for large-scale microarray datasets. Journal of Big Data 9: 35. [Google Scholar] [CrossRef]
- Li, Shaoyu, Kaixuan Ning, and Teng Zhang. 2021. Sentiment-aware jump forecasting. Knowledge-Based Systems 228: 107292. [Google Scholar] [CrossRef]
- Lin, Shih-Lin, and Hua-Wei Huang. 2020. Improving deep learning for forecasting accuracy in financial data. Discrete Dynamics in Nature and Society 2020: 5803407. [Google Scholar] [CrossRef]
- Lin, Tsong-Wuu, and Chan-Chien Yu. 2009. Forecasting stock market with neural networks. Computer Science Business Economics, 1–14. [Google Scholar] [CrossRef]
- Lu, Wenjie, Jiazheng Li, Jingyang Wang, and Lele Qin. 2021. A cnn-bilstm-am method for stock price prediction. Neural Computing and Applications 33: 4741–53. [Google Scholar] [CrossRef]
- Ma, Chenyao, and Sheng Yan. 2022. Deep learning in the chinese stock market: The role of technical indicators. Finance Research Letters 49: 103025. [Google Scholar] [CrossRef]
- Maris, Konstantinos, Konstantinos Nikolopoulos, Konstantinos Giannelos, and Vassilis Assimakopoulos. 2007. Options trading driven by volatility directional accuracy. Applied Economics 39: 253–60. [Google Scholar] [CrossRef]
- Markowitz, Harris. 1952. Portfolio Selection. The Journal of Finance 7: 77–91. [Google Scholar]
- Matkovskyy, Roman, and Taoufik Bouraoui. 2019. Application of neural networks to short time series composite indexes: Evidence from the nonlinear autoregressive with exogenous inputs (narx) model. Journal of Quantitative Economics 17: 433–46. [Google Scholar] [CrossRef]
- McKinney, Wes. 2010. Data structures for statistical computing in python. Paper presented at the 9th Python in Science Conference, Austin, TX, USA, 28 June–3 July 2010; vol. 445, pp. 51–56. [Google Scholar]
- Meese, Richard A., and Andrew K. Rose. 1991. An empirical assessment of non-linearities in models of exchange rate determination. The Review of Economic Studies 58: 603–19. [Google Scholar] [CrossRef]
- Moghaddam, Amin Hedayati, Moein Hedayati Moghaddam, and Morteza Esfandyari. 2016. Stock market index prediction using artificial neural network. Journal of Economics, Finance and Administrative Science 21: 89–93. [Google Scholar] [CrossRef]
- Moghar, Adil, and Mhamed Hamiche. 2020. Stock market prediction using lstm recurrent neural network. Procedia Computer Science 170: 1168–73. [Google Scholar] [CrossRef]
- Mostafa, Mohamed M., and Ahmed A. El-Masry. 2016. Oil price forecasting using gene expression programming and artificial neural networks. Economic Modelling 54: 40–53. [Google Scholar] [CrossRef]
- O’Doherty, Michael S. 2012. On the conditional risk and performance of financially distressed stocks. Management Science 58: 1502–20. [Google Scholar] [CrossRef]
- Puh, Karlo, and Marina Bagić Babac. 2023. Predicting stock market using natural language processing. American Journal of Business 38: 41–61. [Google Scholar] [CrossRef]
- Qi, Chenyang, Jiaying Ren, and Jin Su. 2023. Gru neural network based on ceemdan–wavelet for stock price prediction. Applied Sciences 13: 7104. [Google Scholar] [CrossRef]
- Qi, Min. 1996. 18 financial applications of artificial neural networks. Handbook of Statistics 14: 529–52. [Google Scholar]
- Raudys, Aistis, and Edvinas Goldstein. 2022. Forecasting detrended volatility risk and financial price series using lstm neural networks and xgboost regressor. Journal of Risk and Financial Management 15: 602. [Google Scholar] [CrossRef]
- Reboredo, Juan C., José M. Matías, and Raquel Garcia-Rubio. 2012. Nonlinearity in forecasting of high-frequency stock returns. Computational Economics 40: 245–64. [Google Scholar] [CrossRef]
- Rikukawa, Shota, Hiroki Mori, and Taku Harada. 2020. Recurrent neural network based stock price prediction using multiple stock brands. International Journal of Innovative Computing, Information and Control 16: 1093–99. [Google Scholar]
- Sako, Kady, Berthine Nyunga Mpinda, and Paulo Canas Rodrigues. 2022. Neural networks for financial time series forecasting. Entropy 24: 657. [Google Scholar] [CrossRef]
- Sandoval Serrano, Lilian Judith. 2018. Algoritmos de Aprendizaje Automático Para Análisis y Predicción de Datos. Revista Tecnológica; no. 11. El Salvador: ITCA. [Google Scholar]
- Sheth, Dhruhi, and Manan Shah. 2023. Predicting stock market using machine learning: Best and accurate way to know future stock prices. International Journal of System Assurance Engineering and Management 14: 1–18. [Google Scholar] [CrossRef]
- Song, Hyunsun, and Hyunjun Choi. 2023. Forecasting stock market indices using the recurrent neural network based hybrid models: Cnn-lstm, gru-cnn, and ensemble models. Applied Sciences 13: 4644. [Google Scholar] [CrossRef]
- Stasinakis, Charalampos, Georgios Sermpinis, Konstantinos Theofilatos, and Andreas Karathanasopoulos. 2016. Forecasting us unemployment with radial basis neural networks, kalman filters and support vector regressions. Computational Economics 47: 569–87. [Google Scholar] [CrossRef]
- Ticknor, Jonathan L. 2013. A bayesian regularized artificial neural network for stock market forecasting. Expert Systems with Applications 40: 5501–6. [Google Scholar] [CrossRef]
- Van Der Walt, Stefan, S. Chris Colbert, and Gael Varoquaux. 2011. The numpy array: A structure for efficient numerical computation. Computing in Science & Engineering 13: 22–30. [Google Scholar]
- Van Greuning, Hennie, and Sonja Brajovic Bratanovic. 2020. Analyzing Banking Risk: A Framework for Assessing Corporate Governance and Risk Management. Washington: World Bank Publications. [Google Scholar] [CrossRef]
- Villada, Fernando, Nicolás Muñoz, and Edwin García. 2012. Aplicación de las redes neuronales al pronóstico de precios en el mercado de valores. Información tecnológica 23: 11–20. [Google Scholar] [CrossRef]
- von Spreckelsen, Christian, Hans-Jörg von Mettenheim, and Michael H. Breitner. 2014. Real-time pricing and hedging of options on currency futures with artificial neural networks. Journal of Forecasting 33: 419–32. [Google Scholar] [CrossRef]
- Wang, Xingyuan, Lintao Liu, and Yingqian Zhang. 2015. A novel chaotic block image encryption algorithm based on dynamic random growth technique. Optics and Lasers in Engineering 66: 10–18. [Google Scholar] [CrossRef]
- Wang, Yimeng, and Keyue Yan. 2023. Machine learning-based quantitative trading strategies across different time intervals in the american market. Quantitative Finance and Economics 7: 569–94. [Google Scholar] [CrossRef]
- Zhang, Shuwen, and Wen Fang. 2021. Multifractal behaviors of stock indices and their ability to improve forecasting in a volatility clustering period. Entropy 23: 1018. [Google Scholar] [CrossRef] [PubMed]
- Zhang, Yaojie, Feng Ma, and Yu Wei. 2019. Out-of-sample prediction of the oil futures market volatility: A comparison of new and traditional combination approaches. Energy Economics 81: 1109–20. [Google Scholar] [CrossRef]
- Zhang, Yaojie, Likun Lei, and Yu Wei. 2020. Forecasting the chinese stock market volatility with international market volatilities: The role of regime switching. The North American Journal of Economics and Finance 52: 101145. [Google Scholar] [CrossRef]
- Zhang, Yongjie, Gang Chu, and Dehua Shen. 2021. The role of investor attention in predicting stock prices: The long short-term memory networks perspective. Finance Research Letters 38: 101484. [Google Scholar] [CrossRef]
- Zheng, Yuanhang, Zeshui Xu, and Anran Xiao. 2023. Deep learning in economics: A systematic and critical review. Artificial Intelligence Review 56: 9497–539. [Google Scholar] [CrossRef]
Close (Period Base) | Close Extended Period | Close SARS-CoV-2 | |
---|---|---|---|
count | 1508.000000 | 4023.000000 | 74.000000 |
mean | 3587.112738 | 2353.159294 | 0.530256 |
std | 691.091928 | 1112.926575 | 0.218452 |
min | 2237.399902 | 676.530029 | 0.000000 |
25% | 2888.292542 | 1354.534973 | 0.434525 |
50% | 3676.395020 | 2087.790039 | 0.545201 |
75% | 4204.159912 | 3004.280029 | 0.656688 |
max | 4796.560059 | 4796.560059 | 1.000000 |
Data Used | Authors |
---|---|
DJIA | Puh and Bagić Babac (2023) |
Apple Inc. (AAPL) IBM Corporation (IBM) Microsoft (MSFT) Goldman Sachs (GS) | Ticknor (2013) |
S&P500 | Abhyankar et al. (1997); Lin and Yu (2009); Zhang et al. (2021) |
Nasdaq | Moghaddam et al. (2016) |
Shanghai Composite Index | Lu et al. (2021) |
CAX40, DAX and the Greek FTSE/ASE 20 stock | Abhyankar et al. (1997); Maris et al. (2007) |
Tokyo Stock Exchange | Rikukawa et al. (2020) |
Nikkei 225 | Abhyankar et al. (1997); Moghar and Hamiche (2020) |
GOOGL, NKE | Moghar and Hamiche (2020) |
Chinese stock Market | Ma and Yan (2022) |
SSE 50 index | Zhang et al. (2021) |
MSCI Emerging Markets Index | Zhang et al. (2020) |
Feature | ANN | CNN | LSTM | RNN | GRU |
---|---|---|---|---|---|
Layer Structure | Sequential | Sequential | Sequential | Sequential | Sequential |
Hidden Layers | ANN with 50 units | CNN | LSTM with 50 units | SimpleRNN with 50 units | GRU with 50 units |
Convolutional Layers | None | Conv1D with 64 filters, kernel size 2, ReLU activation | None | None | None |
Pooling Layer | None | MaxPooling1D, pool size 2 | None | None | None |
Flatten Layer | None | Flatten | None | None | None |
Output Layer | Dense with 1 unit | Dense with 1 unit | Dense with 1 unit | Dense with 1 unit | Dense with 1 unit |
Data Normalization | MinMax Scaler | MinMax Scaler | MinMax Scaler | MinMax Scaler | MinMax Scaler |
Callback 2 | EarlyStopping | EarlyStopping | EarlyStopping | EarlyStopping | EarlyStopping |
Data Preparation | Sliding windows | Sliding windows | Sliding windows | Sliding windows | Sliding windows |
Time Window | 3 | 3 | 3 | 3 | 3 |
Number of Epochs | 500 | 500 | 500 | 500 | 500 |
Optimal Epoch (Date Model Base) | 500 | 106 | 285 | 28 | 500 |
Optimal Epoch (Extended period) | 21 | 37 | 31 | 28 | 500 |
Optimal Epoch (SARS-CoV-2) | 137 | 265 | 134 | 100 | 500 |
RMSE | MAPE | RMSE Long Period | MAPE Long Period | RMSE SARS-CoV-2 | MAPE SARS-CoV-2 | |
---|---|---|---|---|---|---|
LSTM | 0.0250893 | 2.7557% | 0.0320 | 3.1168% | 0.06976 | 9.4737% |
CNN | 0.0255681 | 2.7954% | 0.0146 | 1.3137% | 0.04262 | 5.3049% |
ANN | 0.0303422 | 4.6388% | 0.0148 | 1.1291% | 0.03821 | 5.1252% |
RNN | 0.0364491 | 5.6406% | 0.01469 | 1.3327% | 0.05803 | 7.8447% |
GRU | 0.0203339 | 2.2018% | 0.0166 | 1.4994% | 0.04465 | 10.6185% |
Directional Accuracy Train | Directional Accuracy Test | Directional Accuracy Train Long Period | Directional Accuracy Test Long Period | Directional Accuracy Train SARS-CoV-2 | Directional Accuracy Test SARS-CoV-2 | |
---|---|---|---|---|---|---|
LSTM | 50.50% | 49.30% | 47.29% | 50.50% | 47.70% | 49.30% |
CNN | 48.70% | 56.91% | 49.50% | 46.69% | 48.30% | 52.71% |
ANN | 47.90% | 48.10% | 48.70% | 52.10% | 44.89% | 51.70% |
RNN | 47.09% | 49.90% | 48.50% | 51.70% | 50.10% | 45.29% |
GRU | 51.10% | 49.90% | 50.70% | 48.30% | 49.30% | 49.90% |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Chahuán-Jiménez, K. Neural Network-Based Predictive Models for Stock Market Index Forecasting. J. Risk Financial Manag. 2024, 17, 242. https://doi.org/10.3390/jrfm17060242
Chahuán-Jiménez K. Neural Network-Based Predictive Models for Stock Market Index Forecasting. Journal of Risk and Financial Management. 2024; 17(6):242. https://doi.org/10.3390/jrfm17060242
Chicago/Turabian StyleChahuán-Jiménez, Karime. 2024. "Neural Network-Based Predictive Models for Stock Market Index Forecasting" Journal of Risk and Financial Management 17, no. 6: 242. https://doi.org/10.3390/jrfm17060242
APA StyleChahuán-Jiménez, K. (2024). Neural Network-Based Predictive Models for Stock Market Index Forecasting. Journal of Risk and Financial Management, 17(6), 242. https://doi.org/10.3390/jrfm17060242