Introduction

A stock market is a financial exchange where stocks and other securities are traded. It serves as a platform where traders and investors buy and sell equities through designated trading venues known as stock exchanges. In recent years, artificial intelligence (AI) has gained significant traction in the financial sector, particularly in stock market applications.

AI algorithms can analyze vast datasets and utilize the results to support decision-making processes. This capability enhances the accuracy of investment decisions, trend identification, and stock price forecasting. By examining historical stock prices, corporate financial statements, and market trends, AI methods can provide valuable insights into future performance. Furthermore, AI systems can monitor real-time market conditions, detect potential opportunities, and respond dynamically to changes in the trading environment1,2.

In recent years, predicting stock market prices has become increasingly complex due to the inherent volatility and non-linear patterns. Advanced hybrid models, integrating machine learning with optimization algorithms, offer promising solutions. Among these, the combination of ANFIS and chaotic optimization techniques stands out. This study introduces a novel model that leverages the strengths of chaotic Harris Hawks Optimization to enhance the adaptive capabilities of ANFIS, thereby addressing the challenges of accuracy and stability in stock price forecasting.

Recent research has increasingly focused on employing deep learning and AI-based decision-making systems to enhance the accuracy of stock market predictions. Several studies have explored various models and techniques, each aiming to improve forecasting precision.

One comparative study evaluated the effectiveness of a deep feedforward neural network against an artificial neural network (ANN) for predicting stock index prices, demonstrating the potential of deep learning in this context3. Another approach involves using regression analysis through a multilayer perceptron (MLP), an operational ANN model capable of estimating stock market prices4. Among the best time series prediction models is the Adaptive Neuro-Fuzzy Inference System (ANFIS), which has been successfully applied in numerous forecasting tasks5,6,7.

Zheng et al. proposed a novel model called Random Long Short-Term Memory (RLSTM), which builds on the Long Short-Term Memory (LSTM) architecture while addressing the problem of overfitting in stock market index forecasting. By incorporating a sequence of random data with a uniform distribution, RLSTM significantly outperforms conventional models in terms of prediction accuracy8.

Another innovative approach by Chen et al. combined public mood and emotion data with predictive computing to enhance stock market trend forecasting. This model demonstrated superior accuracy compared to traditional machine learning techniques, highlighting the value of integrating sentiment analysis into financial predictions9.

Yeh et al. employed a multiple kernel support vector regression (MKSVR) method to estimate stock market prices, achieving improved predictive performance10. Similarly, Singh et al. introduced a hybrid model known as Wavelet-Based Soft Computing (WSC) to increase forecast accuracy, allowing investors to make more profitable decisions based on reliable stock market estimates11.

In a comparative study focused on classification efficiency, the Support Vector Machine (SVM) technique outperformed ANFIS in detecting finger vein patterns, demonstrating greater computational efficiency and classification power12.

Additionally, Liao et al. proposed a transformer model designed to improve the acquisition of positional information related to long-term emotions. By incorporating ProbAttention and rotating position encoding, the Long-Term Sentiment Change Enhanced Temporal Analysis (LEET) method was validated using the S&P 500 (SP500) and FTSE 100 indexes. Experimental results indicated that LEET outperformed most deep learning architectures commonly used for stock price prediction13.

These advancements underscore the ongoing evolution of AI-based financial forecasting, particularly the integration of hybrid and deep learning models to improve prediction accuracy and computational efficiency.

Recent studies have explored various optimization techniques for financial forecasting, including the use of dendrite neuron models and median dendritic artificial neural networks (Cansu et al.32; Bas et al.33).

Several researchers are looking into optimization techniques to improve the effectiveness of current machine learning algorithms. Lu in14 used PSO to optimize the SVR model’s parameters to make a hybrid stock index forecast model. Shen et al. suggested an optimized a radial basis function NN using the artificial fish swarm algorithm (AFSA) to estimate the Shanghai Security Exchange index15. Gülmez in16 provided a novel LSTM network model for stock market forecast that was optimized LSTM using the Artificial Rabbits Optimization algorithm (ARO). The best model among the models is the LSTM-ARO model, according to the results. Das et al. presented a method to modify the Crow Search Algorithm (CSA) and Extreme Learning Machine (ELM)17. Also, the authors used as PSO depended on Group oriented CSA (PGCSA) techniques. A thorough comparison with some other models in18,19 revealed that the modified method, PGCSA ELM is superior. Qiu et al. applied an attention based Long Short Term Memory NN and a wavelet transform in order to forecast of the stock price. The authors also implemented their method and compared it to other models and showed that the forecasting results from their offered model are more accurate20. Chen and Zhou applied the first technique a Genetic Algorithm (GA) to select the best features, used datasets from the China Construction Bank and the CSI 300 stock index. Moreover, the authors applied the model GA-LSTM, a combination of GA and LSTM, to facilitate efficient feature selection and modeling of intricate stock price dynamics21.

HHO is introduced by Heidari et al. in 2019, a population-based meta-heuristic method. Through the sharing of knowledge amongst Harris Hawks, HHO carries out the best hunting plan and successfully catches the prey22. Some of the shortcomings with the HHO approach include falls into a local optimum solution and sluggish convergence speeds. The population-based optimization technique is recognized to be modifiable in order to search for more precise solutions and avoid various local optima. To overcome these drawbacks and improve the intensification and diversification processes, the dynamical properties of chaos maps were extensively employed. In search procedures and speed parameters, the standard HHO is combined with the chaotic mapping mechanism to achieve this goal. HHO make use of the prey’s earlier unknown position23. Based on algorithmic behavior, the Chaotic Harris Hawk Optimization (ChHHO) is developed. Moreover, chaotic variables are used in place of the random values in. Once combined with chaotic variables, HHO’s exploration is enhanced through the application of the Levy distribution.

ANFIS used for many forecasting challenges and is among the best time series forecasting methods5,6,7. However, there are some shortcomings in the classical ANFIS model’s parameters design. Parameters design are a useful step that influence the performance of solution. Therefore, most of the optimization methods are employed to improve the parameters design process.

The novelty of the proposed ANFIS-ChHHO model lies in its unique integration of the Adaptive Neuro-Fuzzy Inference System (ANFIS) with the Chaotic Harris Hawks Optimization (ChHHO) algorithm. Unlike conventional models, the proposed approach enhances prediction accuracy by addressing the local optima problem often encountered in stock price forecasting. The chaotic mapping mechanism incorporated within the HHO framework significantly improves the exploration and exploitation balance, thus optimizing the ANFIS parameters more effectively. This hybrid model outperforms existing techniques by yielding lower error rates and more reliable predictions, particularly in volatile financial environments. Such advancements demonstrate a significant contribution to the field of stock market prediction, addressing critical challenges inherent in time series forecasting.

In order to get over classical ANFIS limitations, this paper uses ChHHO method to optimize ANFIS parameters in order to get over classical ANFIS limitations. We proposes an optimized ANFIS model that includes the modified HHO meta-heuristic optimization algorithm. The enhanced HHO algorithm is proposed to improve the effectiveness of ANFIS in stock price forecasting. Using stock marketing in Egypt datasets, the ANFIS-ChHHO model’s effectiveness is evaluated and compared with other modified ANFIS models that use some optimization strategies as well as standard ANFIS models. The results indicate that the ANFIS-ChHHO model performs better in stock price prediction than both the other used models and the classical ANFIS model.

The following summarizes this paper’s main contributions:

  1. (i)

    It includes the introduction of the ANFIS-ChHHO model, a stock price time series prediction model.

  2. (ii)

    The developed HHO algorithm to optimize ANFIS parameters in order to get over ANFIS’s limitations.

  3. (iii)

    It evaluates and compares of ANFIS-ChHHO with other models using three datasets. (iv) It optimizes ANFIS parameters using the proposed ANFIS-ChHHO approach in order to improve forecasting precision for the stock prices.

The rest of this work is structured as the following: in Section "Preliminaries", the classical ANFIS and HHO algorithm are discussed. The proposed model ANFIS-ChHHO for predicting stock price is shown in Section "The improved method (Quadratic Chaotic HHO)". The experiments and their results are displayed in Section "Experiments". Lastly, the conclusions and suggested future work are presented in Section "Results".

Preliminaries

Adaptive neuro-fuzzy inference system (Anfis)

The ANFIS model was presented by Jang in 199324 as a combination of two approaches artificial neural networks and fuzzy inference system, it can manage non-linear and complex problems within a structure. Artificial neural networks bring the ability to learn and adapt from data, while fuzzy logic system allows the representation of human-like reasoning and decision-making. The Takagi–Sugeno model is considered the most often utilized fuzzy system in ANFIS model because it is more clear and requires less computing effort than other models. This model operates using the condition IF–THEN logic. ANFIS usually includes five layers as displayed in Fig. 1. Figure 1 describes the fundamental architecture of the ANFIS model which includes five layers. That, the inputs layer1 are x and y, and O1i specifies the node i’s output. The classical ANFIS model can be expressed by Eqs. (1) and (2) as the following:

$${O}_{1i}={\mu }_{{A}_{i}} \left(x\right), i= \text{1,2} {O}_{1i}={\mu }_{{B}_{i}}\left(y\right), i=\text{1,2}$$
(1)
$$\mu \left(x\right)={e}^{{-\left(\frac{x-{\rho }_{i}}{{\alpha }_{i}}\right)}^{2}}$$
(2)

wherever, Every node produces the following output: O1i that represents the membership (Ms) grade for inputs x and y. That, μ (x) is the Generalized Gaussian Ms function, while Ai and Bi are the Ms values of μ(x) . Moreover and αi and ρi display the parameters of the premise. Also, the second layer can be displayed from Eq. (3) as the following:

Fig. 1
figure 1

Classical ANFIS architecture.

$${O}_{2i}={\mu }_{{A}_{i}} \left(x\right)\times {\mu }_{{B}_{i}}\left(y\right) i=\text{1,2}$$
(3)

Furthermore, we define the third layer output as follows from Eq. (4), and this layer includes fixed nodes that compute from the previous layer.

$${O}_{3i}= \overline{{w}_{i}}= \frac{{\omega }_{i}}{{{\omega }_{1}+\omega }_{2}} i=\text{1,2}$$
(4)

Also, the layer 4 nodes are adaptive and apply the following rules: known as the consequent parameters, these parameters are qi, pi and ri. of node i as in Eq. (5):

$${O}_{4i}= \overline{{w}_{i}}{f}_{i}= \overline{{w}_{i}}( {p}_{i}x+{q}_{i}y+{r}_{i})$$
(5)

Lastly, the fifth layer output is calculated as follows from Eq. (6).

$${O}_{5i}=\sum_{i}\overline{{w}_{i}}{f}_{i}$$
(6)

Harris Hawk Optimization Algorithm (HHO)

HHO is a meta-heuristic algorithm that is a population-based algorithm presented by Heidari et al. in 201922. HHO executes the optimal hunting strategy through the information exchange between Harris Hawks and captures the prey. This algorithm consists of three phases are exploration, conversion between exploration and exploitation, and exploitation. The detailed of these stages are as follows:

The first step (Exploration)

During this step, Hawks focus in a search area to hunt preys within the range of the population . Hawks use two methods for finding prey. The first strategy involves perching near other family members when q < 0.5. The second strategy involves randomly choosing a perch on a high pole or tree within their familiar area when q ≥ 0.5. The hawk’s position is updated during the exploration phase using Eq. (7).

$${z}_{m}\left(t+1\right)=\left\{\begin{array}{c}{\text{z}}_{r}\left({\text{t}}\right)-{\text{r}}_{1}\left|{\text{z}}_{r}\left({\text{t}}\right)-{2\text{r}}_{2} z\left(t\right)\right|, q\ge 0.5\\ {(\text{z}}_{prey}\left({\text{t}}\right)-{\text{z}}_{m}\left({\text{t}}\right))-{\text{r}}_{3}(L+ {\text{r}}_{4}\left( U-L\right)), q<0.5\end{array}\right.$$
(7)
$${z}_{m}\left(t\right)=\frac{1}{M}{\sum }_{k=1}^{M}{z}_{k}(t))$$
(8)

where z(t + 1) indicates the position of the hawks in the next iteration. zprey(t) denotes the place of the prey. z(t) denotes the location of the hawks in the current iteration t, r1 – r4 and q are randomly between 0 and 1. The upper and lower boundaries of the population are represented by U and L, in that order. zr (t) indicates a hawk selected at random from the present population. The average of the individual positions in the present population, as given in Eq. (8), is presented as zavg (t), N is the number of hawks.

The second step: transition phase between exploration and exploitation

In this step, The HHO method uses the prey’s escaping energy to switch between exploration and exploitation stages. This step used two search approaches through the prey’s escape energy EE′, when EE′ ≥ 1 the method selects exploring the search space for new solutions and when EE′ < 1 it switches to find the best solutions found during exploration, the Eq. (9) is as:

$$EE^{\prime}=2{E}_{0}\left(1-\frac{t}{T}\right)$$
(9)
$$E_{0} = 2*r_{5} - 1$$
(10)

where, EE′ denotes the escaping energy of the prey at a certain iteration. E0 as in Eq. (10) shows the initial value of energy of the prey. The t and T are the current iteration number and the maximum number of iterations respectively.

The third step (Exploitation)

Through, this stage involves searching and monitoring prey behavior, waiting for the optimal time to attack. The exploitation phase results the actual attack, where the hawk utilizes four various approaches to capture its prey. The process switches from exploration to exploitation when a specific energy level (EE′) drops below a threshold (|EE′|< 1). The hawk’s strategy depends on the prey’s ability to escape, signified by a random number (r) between 0 and 1.

First strategy

Soft Siege, the victim attempts to get away from the chase by skipping, if (|EE′|≥ 0.5 & r ≥ 0.5), the HH can evenly bounded it, fatiguing the prey and then held it. This procedure is demonstrated as follows in Eqs. (11) and (12):

$$z\left( {t + 1} \right) = z\left( t \right) - EE^{\prime } \left| {Jz_{prey} \left( t \right) - z\left( t \right)} \right|$$
(11)

where

$$\Delta z\left({\text{t}}\right)={\text{z}}_{prey}\left({\text{t}}\right)- z\left(t\right)\text{ and }{\text{J}}=2(1-{r}_{5})$$
(12)

That, \(\Delta z\left({\text{t}}\right)\) shows the difference between the prey’s position and its current position and J denotes the random jump power of the prey.

Second strategy

Hard Siege, in this scenario the prey’s energy is low and the hawk can attack the prey strongly, if (r ≥ 0.5 & |EE′|< 0.5). This step is showed in Eq. (13) is as:

$$z\left(t+1\right)={\text{z}}_{prey}\left(t\right)-EE{\prime} \left|\Delta z\left({\text{t}}\right)\right|$$
(13)
Third strategy

Progressively rapid dives during a soft besiege, in this case, the victim has mandatory energy to get away, If (r < 0.5 & |EE′|≥ 0.5), but the hawk uses the skilled approach is called Levy flight (Lf) to trace irregular motions of the prey. The hawk dives fast and unpredictable to right its position and show the best changes. This approach is displayed as the following:

Where, u, v are random values belongs to (0,1), β = 1.5, X and Y are computed by Eqs. (14) and (15).

Third strategy

Progressively rapid dives during a soft besiege, in this case, the victim has mandatory energy to get away, If (r < 0.5 & |EE′|≥ 0.5), but the hawk uses the skilled approach is called Levy flight (Lf) to trace irregular motions of the prey. The hawk dives fast and unpredictable to right its position and show the best changes. This approach is displayed as the following:

$$X = z_{prey} \left( t \right) - EE^{\prime } \left| { J z_{prey} \left( t \right) - z\left( t \right)} \right|$$
(14)
$$Y = X + S. LF\left( D \right)$$
(15)
$$LF\left( z \right) = 0.01 \frac{u \times \sigma }{{\left| v \right|^{{\frac{1}{\beta }}} }}, \sigma = \left( {\frac{{\Gamma \left( {1 + \beta } \right) \times \sin \left( {\frac{\pi \beta }{2}} \right)}}{{\Gamma \left( {\frac{1 + \beta }{2}} \right) \times \beta \times 2^{{\left( {\frac{\beta - 1}{2}} \right)}} }}} \right)^{{\frac{1}{\beta }}}$$
(16)

where, u, v are random values belongs to (0,1), β = 1.5, X and Y are computed by Eqs. (14) and (15).

$$z(t+1)=\left\{\begin{array}{c}X if F\left(X\right) < F(z\left(\text{t}\right))\\ Y if F\left(Y\right) < F(z\left(\text{t}\right))\end{array}\right.$$
(17)

wherever Lf( ) is the function of levy flight, Rvec is a random vector, and Dim is the dimension of the stated problem. The location of the Hawks is updated from Eq. (17).

2.2.3.4 The fourth part: hard besiege with rapid diving, if (r < 0.5 & |EE′|< 0), the prey is very fatigued to flee and the hawk surrounds it. The best time to the hawk is decide by the average of the locations of the prey, which is given in Eqs. (20).

$$X^{\prime } = z_{prey} \left( t \right) - EE^{\prime } \left| { J \times z_{prey} \left( t \right) - z_{m} \left( t \right)} \right|$$
(18)
$$Y^{\prime } = X^{\prime } + S \times LF\left( D \right)$$
(19)
$$z(t+1)=\left\{\begin{array}{l}X^{\prime} if F\left(X^{\prime}\right) < F(z\left(\text{t}\right))\\ Y^{\prime} if F\left(Y^{\prime}\right) < F(z\left(\text{t}\right))\end{array}\right.$$
(20)

where X and Y\({\prime}\) are computed by Eqs. (18) and (19), zavg(t) is found in Eq. (8).

In the following section, we show the improved technique.

The improved method (Quadratic Chaotic HHO)

In this section, we presented an improved HHO algorithm, which is based on chaos. In deterministic nonlinear systems, chaos is a restricted dynamic behavior characterized by nonlinear systems, unpredictable behavior and sensitivity. The use of chaotic systems in meta-heuristic algorithms for the initial population has increased recently. Some of the shortcomings with the HHO approach include falls into a local optimum solution and slow convergence speeds. Our objective, we improve the population initialization and the exploration capabilities of the method, the enhanced algorithm can accomplish a superior balance between the exploration phase and exploitation to get the best solution. HHO use the prey’s position, which is unknown earlier23. Based on algorithmic behavior, we have created the Chaotic HHO (ChHHO). Additionally, chaotic variables are used in place of the random values in ChHHO. HHO makes use of the Levy distribution, which improves the HHO’s exploration when combined with chaotic variables. Enhancing the initial population of HHO is the goal of ChHHO in order to improve the average population which lead to an efficient search process and better convergence.

From the types of used chaotic maps as a logistic, a tent, a Chebyshev, a Gauss, a Circle, and a Sine chaotic maps25,26. Among these types, it was found that logistic chaotic map is better in convergence and ergodicity25. Yuan et al., used Singer, Gauss, and tent chaotic maps to enhance the technique’s performance25. In this work, we used the quadratic chaotic map to enhance the population initialization and the exploration capabilities of our approach as showed in Eq. (21).

$$x_{i + 1} = a - x_{i}^{2} l,\;a = 1.4$$
(21)

where xi is a control parameter, and the value range is (0,1), a is constant equal 1.4 as in27.

The uniqueness of the proposed ANFIS-ChHHO algorithm lies in its ability to dynamically adjust the search space by integrating chaotic variables. This not only prevents premature convergence but also improves prediction stability, making it more effective for volatile financial data.

Algorithm 1 demonstrates the improved Harris Hawk Optimization method.

Algorithm 1
figure a

The framework of the proposed model ANFIS – ChHHO.

The workflow of the ANFIS-ChHHO model

This section presents the proposed ANFIS-ChHHO model for stock market prediction. The parameters of ANFIS are optimized with the ChHHO methodology, which enhances the efficacy of the HHO method. The ANFIS model is optimized using the improved HHO (ChHHO) approach for stock market forecasting. The steps are illustrated in Fig. 2. In the ANFIS-ChHHO model, the initial phase involves partitioning the stock market data into two subsets: the training set, including 70% of the whole data, and the testing set, which contains 30% of the overall data In the following step, the improved algorithm is used to search for the optimal parameters of the ANFIS model. Lastly, the ANFIS model with the optimal parameters is used to predict of the stock.

Fig. 2
figure 2

The framework of the proposed model ANFIS – ChHHO.

The main steps of framework of the proposed model ANFIS-ChHHO:

Step 1: Prepare the datasets and initialize the parameters.

Step 2: Divide the data into training and testing.

Step 3: Design the ANFIS network, train the ANFIS network and calculate the expected output of the training data as shown in the Eq. (22) .

$$\text{MSE}= \frac{1}{\text{N}} \sum_{\text{i}=1}^{\text{N}}(\text{X}_{\rm i}-{\text{PX}_{\rm i})}^{2}$$
(22)

That, Xi is actual value, PXi is expected value and N is number of samples.

Step 4: Update ANFIS model by using the improved HHO.

Step 5: Evaluate the current solution, checked the terminal condition and repeated the steps until the end of the condition.

Step 6: The training result is tested with the test data.

Step 7: The best ANFIS model is used for prediction of the stock.

Experiments

To clearly highlight the effectiveness of the proposed model, we present a comparative analysis using newly introduced performance metrics such as RMSRE, MSRE, MARE, and RMSPE. Additionally, structured subheadings were added to delineate the results for each dataset (EGX-30, EGX-70, EGX-100). Each subsection now includes detailed comparative tables and graphical illustrations to visualize the performance differences. The inclusion of real-world stock prediction scenarios further demonstrates the practical implications of the proposed model, showing its potential in financial decision-making processes.

Datasets

In this work, we apply on the Egyptian Stock Exchange (EGX ) on the historical data for three stock indices: the EGX-30 Index (EGX30), EGX-70 Index (EGX70), and EGX-100 Index (EGX100). These datasets are from January 3, 2010, to June 27, 2019. These data are collected from (https://www.investing.com). The basic transaction datasets contain of six variables. The feature of open price present the value at which a security is implemented per share when the market opens while the feature of close price is the value at which a security is managed per share when the market close. A stock’s daily high and low are its highest and lowest values, in that order. The quantity of a operation in a given amount of time is mentioned as its volume. The datasets include six features: date, open, high, low and close prices and the volume as presented in Table 1. This work employs four features: open, high, and low prices as input variables of the proposed model ANFIS-ChHHO for evaluating the close price of the following day.

Table 1 Partial stock data samples for EGX-30.

Performance metrics

Four evaluation metrics are employed in this study as Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and Standard deviation (SD)28,29,30,31. The smallest values of these metrics demonstrate better predicted data. Also, Theil’s U is used to determine the predicting accuracy. The minimum value of Theil’s U demonstrates more accuracy of prediction17. These metrics are computed by the following Eqs. (23)–(26):

$$MAE = \frac{1}{N}\mathop \sum \limits_{i = 1}^{N} \left| {Y_{i} - PY_{i} } \right|$$
(23)
$$RMSE=\sqrt{\frac{1}{N} \sum_{i=1}^{N}{({Y}_{i} - P{Y}_{i})}^{2}}$$
(24)
$$SD=\frac{1}{N} \sum_{i=1}^{N}{({Y}_{i} - {\overline{Y} }_{i})}^{2}$$
(25)
$${\text{Theil}}'{\mathrm{s}}\;U = \frac{{\sqrt {\frac{1}{N} \mathop \sum \nolimits_{i = 1}^{N} \left( {Y_{i} - PY_{i} } \right)^{2} } }}{{\sqrt {\frac{1}{N} \mathop \sum \nolimits_{i = 1}^{N} \left( {Y_{i} } \right)^{2} } + \sqrt {\frac{1}{N} \mathop \sum \nolimits_{i = 1}^{N} \left( { PY_{i} } \right)^{2} } }}$$
(26)

The new metrics in Eqs. (27)–(29):

$$MSRE=\frac{1}{N} \sum_{i=1}^{N}{\{{Y}_{i} - P{Y}_{i})/{Y}_{i}\}}^{2}$$
(27)
$$RMSRE=\sqrt{\frac{1}{N} \sum_{i=1}^{N}{\{{(Y}_{i} - P{Y}_{i})/{Y}_{i}\}}^{2}}$$
(28)
$$RMSRE=\sqrt{\frac{1}{N} \sum_{i=1}^{N}{\{{Y}_{i} - P{Y}_{i})/{Y}_{i}\}}^{2}*100}$$
(29)
$$MARE = \frac{1}{N}\mathop \sum \limits_{i = 1}^{N} \left| {(Y_{i} - PY_{i} )/Y_{i} } \right|$$
(30)

The metrics are MARE, MSRE, RMSRE, RMSPE are refer to Mean Absolute Relative Error, Mean Squared Relative Error, Root Mean Squared Relative Error and the last is Root Mean Squared Percentage Error and these metrics the minimum is better.

Where \({\text{Y}}_{\text{i}},\) \({\text{PY}}_{\text{i}}\) are the values of target and predicted respectively. \(\overline{{\text{Y} }_{\text{i}}}\) is the mean value of target. \(N\) is number of samples.

Comparison to other predicting approaches

In this study, the ChHHO-ANFIS compared to some meta-heuristics algorithms as HHO algorithm, particle swarm optimization algorithm (PSO), grey wolf optimization algorithm (GWO), and the classical ANFIS models. The dataset is divided into 70% for training and 30% for testing in all work. Table 2 presents the settings for all techniques, which were executed separately several times and the CPU is Intel (R) Core (TM) i7-6600U CPU @ 2.60GHz 2.80 GHz, MATLAB 2016a is used for all operations.

Table 2 Parameter setting.

Results

Results of EGX-30

In this section, we use the EGX-30 a first stock marketing datasets to evaluate the proposed ANFIS-ChHHO technique. We considered several well-known optimization algorithms to be compared the proposed method, including the classical ANFIS model as the standard HHO algorithm, PSO algorithm and GWO algorithm. The findings of all models record in Table 3 about, MAE, RMSE, SD and Theil’s U. We can see that the ANFIS-ChHHO accomplished the best MAE value, then came ANFIS-HHO, ANFIS, ANFIS-PSO and ANFIS-GWO model in that order. Also, the ANFIS-ChHHO also got the best RMSE value, where ANFIS-HHO obtained the second rank. Other models came in the following order, ANFIS, ANFIS-PSO and ANFIS-GWO. Further, the ANFIS-ChHHO attained the best Theil’s U value of 0.0019, and ANFIS model got the second rank, and two models obtained the third rank, ANFIS- HHO and ANFIS-PSO, and ANFIS-GWO model attained the fourth rank. More, the ANFIS- ChHHO come in the first rank in the measured of SD, after that ANFIS-HHO, ANFIS, PSO-ANFIS, and GWO-ANFIS respectively. Also, Figs. 3a–e and 4 demonstrate the results of prediction of the next closing price day of the ANFIS-ChHHO compared to other models. It is clear that our method is better than other models with the nearest values to the target data. Figure 4 illustrates the results of the RMSE, MAE, and SD metrics for testing the five models (AMF5, AMF5-CHH4O, AMF5-HHO, AMF5-PSO, and AMF5-GWO) on the EGX-30 dataset.

Fig. 3
figure 3figure 3

Prediction results of EGX-30 dataset.

Fig. 4
figure 4

The results of metrics EGX-30 for testing the five models.

To further validate the robustness of the proposed model, we calculated additional performance metrics: RMSRE, MSRE, MARE, and RMSPE. These metrics provide a more comprehensive evaluation of prediction accuracy. As depicted in Tables 3, 4, the ANFIS-ChHHO model consistently outperformed conventional models across all metrics, indicating its superior generalization ability.

Table 3 Prediction performance of different models (ANFIS, ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) on the EGX-30 index testing set: RMSE, MAE, SD, and Theil’s U.
Table 4 Prediction performance of different models (ANFIS, ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) on the EGX-30 index testing set: MARE, MSRE, RMSRE, and RMSPE.

The predictive performance of various ANFIS-based models (ANFIS, ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, and ANFIS-GWO) on the EGX-30 index testing set is systematically evaluated across multiple error metrics. Table 3 compares the models using traditional accuracy measures (RMSE, MAE, SD, and Theil’s U), revealing ANFIS-ChHHO’s superior performance with the lowest RMSE (38.2695) and Theil’s U (0.0019). Table 4 extends this analysis to relative error metrics (MARE, MSRE, RMSRE, and RMSPE), where ANFIS-ChHHO again demonstrates robustness, particularly in MARE (0.002792). Finally, Table 5 consolidates all eight metrics, providing a comprehensive view of model performance; notably, ANFIS-ChHHO maintains consistently competitive results across all measures, while ANFIS-GWO exhibits the highest errors (e.g., RMSE: 64.9128, Theil’s U: 0.0033), highlighting the impact of optimization techniques on prediction accuracy.

Table 5 Performance metrics of ANFIS-based models (ANFIS, ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) on EGX-30 index testing set: RMSE, MAE, SD, Theil’s U, MARE, MSRE, RMSRE, and RMSPE values.

Results of EGX-70

In this part, we assess the proposed ANFIS-ChHHO method using the EGX-70 dataset. The findings of all models list in Table 4 about, MAE, RMSE, SD and Theil’s U. it is clear that the proposed approach got the best RMSE value, then ANFIS-HHO, ANFIS-PSO, ANFIS and ANFIS-GWO model, in that order. Also, ANFIS-ChHHO got the best MAE value, where ANFIS-PSO achieved the second rank. Other models as the following, ANFIS-HHO, ANFIS model and ANFIS-GWO. Further, the ChHHO-ANFIS attained the best Theil’s U value of 0.0019, and two models obtained the second rank ANFIS-HHO and ANFIS-PSO, ANFIS model got the third rank, and ANFIS-GWO model obtained the fourth rank. Also, the ANFIS-ChHHO came in the first rank in measured of SD, followed by ANFIS-HHO, ANFIS-PSO, ANFIS and the ANFIS-GWO model. Furthermore, Figs. 5a–e and 6 display the results of the all methods and the ANFIS-ChHHO of prediction of the next closing price day of the proposed method to compare the other models. As saw that, the proposed method achieved the closest values to the real data.

Fig. 5
figure 5figure 5

Prediction results of EGX-70 dataset.

Fig. 6
figure 6

The results of metrics EGX-70 for testing the five models.

The predictive performance of ANFIS and its hybrid variants on the EGX-70 index is comprehensively evaluated across multiple metrics (Tables 6, 7, 8). Table 6 demonstrates ANFIS-ChHHO’s superiority in absolute error metrics (RMSE: 2.2414, MAE: 1.5336) and stability (Theil’s U: 0.0019), outperforming standard ANFIS by 13–15%. Table 7 further confirms this advantage in relative error measures, with ANFIS-ChHHO achieving the lowest MARE (0.002815) and RMSPE (0.40613), reflecting 9–33% improvements over other hybrids. The consolidated results in Table 8 reveal ANFIS-ChHHO’s consistent dominance across all eight metrics, particularly in MSRE (1.6824 × 10−5) and RMSRE (0.0040613), while ANFIS-PSO and ANFIS-GWO exhibit higher deviations. Together, these tables underscore the robustness of the ChHHO-optimized model for EGX-70 index forecasting.

Table 6 Performance comparison of different ANFIS-based hybrid models (ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) and standalone ANFIS in predicting the EGX-70 index for the testing set, evaluated using RMSE, MAE, SD, and Theil’s U statistics.
Table 7 Comparative performance of ANFIS and its hybrid variants (ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) in predicting the EGX-70 index for the testing set, assessed using MARE, MSRE, RMSRE, and RMSPE metrics.
Table 8 Comprehensive performance evaluation of ANFIS and its hybrid variants (ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) in forecasting the EGX-70 index across multiple error metrics (RMSE, MAE, SD, Theil’s U, MARE, MSRE, RMSRE, RMSPE) for the testing set.

Figure 6 displays the results of metrics EGX-70 for testing the five models, while Fig. 5a–e are expressed the prediction results of EGX-70 dataset.

Results of EGX-100

The proposed ANFIS-ChHHO approach is considered in this section using the EGX-100 dataset. Table 5 records the results of all models of the values, MAE, RMSE, SD and Theil’s U. As we can see, the ANFIS-ChHHO model got the best RMSE value, followed by the models ANFIS, ANFIS-GWO model, ANFIS-PSO, and ANFIS-HHO. Also, ANFIS- ChHHO obtained the best MAE value, while ANFIS came in second. After that, the ANFIS-GWO, ANFIS-PSO and ANFIS-HHO model. More, the ANFIS-ChHHO achieved the best Theil’s U value of 0.00161, and two models obtained the second rank ANFIS-GWO and ANFIS model, ANFIS-PSO model got the third rank, ANFIS-HHO came the fourth rank. Also, the ANFIS-ChHHO came in the first rank in the measured of SD, followed by ANFIS, ANFIS-GWO model, the ANFIS-PSO, and ANFIS-HHO. Moreover, Figs. 7a–e and 8 indicate the results of the all methods and the ANFIS-ChHHO for forecast of the next closing price day compared to other models is better and it is values that are closest to the original data.

Fig. 7
figure 7figure 7

Prediction results of EGX-100 dataset.

Fig. 8
figure 8

The results of metrics EGX-100 for testing the five models.

The forecasting performance of ANFIS and its hybrid variants on the EGX-100 index is systematically evaluated across three key dimensions (Tables 9, 10, 11). Table 9 establishes ANFIS-ChHHO’s superior accuracy in absolute terms, achieving the lowest RMSE (3.8001) and MAE (2.7368), representing 2.8–11.3% improvements over other models. Table 10 reveals even more striking advantages in relative error metrics, where ANFIS-ChHHO demonstrates 42–74% reductions in MSRE (1.3892 × 10−5) and RMSPE (0.37272) compared to standard ANFIS. The comprehensive comparison in Table 11 consolidates these findings, showing ANFIS-ChHHO’s consistent top performance across all eight evaluation criteria, including SD (3.7873) and Theil’s U (0.00161). Notably, while ANFIS-HHO shows competitive absolute errors, its relative errors remain higher, and ANFIS-GWO emerges as the least accurate hybrid. These results collectively highlight ANFIS-ChHHO as the most reliable model for EGX-100 index prediction, particularly for applications requiring precise relative error control.

Table 9 Performance comparison of ANFIS and hybrid ANFIS models (ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO) in forecasting the EGX-100 index, evaluated using RMSE, MAE, SD, and Theil’s U metrics.
Table 10 Comparative analysis of relative error metrics (MARE, MSRE, RMSRE, RMSPE) for ANFIS and its hybrid variants in predicting the EGX-100 index.
Table 11 Comprehensive performance evaluation of ANFIS and its hybrid variants (ANFIS-ChHHO, ANFIS-HHO, ANFIS-PSO, ANFIS-GWO) in forecasting the EGX-100 index, assessed through multiple accuracy metrics (RMSE, MAE, SD, Theil’s U, MARE, MSRE, RMSRE, RMSPE).

The following figures, Fig. 7a–e, are the prediction results of EGX-100 dataset.

In addition to the EGX datasets, we applied the model to the NASDAQ and S&P 500 indices. Figure 8 indicates the results of metrics EGX-100 for testing the five models. The results demonstrated consistent performance improvements, highlighting the model’s robustness across diverse financial environments as in Tables 12, 13, 14, 15, 16, and 17 and Figs. 9a–e and 10a–e.

Table 12 Comparative performance of ANFIS and hybrid ANFIS models in forecasting the NASDAQ index, evaluated through RMSE, MAE, SD, and Theil’s U metrics.
Table 13 Relative error analysis of ANFIS and hybrid variants in NASDAQ index prediction.
Table 14 Comprehensive performance evaluation of ANFIS and hybrid variants in NASDAQ index forecasting, demonstrating ANFIS-ChHHO’s dominant performance across all metrics.
Table 15 Performance comparison of ANFIS and hybrid models in S&P 500 index forecasting, with ANFIS-ChHHO demonstrating superior predictive accuracy.
Table 16 Relative error analysis of ANFIS-based models for S&P 500 index prediction, showing ANFIS-ChHHO’s superior performance with the lowest MARE (0.0032336), MSRE (2.0298 × 10−5), RMSRE (0.0045054), and RMSPE (0.45054).
Table 17 Comprehensive performance evaluation of ANFIS and hybrid models for S&P 500 index forecasting, demonstrating ANFIS-ChHHO’s superior accuracy across all metrics.
Fig. 9
figure 9figure 9

Prediction results of NASDAQ dataset.

Fig. 10
figure 10figure 10

Prediction results of S&P 500 dataset.

The datasets in both NASDAQ and S&P 500 from 8/11/2019 6:05:00 PM to 8/16/2019 4:10:00 AM and the data each 5 min. The number of rows 1214 . from (https://www.investing.com).

Results in Table 12 demonstrate ANFIS-ChHHO’s superior predictive accuracy with the lowest error values (RMSE = 2.1893, Theil’s U = 0.000142), while standard ANFIS and other hybrid variants show comparatively higher deviations. Notably, ANFIS-ChHHO achieves a 28% reduction in RMSE compared to baseline ANFIS.

Table 13 shows ANFIS-ChHHO’s exceptional performance with the lowest MARE (0.00019011), MSRE (8.2808e-8), RMSRE (0.00028776), and RMSPE (0.028776) – outperforming standard ANFIS by an order of magnitude in MARE and demonstrating 33–92% improvement across all metrics compared to other hybrid models.

In Table 14: The model achieves superior results with: lowest RMSE (2.1893), MAE (1.7183), Theil’s U (0.000142), MARE (0.00019011), MSRE (8.2808e-8), RMSRE (0.00028776), and RMSPE (0.028776) – showing 28–93% improvement over standard ANFIS and consistently outperforming other hybrid models in predictive accuracy and stability.

The following figures, Fig. 9a–e, indicate the prediction results of NASDAQ dataset.

The model in Table 15 achieves the lowest error metrics (RMSE = 38.1724, MAE = 26.7329, Theil’s U = 0.0019104), showing 31.2–32.3% improvement in RMSE and MAE over standard ANFIS, while maintaining the most stable predictions (SD = 38.0415). ANFIS-HHO shows comparable performance, whereas ANFIS-GWO performs closest to the baseline model.

OR

If used these metrics only

As indicated in Table 16: the hybrid model demonstrates 29–62% improvement across all error metrics compared to standard ANFIS, with particularly strong gains in MSRE (62% reduction) and RMSPE (32% reduction). ANFIS-HHO and ANFIS-PSO show intermediate performance, while ANFIS-GWO remains closest to the baseline model’s results.

The optimal model in Table 17 achieves: lowest RMSE (38.1724, 31.2% improvement), MAE (26.7329, 32.3% reduction), Theil’s U (0.0019104), MARE (0.0032336), MSRE (2.0298 × 10−5), RMSRE (0.0045054), and RMSPE (0.45054), outperforming standard ANFIS by 29–62% across relative error measures. ANFIS-HHO shows comparable absolute errors but slightly higher relative errors, while ANFIS-GWO performs closest to the baseline, highlighting the effectiveness of the ChHHO optimization approach.

The following figures, Fig. 10a–e, are prediction results of S&P 500 dataset.

Discussion

The sensitivity of the model to various input features was examined using a feature importance analysis. Results indicated that the open and high prices significantly influenced the prediction accuracy, while the low prices had a relatively lower impact. The computational complexity analysis demonstrated that the proposed ChHHO model significantly reduces convergence time compared to traditional methods, making it suitable for real-time forecasting.

The results from all datasets, including measures such as RMSE, MAE, SD, and Theil’s U, indicate that the proposed approach yields favorable outcomes across all utilized datasets. Compared to the classical ANFIS model, the proposed method attains the lowest error rate during the testing phase, demonstrating superior performance. Additionally, the various optimization techniques were assessed, including HHO, PSO, and GWO. The findings indicate that the proposed method surpassed all others regarding RMSE, MAE, SD, and Theil’s U. All tests in the study demonstrate the impact of ChHHO on optimizing the parameters of the ANFIS model.

In summary, the assessment experiments indicate that the implementation of the ChHHO substantially influences the efficacy of the classical ANFIS model. Furthermore, the chaotic mapping improved the efficacy of the basic HHO method, resulting in the ANFIS-ChHHO outperformed all other models in every measurable aspect.

Table 18 shows the predictive outcomes of several stock indices based on specific assessment measures through the current study and similar studies in literature.

Table 18 Comparison of similar studies in the literature.

Conclusions

In this paper, we propose an optimized Adaptive Neuro-Fuzzy Inference System (ANFIS) approach for stock market prediction. The classical ANFIS model has been enhanced using an improved Harris Hawks Optimization (HHO) algorithm to increase forecasting accuracy. The modified model, referred to as ANFIS-ChHHO, was evaluated using three datasets from the Egyptian Stock Exchange. To assess its performance, we compared the proposed model with the classical ANFIS model, as well as with other enhanced ANFIS variants, including ANFIS-HHO, ANFIS-PSO, and ANFIS-GWO.

The evaluation metrics used to compare the models were Root Mean Square Error (RMSE), Mean Absolute Error (MAE), Standard Deviation (SD), and Theil’s U. The results demonstrated that the ANFIS-ChHHO model significantly outperformed the classical ANFIS model and its enhanced counterparts, indicating superior forecasting precision.

Additionally, this study details the development of the HHO algorithm to improve its initial population by incorporating chaotic techniques, resulting in a more efficient search process and better convergence. The integration of the Levy distribution further enhances the HHO’s exploration capabilities when combined with chaotic mapping.

Future improvements to the ANFIS-ChHHO model could involve the incorporation of hybrid wavelet techniques to achieve even greater predictive accuracy. This potential enhancement could further optimize the model’s performance, especially in scenarios characterized by high market volatility.

Despite the promising results, the proposed model has certain limitations, including the computational overhead associated with chaotic mapping. Additionally, the model’s performance may vary with different stock datasets. Future research will explore integrating other hybrid optimization techniques, such as Genetic Algorithms, to further enhance accuracy and stability. Future research will explore the integration of deep learning techniques with chaotic optimization to further enhance predictive accuracy, especially in high-frequency trading scenarios.