1. Introduction
Stocks have evolved over the past four centuries and now play a significant role in the global financial system, with the stock market valued at over $10 trillion. Stock market fluctuations have historically affected economies worldwide, as seen during the U.S. economic downturn of the early 20th century, which led to a global recession. Predicting stock prices is a field full of potential, helping to identify market trends and support informed decision-making.
This paper investigates stock prediction using a neural network. Neural networks have the ability to learn autonomously, making them particularly effective in processing large amounts of data. As a result, they can develop models with greater precision than conventional algorithms by analyzing historical stock data, enabling more empirical predictions.
The paper is organized into five sections. The next section reviews the literature on the use of artificial intelligence, particularly neural networks, for stock price prediction. The third section introduces the data and neural network methods we used. In the fourth section, we present and analyze our findings. Finally, the paper concludes with a discussion of the study's limitations and potential directions for future research.
2. Literature Review
Before the 21st century, most economic forecasts were constrained by limitations in information technology, which hindered the use of sufficient economic data. In the early decades of the 21st century, although artificial intelligence technology began to provide access to larger datasets, limitations persisted due to the relatively small data volumes and outdated methodologies. In 2000, the Generalized Regression Neural Network (GRNN) was applied to Taiwan's economic landscape and demonstrated superior predictive accuracy compared to the Multi-Layer Feedforward Network (MLFN)[1]. By 2003, a Probability Neural Network (PNN) based on Bayesian classification was used to predict the directional movement of the Taiwan Stock Exchange index returns. Validation of this model showed it outperformed the Generalized Method of Moments (GMM)-Kalman filter and random walk forecasting models[2]. These findings reinforced the notion that, with sufficient computational power, neural networks provide superior predictive abilities compared to traditional algorithms.
From the second decade of the 21st century onwards, artificial neural networks have been widely adopted in numerous fields, including economics. In 2014, genetic algorithms (GAs) were used in the economic sector to detect financial distress in small and medium-sized enterprises (SMEs) efficiently. Validation demonstrated that genetic algorithms were highly effective in identifying bankruptcy prediction rules, outperforming logistic regression (LR) and support vector machines (SVM)[3]. In 2017, Recurrent Neural Networks (RNN), Long Short-Term Memory (LSTM) models, and Convolutional Neural Networks (CNN) were employed to forecast the valuations of listed securities in Southeast Asia, yielding positive results[4]. By 2018, a variety of machine learning technologies, particularly neural networks, were used to predict stock market trends in 39 countries, highlighting the predictive power of deep learning methods[5].
Since 2020, deep learning, particularly neural networks, has become one of the most widely applied technologies in economic forecasting. As artificial intelligence advances, the limitations of using a single neural network architecture have become increasingly apparent, leading to the integration of multiple algorithms to improve predictive capabilities. The CNN-BiLSTM-AM method, which combines Convolutional Neural Networks (CNN), Bidirectional Long Short-Term Memory networks (BiLSTM), and Attention Mechanisms (AM), has been used for stock market prediction in the Shanghai market. This integration has shown superior predictive accuracy and performance compared to its individual components[6]. In 2020, more advanced models like Multi-Layer Perceptron (MLP) and Radial Basis Function (RBF) neural networks were used to analyze the effects of oil price volatility on the exchange rate dynamics between the euro and the US dollar. It was found that MLP networks provided more accurate forecasts and captured intertemporal trends more effectively[7]. The COVID-19 pandemic in 2019 had a significant impact on the global economy. In response, Long Short-Term Memory (LSTM) networks, a variant of Recurrent Neural Networks (RNN), were used to analyze trade patterns and predict post-pandemic trends across various countries after the introduction of vaccines. The findings revealed a notable decrease in global trade concentration[8].
In conclusion, a thorough review of the literature clearly shows the substantial benefits of neural networks in economics. Our research will, therefore, focus on employing neural networks to forecast stock market trajectories.
3. Methodology
The dataset used in this study consists of stock market data from New York City, covering the period from December 1965 to May 2021. It includes columns for dates, opening prices, closing prices, highest prices, and lowest prices. To evaluate the effectiveness of the Backpropagation Neural Network (BPNN) in predicting stock prices, we selected datasets spanning half a year, one year, two years, and three years, starting from May 2021 and going backward.
Stock price predictions are typically made over a minimum timeframe of six months for short-term trends and up to three years for long-term trends. Due to the periodic closures of stock markets, we used four distinct datasets, ranging from 127 to 771 data points, to assess the accuracy of predictions across various node configurations. Performance was evaluated using the Mean Squared Error (MSE) metric.
In machine learning, backpropagation is a gradient estimation technique widely used to optimize neural networks, enabling updates to network parameters.
It efficiently applies the chain rule within neural network frameworks. Backpropagation computes the gradient of the loss function with respect to the network parameters for each input-output instance. This method is computationally efficient because it calculates the gradients for each layer in reverse order, avoiding unnecessary computations related to intermediate terms, as specified by the chain rule. This optimization is similar to the principles of dynamic programming.
Backpropagation is a crucial algorithm in training neural networks. Its primary goal is to minimize the difference between predicted outcomes and actual target values by adjusting the network’s parameters. The process can be summarized as follows:
1. Forward Propagation: In this initial phase, input data passes through the neural network, with each layer generating predictions based on its weights and biases. This process culminates in the network's output, which represents the neural network's response to the input data.
\( sigmoid(x)=\frac{1}{1+{ⅇ^{-x}}} \)
\( {w_{ji}}←{w_{ji}}-η\frac{∂{E_{d}}}{∂{w_{ji}}} \)
2. Loss Function Computation: The network's output is compared with the actual target values, and a loss function is used to evaluate the difference between the two. This loss function quantifies the error in the network's predictions by assigning a numerical value that represents the magnitude of the discrepancy between the output and the target values.
\( {E_{d}}≡\frac{1}{2}\sum _{ⅈϵoutputs}{({t_{i}}-{y_{i}})^{2}} \)
3. Backward Propagation: After calculating the loss, the error is propagated backward through the network. This step determines the gradient of the loss function with respect to each weight by computing the partial derivatives using the chain rule of calculus. This process helps identify the direction and magnitude of the weight adjustments needed to minimize prediction error.
4. Weight Update: The gradients from backward propagation are used to update the network parameters, typically through optimization algorithms such as Stochastic Gradient Descent (SGD) or Adam. The weights are adjusted in the direction that reduces the loss.
5. Iterative Process: Steps 1 through 4 are repeated over multiple iterations (or epochs) with the training dataset, gradually improving the network's accuracy.
In summary, backpropagation involves passing data through the network, calculating the loss, and adjusting the weights based on the loss gradient. This process is repeated iteratively to improve the network's performance.
4. Result and Discussion
In stock prediction, securities are typically segmented into short-term, medium-term, and long-term predictions due to their inherent cyclicality. To evaluate the effectiveness of the Backpropagation Neural Network (BPNN) in predicting stock prices, we employed four distinct datasets from the New York Stock Exchange (NYSE). These datasets include the opening price, closing price, high price, low price, and the next day's closing price, which serve as the input features and the target variable for assessing prediction accuracy.
6. The first dataset spans six months, consisting of 127 days of data from December 1, 2020, to June 1, 2021.
7. The second dataset covers one year, with 258 days of data from June 1, 2020, to June 1, 2021.
8. The third dataset spans two years, containing 511 days of data from June 3, 2019, to June 1, 2021.
9. The fourth dataset covers three years, consisting of 770 days of data from May 28, 2018, to June 1, 2021.
When using a backpropagation neural network, it is essential to adjust the number of nodes in the network and evaluate the prediction accuracy at different node configurations. In a neural network architecture, nodes, also called neurons or units, are the fundamental components. Each node has a specific role in the computation process, with its primary functions including:
10. Information Processing: Each node receives input signals from the previous layer, computes a weighted sum, and converts it into an output signal using an activation function. This process enables the network to learn and capture complex features and patterns.
11. Feature Extraction in Neural Networks: In neural networks, nodes extract features from input data at different levels. In shallow networks, nodes typically identify basic features, while in deep networks, they can detect more intricate and abstract features. However, due to the relative simplicity of stock data, a single neural network is sufficient for our purposes.
We adjust the number of nodes to ensure that the data is appropriately accommodated, optimizing the network's capacity to represent the data. If the network has too few nodes, it may result in underfitting, where the model fails to capture the data's full characteristics. Increasing the number of nodes can improve the model's ability to fit the training data. However, if too many nodes are used, the model may overfit, performing well on the training data but failing to generalize to unseen data. Finding the right balance between learning efficiency and generalization requires determining the optimal number of nodes. This allows the model to capture key features of the training data without relying too heavily on it, maintaining strong performance across various inputs.
Given the variability in our stock dataset, which spans from 127 to 770 days, we established a maximum node count of 512 to prevent underfitting. We also set a minimum of 4 nodes to reduce the risk of overfitting due to too few nodes. As a result, we configured eight groups with varying node counts: 4, 8, 16, 32, 64, 128, 256, and 512.
We use the mean squared error (MSE) to measure prediction accuracy across different parameters. A lower MSE value indicates higher accuracy.
MSE \( (\hat{θ})=E{(\hat{θ}-θ)^{2}} \)
We examined a table of Mean Squared Error (MSE) values for stock index predictions using a backpropagation neural network, varying both the number of nodes and the length of the datasets.
Mean Squared Error (MSE) Across Varying Node Counts and Data Sizes | ||||
nodes\years | 0.5 year | 1 year | 2 years | 3 years |
4 | 0.006124543 | 0.010362469 | 0.005425964 | 0.005674282 |
8 | 0.004739692 | 0.000932105 | 0.001562127 | 0.001426662 |
16 | 0.006544867 | 0.005633083 | 0.014418773 | 0.009136897 |
32 | 0.009946692 | 0.005291003 | 0.000988903 | 0.017322822 |
64 | 0.072029498 | 0.049832252 | 0.032522942 | 0.024039745 |
128 | 0.034338613 | 0.375020155 | 0.094209763 | 0.140789361 |
256 | 0.336405213 | 0.202655613 | 0.135073309 | 0.159027134 |
Our goal was to determine how well the model adapted to different time periods and node configurations, specifically identifying instances of overfitting and underfitting. By closely analyzing the MSE values, looking for significant fluctuations, we could identify these tendencies. Overfitting occurred with 4 nodes when predicting the entire dataset, while underfitting was observed with 128 and 256 nodes when forecasting the complete data. Overall, neural networks performed effectively on stock data spanning six months to three years when the number of nodes was between 8 and 64. Our analysis further showed that the MSE was significantly reduced, and prediction accuracy improved when using 8 nodes for one-year forecasts and 32 nodes for two-year forecasts. More broadly, neural networks with 8 to 32 nodes performed well in predicting stock data over periods ranging from six months to three years, yielding accurate results.
5. Conclusion
Using data from the New York Stock Exchange, we achieved improved accuracy in predicting future stock prices. During the implementation of the backpropagation neural network, it was found that a network with four nodes was insufficient for processing the entire dataset, leading to overfitting. Similarly, networks with 128 or 256 nodes exhibited signs of underfitting. As a result, we suggest that a node count between 8 and 64 is optimal for stock price prediction over a period of six months to three years. Our analysis showed that using a neural network with 8 nodes for one-year data provided significantly better accuracy than using 32 nodes for two-year data.
Future research should explore the effectiveness of backpropagation neural networks in stock price prediction, focusing on refining the optimal number of nodes and dataset size for accurate forecasting.
References
[1]. Mark T. Leung., An-Sing Chen. & Hazem. Daouk. (2000). Forecasting exchange rates using general regression neural networks, Computers & Operations Research, Volume 27, Issues 11–12, Pages 1093-1110, ISSN 0305-0548, https://doi.org/10.1016/S0305-0548(99)00144-6.
[2]. An-Sing. Chen., Mark T. Leung., Hazem. Daouk. (2003). Application of neural networks to an emerging financial market: forecasting and trading the Taiwan Stock Index, Computers & Operations Research, Volume 30, Issue 6, Pages 901-923, ISSN 0305-0548, https://doi.org/10.1016/S0305-0548(02)00037-0.
[3]. Niccolò. Gordini. (2014). A genetic algorithm approach for SMEs bankruptcy prediction: Empirical evidence from Italy, Expert Systems with Applications, Volume 41, Issue 14, Pages 6433-6445, ISSN 0957-4174, https://doi.org/10.1016/j.eswa.2014.04.026.
[4]. S. Selvin, R. Vinayakumar, E. A. Gopalakrishnan, V. K. Menon and K. P. Soman. (2017). Stock price prediction using LSTM, RNN and CNN-sliding window model, 2017 International Conference on Advances in Computing, Communications and Informatics (ICACCI), Udupi, India, pp. 1643-1647, doi: 10.1109/ICACCI.2017.8126078.
[5]. Sotirios P. Chatzis., Vassilis Siakoulis., Anastasios Petropoulos., Evangelos Stavroulakis., Nikos Vlachogiannakis. (2018). Forecasting stock market crisis events using deep and statistical machine learning techniques, Expert Systems with Applications, Volume 112, Pages 353-371, ISSN 0957-4174, https://doi.org/10.1016/j.eswa.2018.06.032.
[6]. Lu, W., Li, J., Wang, J. et al. (2021). A CNN-BiLSTM-AM method for stock price prediction. Neural Comput & Applic 33, 4741–4753 https://doi.org/10.1007/s00521-020-05532-z
[7]. Vochozka, M., Rowland, Z., Suler, P., & Marousek, J. (2020). The Influence of the International Price of Oil on the Value of the EUR/USD Exchange Rate. Journal of Competitiveness, 12(2), 167–190. https://doi.org/10.7441/joc.2020.02.10
[8]. C. T. Vidya. & K. P. Prabheesh. (2020). Implications of COVID-19 Pandemic on the Global Trade Networks, Emerging Markets Finance and Trade, 56:10, 2408-2421, DOI: 10.1080/1540496X.2020.1785426
Cite this article
Yu,H. (2025). The Application of a Backpropagation Neural Network for the Prediction of the New York Stock Exchange. Theoretical and Natural Science,87,300-305.
Data availability
The datasets used and/or analyzed during the current study will be available from the authors upon reasonable request.
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 EWA Publishing and/or the editor(s). EWA Publishing 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.
About volume
Volume title: Proceedings of the 4th International Conference on Computing Innovation and Applied Physics
© 2024 by the author(s). Licensee EWA Publishing, Oxford, UK. This article is an open access article distributed under the terms and
conditions of the Creative Commons Attribution (CC BY) license. Authors who
publish this series agree to the following terms:
1. Authors retain copyright and grant the series right of first publication with the work simultaneously licensed under a Creative Commons
Attribution License that allows others to share the work with an acknowledgment of the work's authorship and initial publication in this
series.
2. Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the series's published
version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgment of its initial
publication in this series.
3. Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and
during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (See
Open access policy for details).
References
[1]. Mark T. Leung., An-Sing Chen. & Hazem. Daouk. (2000). Forecasting exchange rates using general regression neural networks, Computers & Operations Research, Volume 27, Issues 11–12, Pages 1093-1110, ISSN 0305-0548, https://doi.org/10.1016/S0305-0548(99)00144-6.
[2]. An-Sing. Chen., Mark T. Leung., Hazem. Daouk. (2003). Application of neural networks to an emerging financial market: forecasting and trading the Taiwan Stock Index, Computers & Operations Research, Volume 30, Issue 6, Pages 901-923, ISSN 0305-0548, https://doi.org/10.1016/S0305-0548(02)00037-0.
[3]. Niccolò. Gordini. (2014). A genetic algorithm approach for SMEs bankruptcy prediction: Empirical evidence from Italy, Expert Systems with Applications, Volume 41, Issue 14, Pages 6433-6445, ISSN 0957-4174, https://doi.org/10.1016/j.eswa.2014.04.026.
[4]. S. Selvin, R. Vinayakumar, E. A. Gopalakrishnan, V. K. Menon and K. P. Soman. (2017). Stock price prediction using LSTM, RNN and CNN-sliding window model, 2017 International Conference on Advances in Computing, Communications and Informatics (ICACCI), Udupi, India, pp. 1643-1647, doi: 10.1109/ICACCI.2017.8126078.
[5]. Sotirios P. Chatzis., Vassilis Siakoulis., Anastasios Petropoulos., Evangelos Stavroulakis., Nikos Vlachogiannakis. (2018). Forecasting stock market crisis events using deep and statistical machine learning techniques, Expert Systems with Applications, Volume 112, Pages 353-371, ISSN 0957-4174, https://doi.org/10.1016/j.eswa.2018.06.032.
[6]. Lu, W., Li, J., Wang, J. et al. (2021). A CNN-BiLSTM-AM method for stock price prediction. Neural Comput & Applic 33, 4741–4753 https://doi.org/10.1007/s00521-020-05532-z
[7]. Vochozka, M., Rowland, Z., Suler, P., & Marousek, J. (2020). The Influence of the International Price of Oil on the Value of the EUR/USD Exchange Rate. Journal of Competitiveness, 12(2), 167–190. https://doi.org/10.7441/joc.2020.02.10
[8]. C. T. Vidya. & K. P. Prabheesh. (2020). Implications of COVID-19 Pandemic on the Global Trade Networks, Emerging Markets Finance and Trade, 56:10, 2408-2421, DOI: 10.1080/1540496X.2020.1785426