[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
10.1145/3696952.3696996acmotherconferencesArticle/Chapter ViewFull TextPublication PagesiciipConference Proceedingsconference-collections
research-article
Open access

Stock Price Forecasting Based on Improved Particle Swarm Optimization Neural Network Algorithm

Published: 21 November 2024 Publication History

Abstract

The traditional neural network algorithm applied to the forecasting of stock price which is easy to fall into local optima. To enhance the accuracy of stock price forecasting and reduce the forecasting time, this paper introduces the improved Particle Optimization Neural Network Algorithm. By integrating neural networks and particle swarm optimization algorithms, a more effective forecasting model is constructed to better reflect the dynamic changes in stock prices. Meanwhile, the introduction of chaos interference factor and mutation factor can increase the diversity of the algorithm, further improving the accuracy and stability of the forecasting. This method offers a new solution for research and application in the field of stock price forecasting, providing valuable reference for relevant practitioners.

1 Introduction

Traditional stock price forecasting methods are often based on statistical models or time series analysis, such as the moving average method and exponential smoothing method. While these methods can provide certain predictive results, they often perform poorly in handling large-scale, multivariate, and high-dimensional data. Additionally, the predictive accuracy and efficiency of traditional methods are significantly limited. Artificial intelligence models, with their powerful capability to fit nonlinear data, typically outperform traditional analytical methods in processing complex nonlinear financial data. In recent years, to overcome the limitations of traditional methods, big data and artificial intelligence technologies have gradually been applied to stock price forecasting. Various AI models have garnered significant interest, including neural networks, support vector machines, decision trees, and other models and hybrid models. Among these, artificial neural networks (ANNs) have shown substantial potential in capturing complex stock price relationships. However, ANNs, as a type of backpropagation algorithm, may converge to local optima and require tuning numerous network parameters. To address the issue of ANNs easily falling into local optima, this paper proposes using particle swarm optimization to enhance ANNs, constructing a forecasting model to improve the accuracy of forecasting for stock price forecasting.

2 Literature Review

In recent years, with the rapid development of big data and artificial intelligence technologies, stock price forecasting based on statistical analysis and data mining techniques has gained widespread attention in academia and the financial industry. By reviewing existing literature, this paper aims to outline the research progress in this field, identify major technical methods, evaluate their application effects, and explore future research directions.

2.1 Application of Statistical Analysis Methods in Stock Price Forecasting

2.1.1 Classical Statistical Models Machine Learning Methods

Time series analysis is one of the most commonly used methods in financial data analysis and forecasting. The ARIMA model proposed by Box and Jenkins (1976) has been widely applied in predicting stock prices, exchange rates, and other financial indicators. Other studies have combined the GARCH model with machine learning methods for volatility prediction (Liu et al., 2021). Multivariate statistical models are also widely used in asset pricing and risk management, such as multiple linear regression and principal component analysis (PCA), which can handle multiple financial indicators for comprehensive analysis. For example, the three-factor model proposed by Fama and French (1992) uses market risk, company size, and book-to-market ratio as major factors influencing stock returns, providing effective forecasting for asset pricing. Chen et al. (2021) proposed a new multi-factor model that combines principal component analysis and factor analysis, effectively explaining the relationship between market risk and returns.

2.2 Application of Data Mining Techniques in Stock Price Forecasting

2.2.1 Machine Learning Methods

Support vector machines (SVM) perform excellently in classification and regression problems, widely applied in stock price prediction and portfolio optimization. Kim (2003) showed that SVM outperforms traditional linear regression models in stock market prediction. Lee et al. (2020) also demonstrated that SVM effectively identifies market trends and outperforms traditional linear regression models. Decision tree models predict by constructing a tree structure, which is easy to interpret. Random forests enhance prediction accuracy and stability by integrating multiple decision trees (Breiman, 2001), achieving good results in financial fraud detection and credit scoring. Liu et al. (2021) used random forest algorithms for financial fraud detection, showing high efficiency and accuracy in big data environments.

2.2.2 Deep Learning Methods

The initial concept of artificial neural networks (ANNs) was proposed by psychologist McCulloch and mathematician Pitts in 1943, including a mathematical model of neurons, thus opening the door to ANN research. Subsequently, many different neural network models emerged, but most were simple in structure, hence called "first-generation neural network models." ANNs, by simulating biological neural networks, can handle complex nonlinear relationships. In recent years, ANNs have performed well in stock price forecasting, option pricing, and more (Zhang et al., 1998). Wu and Zhao (2022) used deep neural networks to predict the stock market, finding that they outperformed traditional models in capturing market dynamics. Long short-term memory networks (LSTM) are a special type of recurrent neural network (RNN) adept at handling time series data. Fischer and Krauss (2023) showed that LSTM outperforms traditional time series models in stock market forecasting and effectively captures long-term and short-term dependencies in the market. Ensemble learning methods combine multiple models to improve forecasting accuracy and stability.

2.2.3 Intelligent Optimization Algorithms

With the rapid development of artificial intelligence (AI) technology, intelligent optimization algorithms are increasingly applied in the field of stock price forecasting. These algorithms, by simulating human intelligence or the behavior of biological populations, and utilizing the laws of natural phenomena, provide new perspectives and methods for solving complex stock price forecasting problems. Intelligent optimization algorithms such as Genetic Algorithms, Particle Swarm Optimization, and Ant Colony Algorithms have been widely used in stock price forecasting optimization.
Genetic Algorithm (GA) is an optimization algorithm that simulates natural selection and genetic mechanisms, widely used in portfolio optimization and trading strategy formulation. Chen et al. (2021) used Genetic Algorithm to optimize portfolios, significantly improving investment returns and risk management capabilities. In another study, Rani et al. (2020) combined GA with Support Vector Machines (SVM), performing excellently in stock market forecasting, showing the potential of Genetic Algorithm in multi-objective optimization. Particle Swarm Optimization (PSO), by simulating group behavior for global search, is an effective optimization algorithm. Liu et al. (2020) combined Particle Swarm Optimization with deep learning, improving the accuracy of financial time series forecasting. Kumar et al. (2022) used Particle Swarm Optimization to optimize trading strategies, significantly enhancing the returns and stability of trading strategies, demonstrating the adaptability and robustness of Particle Swarm Optimization in dynamic environments.

2.3 Conclusion

With the development of the economy and society, numerous research methods for stock price forecasting have emerged. Due to the ease of implementation and strong fitting ability of neural network algorithms, they have become a favorite among many experts and scholars. As a result, they hold significant potential in stock market forecasting, financial time series analysis, and risk assessment. To date, an increasing number of intelligent algorithms have been developed to optimize artificial neural network algorithms, aiming to enhance the effectiveness of stock price forecasting.

3 Traditional Statistical Analysis Methods

3.1 Moving Average Method

The moving average method is a fundamental smoothing technique that predicts future stock prices by calculating the average of stock prices over a certain period. However, this method performs poorly when dealing with nonlinear trends and sudden events.
The formula is as follows (1):
\begin{equation} {\rm{MAt\ }} = \frac{{P1{\rm{\ }} + {\rm{\ }}... + Pt}}{t}{\rm{\ }} \end{equation}
(1)
Among them, MAt represents the moving average at time t, Pt represents the stock price at the first time point, t is the time window size for the moving average.

3.2 Exponential Smoothing Method

The exponential smoothing method is based on the idea of weighted averaging, applying exponential weighting to historical data to predict future stock prices. However, this method fails to accurately capture complex market fluctuations and nonlinear changes.
The formula is as follows (2):
\begin{equation} {\rm{ESt\ }} = {\rm{\alpha }} \cdot {\rm{Pt}} + \left( {1 - {\rm{\alpha }}} \right){\rm{ESt}} - 1 \end{equation}
(2)
Where ESt represents the exponential smoothing value at time t, Pt represents the stock price at time t, and α is the smoothing coefficient.

3.3 Autoregressive Moving Average Model

The Autoregressive Moving Average (ARIMA) model is a commonly used time series analysis method that considers the autocorrelation and moving average properties of data to capture trends and periodic changes in time series. However, this model requires data to be stationary and linearly related, making it inadequate for handling nonlinear relationships and complex market conditions.

4 Neural Network Algorithm Based on Particle Optimization

4.1 Particle Optimization Algorithm

The Particle Swarm Optimization (PSO) algorithm is a heuristic optimization algorithm whose core concept originates from simulating the collaboration and information sharing among individuals in a flock of birds or a school of fish. PSO can be used to optimize neural network model parameters in stock price forecasting, improving forecasting accuracy. In the PSO algorithm, each search solution is represented as a particle, and each particle's position represents the parameter configuration of the neural network. Particles adjust their positions by tracking their personal best positions and the global best position of the swarm, gradually approaching the optimal solution. The algorithm execution steps are as follows:
Update particle velocity:
\begin{equation} \begin{array}{@{}l@{}} {\rm{Vi}}\left( {{\rm{t}} + 1} \right) = \omega \cdot {\rm{Vi}}\left( {\rm{t}} \right) + {\rm{c}}1 \cdot {\rm{r}}1 \cdot \left( {{\rm{Pbest}},{\rm{i}}\left( {\rm{t}} \right) - {\rm{Xi}}\left( {\rm{t}} \right)} \right)\\ \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; + {\rm{c}}2 \cdot {\rm{r}}2 \cdot \left( {{\rm{Gbest}}\left( {\rm{t}} \right) - {\rm{Xi}}\left( {\rm{t}} \right)} \right) \end{array} \end{equation}
(3)
Vi(t + 1) represents the velocity of particle, ω is the inertia weight,c1 and c2 represent learning factors, r1 and r2 are random numbers, Pbest,i(t) is the personal best position of particle i, Gbest(t) is the global best position of the swarm, and Xi(t) is the current position of particle i.
Update particle position:
\begin{equation} {\rm{Xi}}\left( {{\rm{t\ }} + {\rm{\ }}1} \right){\rm{\ }} = {\rm{\ Xi}}\left( {\rm{t}} \right){\rm{\ }} + {\rm{\ Vi}}\left( {{\rm{t\ }} + {\rm{\ }}1} \right) \end{equation}
(4)
Calculate fitness:
\begin{equation} {\rm{Fitness}}\left( {{\rm{Xi}}\left( {{\rm{t}} + 1} \right)} \right) = \frac{1}{n}\sum\nolimits_{i = 1}^n {\left( {yi - \hat{y}i} \right)2} \end{equation}
(5)
Update personal best position and global best position:
\begin{equation} \begin{array}{@{}l@{}} {P}_{best,i}\left( {t + 1} \right) = {X}_i\left( {t + 1} \right),If\,Fitness\left( {{X}_i\left( {t + 1} \right)} \right) < Fitness\left( {{P}_{best,i}\left( t \right)} \right)\\ {G}_{best}\left( {t + 1} \right) = {X}_i\left( {t + 1} \right),If\,Fitness\left( {{X}_i\left( {t + 1} \right)} \right) < Fitness\left( {{G}_{best}\left( t \right)} \right) \end{array} \end{equation}
(6)

4.2 Introduction of Chaos Perturbation Factor and Mutation Factor

Introducing the Chaos Perturbation Factor and Mutation Factor is an effective method to increase the diversity and global search capability of the algorithm. These factors add greater randomness to the particles during the search process, thereby exploring the parameter space more effectively and avoiding local optima. The Chaos Perturbation Factor introduces randomness by adjusting the particle's velocity and position. Its core idea is to use chaotic sequences to generate random perturbation terms, increasing search diversity.
Chaotic sequences are generated by complex nonlinear dynamical equations like Logistic mapping (7):
\begin{equation} {X}_{n + 1} = r + {x}_n \cdot \left( {1 - {x}_n} \right) \end{equation}
(7)
Where r is the control parameter, and xn represents the n-th element of the chaotic sequence. Mapping the chaotic sequence to an appropriate range and combining it with the particle's original velocity and position yields the Chaos Perturbation Factor C(8).
\begin{equation} {\rm{C}} = \frac{{{\rm{x}} - {\rm{min}}\left( x \right)}}{{\max \left( x \right) - {\rm{min}}\left( x \right)}} \end{equation}
(8)
Here, min(x) and min(x) are the minimum and maximum values of the chaotic sequence, respectively. The Chaos Perturbation Factor adjusts the particle's velocity and position in each iteration, increasing search diversity. The Mutation Factor controls the particle's local variations in the search space. The Mutation Factor is a random term that adjusts the particle's position, maintaining algorithm diversity and avoiding local optima.
The Mutation Factor can be expressed as:
\begin{equation} M = R \times search\,space\,range \end{equation}
(9)
Where the random number R is regenerated by the program in each iteration.

4.3 Neural Network Model

Artificial Neural Networks (ANNs) are currently one of the most popular machine learning algorithms. Due to their powerful nonlinear fitting capabilities and the emergence of various optimization algorithms, neural networks are widely used in fields such as image recognition, speech recognition, and even autonomous driving. An artificial neural network model achieves the desired output by adjusting the network's structure, connection weights, biases, and activation functions. Essentially, it is a composite function that approximates the relationships governed by certain patterns in nature. The following diagram depicts a simple artificial neural network model. This network has three layers. The first layer, the input layer, has two neurons; the second layer, the hidden layer, has five neurons; and the final layer, the output layer, has one neuron. In this model, x represents the input vector,W1 and W1 are the weight vectors from the input layer to the hidden layer and from the hidden layer to the output layer, respectively, b1 and b2 are the bias vectors from the input layer to the hidden layer and from the hidden layer to the output layer, respectively. The function \({\boldsymbol{f}}\) denotes the activation function, and y represents the output.
Figure 1:
Figure 1: Neural Network Model Diagram
The basic structure of an artificial neural network is a neuron, which consists of an input vector X(1,2,…,n), a weight matrix W(1,2,…,n), a bias term b, an activation function \({\boldsymbol{f}}( \cdot )\), and an output y.
The output formula of a neuron is as follows:
\begin{equation} u = W{X}^T + b \end{equation}
(10)
After obtaining the result u from the forward propagation, it will enter the activation function σ(u) for nonlinear transformation. The activation function is crucial for neurons to fit nonlinear functions. Without the nonlinear transformations performed by hidden layers, a neural network can only fit linear relationships and cannot fit nonlinear relationships. Therefore, the activation function is very important. Commonly used activation functions include Sigmoid, Tanh, and ReLU, as shown in the figure below:
Figure 2:
Figure 2: Sigmoid Activation Function
Figure 3:
Figure 3: ReLU Activation Function
Due to the requirement that activation functions be differentiable in neural network algorithms, the Sigmoid and ReLU activation functions are the most common in such algorithms.
This study selects the following key features for forecasting: Stock/Index Historical Prices, Trading Volume and Technical Indicators.
Stock/Index Historical Prices: As sequence data, historical closing prices over a number of past trading days are chosen as features. For example, if the past 20 trading days' data are selected, the number of nodes in the input layer would be 20.
Trading Volume: Typically correlated with stock/index price fluctuations, the past 10 trading days' trading volume is chosen as another feature. Similarly, if X trading days' volume data are selected, X additional nodes are needed.
Technical Indicators: EMA and RSI, commonly used to gauge stock price trends and market forces, are included as features, requiring 2 more nodes.
In summary, this study selects the closing prices of the past 20 trading days, the trading volumes of the past 10 trading days, and 2 technical indicators as input features. The input layer's node count is thus 20+10+2=32. Each node corresponds to a feature, serving as the neural network model's input to predict stock price trends.

5 Experimental Design

5.1 Particle Swarm Optimization Neural Network Algorithm

To overcome the limitations of artificial neural networks, this paper proposes a particle swarm optimization (PSO) algorithm incorporating chaotic disturbance and mutation factors to optimize initial parameters and improve training accuracy. The improved PSO algorithm optimizes the neural network by calculating the weights and biases of each particle in the swarm, evaluating particle fitness, and updating individual and global best values. By continually adjusting particle speed and position, the maximum number of iterations is determined. Optimizing particles provides optimal weights and biases for the neural network. The specific algorithm flowchart is as follows:
Figure 4:
Figure 4: Flow Chart of PSO Neural Network Algorithm

5.2 Data Collection and Preprocessing

This study select daily K-line data (open price, close price, high price, low price, and trading volume) of the CSI 300 Index, CSI 500 Index, and Sg Micro Corp. (code: 300661) from January 1, 2018, to December 31, 2023 (from Wind) as backtest data to construct corresponding stock price forecasting models. Data preprocessing involves data cleaning, including handling missing and abnormal values, removing noise, and ensuring data quality. Missing values are filled using interpolation and mean filling, while abnormal values are processed using the 3σ principle. Continuous data such as stock prices and trading volumes are standardized to maintain consistent scales across features during model training. Min-max normalization maps feature values to the [0, 1].

5.3 Experiment Setup and Parameter Selection

To evaluate the performance of the particle swarm optimization neural network algorithm for stock price forecasting, the study uses deep learning frameworks like TensorFlow to build the model and NumPy for data processing and analysis.
Neural Network Model Configuration: The neural network consists of an input layer, hidden layers, and an output layer, with a learning rate of 0.01. The input layer has nodes based on the number of features (32 in this study), with each hidden layer containing several neurons. The output layer is used for stock price regression forecasting, with ReLU as the activation function.
PSO Algorithm Parameter Settings: The inertia weight range is [0.3, 0.9], with learning factors c1 = c2 = 2, and random numbers r1 and r2 ranging from [0, 1]. A logistic map equation generates chaotic sequences by setting the control parameter r. The mutation factor M is obtained by multiplying a random number R by the search space range.
Training and Testing Parameters: The training set is input into the model, using Mean Squared Error (MSE) as the loss function. The neural network is trained for 200 epochs, with a particle count N=50 and a maximum iterations itmax=500.
Evaluation metrics in this study include Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), forecasting Accuracy, and forecasting Time.

6 FOREcasting Results Analysis

6.1 Algorithm Performance and Accuracy Analysis

6.1.1 Algorithm effect and accuracy

Table 1:
Index/StockAlgorithmRMSEMAEForecasting Accuracy(%)
CSI 300 Index
PSO
Moving Average
10.35
19.73
7.79
15.42
75.86
58.84
 SVM12.6711.6869.56
CSI 500 Index
PSO
Moving Average
12.84
20.16
9.56
15.92
75.46
57.86
 SVM13.7814.2264.29
Sg Micro Corp(300661)PSO
Moving Average
8.68
16.27
6.82
12.33
80.57
64.12
 SVM10.838.0973.58
Table 1: Forecasting Results of Index/Stock Price by Different Algorithms
Forecasting results for stock indexes/prices using different algorithms are shown in Table 1. Experimental results indicate that the particle swarm optimization neural network algorithm achieves relatively low error values across all scenarios, making it more accurate in predicting stock prices. Compared to traditional moving average methods and SWM, the PSO-based neural network method achieves higher forecasting accuracy, particularly for individual stocks like Sg Micro Corp (300661), with forecasting accuracy exceeding 80%, demonstrating its superiority in individual stock forecasting. PSO accurately captures overall market trends, providing investors with more reliable references.

6.1.2 Forecasting time consumption and efficiency

Figure 5:
Figure 5: Forecasting Time Consumption and Efficiency
It can be seen from figure 2 that the stock price forecasting based on the PSO neural network algorithm has a shorter average forecasting time compared to MA and SVM, indicating that this method has higher computational efficiency in the forecasting process and can generate forecasting results faster. In addition, it is also observed that PSO can make more efficient use of computer resources in terms of CPU and GPU usage.

7 Conclusion

Intelligent optimization forecasting techniques based on statistical analysis and data mining have broad application prospects across various fields. We believe that with further technological breakthroughs and practical accumulation, this technology will enhance decision-making efficiency, resource allocation, and inject new momentum into various industries' development. The PSO-based neural network stock price forecasting method proposed in this paper offers a new and effective tool for investment decision-making in the stock market. Future research can further optimize the algorithm, expand data sources, and achieve more precise forecasting, providing investors with more valuable decision support.

Acknowledgments

This work was supported by the project of Wuhan Vocational and Adult Education Association(2023-17Y) and project of Finance and Economics Literacy Education Committee of the Tao Xingzhi Research Association of China(CJZ202403).

References

[1]
Fischer, T., & Krauss, C. 2023. Long short-term memory networks for financial market prediction. Journal of Economic Dynamics and Control, 139, 104261.
[2]
Li, F., & Xu, Y. 2023. Real-time high-frequency data analysis using Kalman Filter. Quantitative Finance, 21(4), 567-580.
[3]
Kumar, R., Singh, S., & Verma, P. 2022. PSO-based trading strategy optimization. Journal of Trading Strategies, 17(2), 117-136.
[4]
Zheng J, Zhang Z, Zou J, et al.2022. A dynamic multi-objective particle swarm optimization algorithm based on adversarial decomposition and neighborhood evolution[J]. Swarm and Evolutionary Computation, 69: 100987.
[5]
Bas, Eren, Erol Egrioglu, and Emine Kolemen. 2022. Training simple recurrent deep artificial neural network for forecasting using particle swarm
[6]
optimization. Granular Computing 7.2:411-420
[7]
Adamu A, Abdullahi M, Junaidu S B, et al. 2021. An hybrid particle swarm optimization with crow search algorithm for feature selection[J]. Machine Learning with Applications, 6: 100108.
[8]
Bootkrajang J, Kabán .2021. A. Label-noise robust logistic regression and its applications[M]. Machine Learning and Knowledge Discovery in Databases. Springer Berlin Heidelberg.
[9]
Bento M E C. 2021. A hybrid particle swarm optimization algorithm for the wide-area damping control design[J]. IEEE Transactions on Industrial Informatics, 18(1): 592-599.
[10]
Wang, J., Liu, Y., & Zhang, H. 2020. Improved ARIMA models for stock price prediction. Journal of Financial Studies, 12(3), 145-160.
[11]
Lee, S., Kim, H., & Park, J. 2020. Support vector machines for stock market prediction. Expert Systems with Applications, 160, 113-129.
[12]
Liu, Q., Zhang, M., & Li, F. 2020. Particle swarm optimization in financial forecasting and optimization. Computational Finance, 31(5), 421-436.
[13]
Rani, R., Gupta, S., & Kumar, V. 2020. Hybrid genetic algorithm and support vector machine for stock market prediction. Expert Systems with Applications, 44(5), 234-245.
[14]
Lohrmann C,Luukka P .2019. Classification of intraday S&P500returnswitharandomforest[J] International Journal of Forecasting,35(1):390-407.
[15]
Kwon O, Tseng K, Tjung L.2017. Time series and neural network forecast of dailystock prices[J]. Investment Management & Financial Innovations, 9(1):32-54.
[16]
Strobelt H, Gehrmann S, Huber B, et al. 2016. Visual Analysis of Hidden State Dynamics in Recurrent Neural Networks[J]. IEEE Transactions on Visualization &Computer Graphics, PP (99):1-1.
[17]
Kim M, Sayama H. Predicting stock market movements using network science: an information theoretic approach[J]. Applied Network Science, 2017, 2(1):35.
[18]
Fama,E.F. 1970."Efficient capital markets; A review of theory and empirical work", Journal of Finance, 25:383-417
[19]
Rather, A. M., Agarwal, A., & Sastry, V. 2015. Recurrent neural network and ahybrid model for prediction of stock returns. Expert Systems with Applications, 42(6),3234–3241.

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Other conferences
ICIIP '24: Proceedings of the 2024 9th International Conference on Intelligent Information Processing
November 2024
419 pages
ISBN:9798400718076
DOI:10.1145/3696952

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 21 November 2024

Check for updates

Author Tags

  1. Neural Network Algorithm
  2. Particle swarm optimization
  3. Stock Price Forecasting

Qualifiers

  • Research-article

Conference

ICIIP 2024

Acceptance Rates

Overall Acceptance Rate 87 of 367 submissions, 24%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 77
    Total Downloads
  • Downloads (Last 12 months)77
  • Downloads (Last 6 weeks)77
Reflects downloads up to 12 Dec 2024

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

HTML Format

View this article in HTML Format.

HTML Format

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media