Hybrid Clustering-GWO-NARX neural network technique in predicting stock price

Prediction of stock price is one of the most challenging tasks due to nonlinear nature of the stock data. Though numerous attempts have been made to predict the stock price by applying various techniques, yet the predicted price is not always accurate and even the error rate is high to some extent. Consequently, this paper endeavours to determine an efficient stock prediction strategy by implementing a combinatorial method of Grey Wolf Optimizer (GWO), Clustering and Non Linear Autoregressive Exogenous (NARX) Technique. The study uses stock data from prominent stock market i.e. New York Stock Exchange (NYSE), NASDAQ and emerging stock market i.e. Malaysian Stock Market (Bursa Malaysia), Dhaka Stock Exchange (DSE). It applies K-means clustering algorithm to determine the most promising cluster, then MGWO is used to determine the classification rate and finally the stock price is predicted by applying NARX neural network algorithm. The prediction performance gained through experimentation is compared and assessed to guide the investors in making investment decision. The result through this technique is indeed promising as it has shown almost precise prediction and improved error rate. We have applied the hybrid Clustering-GWO-NARX neural network technique in predicting stock price. We intend to work with the effect of various factors in stock price movement and selection of parameters. We will further investigate the influence of company news either positive or negative in stock price movement. We would be also interested to predict the Stock indices.


Introduction
For few decades, stock market is one of the best investment options for investors despite stock price being uncertain and unpredictable. Due to the nonlinear nature of stock, the prediction of stock price is are available based on time series data and factors for stock prediction. Xu has attempted to predict weekly stock price by mingling the conventional time series analysis technique with information from the Google trend website and the Yahoo finance website. He had found that there is a correlation between the changes in weekly stock prices and the values of important news/events computed from the Google trend website. He also argued that his result is better than traditional time series analysis however he has also agreed that his study has many drawbacks as well. He has finally suggested that further research can be conducted to improve the stock prediction and more accurate algorithm can be used for such prediction [10]. Statistical analysis is another way of making stock prediction by applying regression, co-linearity, ARIMA and so on. But, main drawback of statistical model is that it can deal with linear data whereas stock data is non-linear in nature. Due to this reason, the statistical model is becoming obsolete.

Stock prediction using data mining: Issues and Challenges
Extracting knowledge from database is known as Data mining. Data mining is able to extract the appropriate data based on various techniques i.e. Classification, Prediction, Clustering, Association. Classification and Prediction is predictive model, whereas Clustering and Association is descriptive model. Unknown pattern of data can be discovered through data mining [11]. Kannan et al. has emphasized that the amount of data is growing day by day and hence we need to apply an appropriate technique to better manage the huge amount of data. Therefore, data mining is identified as very demanding and one of the best key research areas in data management. So, they have applied data mining technology and performed data analysis to predict whether the closing price of a stock will increase or decrease for a day better than level of significance. However, their algorithm was able to make 50% correct prediction and their algorithm was silent for few situations i.e. when to sell the stock4. Hence, better data mining algorithm is needed to be explored to make more accurate prediction.

Stock prediction systems using neural network and their limitation
Neural network is established based on artificial intelligence and it consists of interconnected processors like human brain. It uses mathematical model to make prediction. The most exciting feature of neural network is its ability to deal with non-linear or dynamic data. Due to this, it is extensively applied in dealing with financial data i.e. forecasting the prices of stock market. Neural network can make good prediction if it is configured well for a particular problem as it can learn based on patterns. However, the main challenge of neural network is optimizing number of neurons for a problem and selection of data [11]. Tomasz Kozdraj has attempted to apply neural network in predicting stock price for Warsaw Stock Exchange. He has considered stock prices of 30 companies and performed necessary research and analysis which provided him average level of mean absolute percentage error. The error value was acceptable for his study however he encountered some disturbances in forecasting fitness. He added that though the neural network is worthwhile in stock prediction, but there is no existence of universal forecasting method. The problem which lowered his result is due to various reasons such as one single outcome of a network to a specific internal decision is very difficult, noisy data, overfitting which affects generalization, choice of input series, network parameter setting etc. He concluded that complex network suffers from various difficulties such as data pre-processing, selection of architecture and parameterization. Finally, he resolved that neural network is having limitation and problems in stock prediction which needs further research [12].

Use of classification in stock prediction systems and their limitation
Analysing the data to determine the possible course of action is known as classification, for example: stock data is analysed to know whether it is feasible to invest or not. The dynamic and non-linear nature of stock data demands the application of sophisticated algorithm. However, the technological advance has made us available the computational intelligence by providing various tools and algorithms. Classification and various machine learning algorithms which use combination of classifiers are also gaining researchers' attention in dealing with the stock prediction. Among the various classification methods, some of the researchers use single classification for stock forecasting, whereas others use combination of multiple classifiers to improve the accuracy of prediction [13]. proposed of applying combination of technical analysis and nearest neighbour classification in predicting Brazilian stock market. They have compared their result with buy-and-hold strategy and found the combination of technical analysis and classification produced more profits. Eventually, their proposed method also reduced the risk. However, they have suggested using of better classification algorithm such as Support Vector machines, k-NN etc. to achieve more generalization. Additionally, they have also recommended applying classification technique in Asian market [14]. B. Narayanan et al. have attempted applying two classification methods AdaSVM and AdaNaive and compared their result with widespread classification methods i.e. Support Vector Machine (SVM) and Naïve Bayes which gave them more accuracy with significant reduce of classification error. They have also mentioned that change of technique and increase of input data may provide even more accurate result. Finally, they have agreed that continuous research is essential in developing an acceptable stock forecasting method [15].

Stock prediction systems using hybrid data mining and neural network and their limitation
Data mining is capable of describing cause and effect relation of information, whereas, much prediction problems can be solved using neural network. However, distinct application of neither data mining nor neural network is as effective as the combination of these two techniques15. Prior researches also support that hybridization of these two techniques provide more accurate result with less error rate. Tsai et al. have applied hybridization of artificial neural network (ANN) and decision tree (DT) data mining technique in creating stock price forecasting model for Taiwan stock market which provided them 77% accuracy which was higher than the single use of ANN or DT. However, they recommended performing further research by applying other techniques such as support vector machine, genetic algorithm etc. They have also suggested pre-processing data applying genetic algorithm to achieve better prediction accuracy. Finally, they have added that other industries can be merged with electronic for comparisons [16]. The database of shares was studied and prediction was made accordingly applying data mining and artificial intelligence by Navale et al. They have gained highest probability prediction for share in their study. However, they have emphasized the necessity of improving parameters in accurate prediction performance through data mining and artificial intelligence. They have also recommended for further research on hybridizing artificial intelligence and data mining to reveal the weaknesses of other researches [17]. The advantages and shortcomings of the relevant researches above states that further research is required for revealing the uncertainty of stock market. In search of appropriate stock prediction method, most effective methods like data mining, neural network, classification etc. can be applied for developing accurate prediction system.

Basic concepts of Grey Wolf Optimizer (GWO)
An algorithm which is executed iteratively to produce optimum solution through the comparison of various solutions is known as Optimization algorithm. Grey Wolf Optimizer (GWO) is a new metaheuristic algorithm which is emulated from grey wolves (Canis lupus) and it mimics the leadership hierarchy and hunting mechanism of grey wolves in nature 9 . The leadership hierarchy is simulated applying four types of grey wolves i.e. α, β, δ, ω and hunting is implemented applying three main steps i.e. searching for prey, encircling prey, attacking prey. The GWO algorithm is applicable to challenging problems in unknown search spaces which produces better result than PSO, GSA, DE, EP and ES9. In this research, GWO algorithm is analyzed and it is applied as a training algorithm for Multi-layer perceptron such that it suits with stock data. The novelty of the research is that GWO is applied first time for stock prediction. The proposed algorithm improves the wolves attack strategy. It calculates the weights based on wolves fitness function and gives the highest weight to the dominant wolf concurrently to improve the convergence. The empirical results confirm the power of GWO and demonstrate that the algorithm can faster decide the suitable thresholds, provide good classification rate, efficiency and accuracy. Grey wolves (Canis lupus) belong to Canidae family and they are considered as apex predators, meaning that they are at the top of the food chain. They have a very strict social dominant hierarchy. The algorithm divides the wolves into four types: α, β, δ, and ω, whereas, each type of wolves displays the following social behavior.
The leaders are a male and a female, called alpha. Decision making about hunting, sleeping place, time to wake etc. is made by alpha, that's the reason alpha becomes the leader in the pack and others follow its orders. The best solution of a problem can be determined identifying the location of alpha, as it is the best member in managing the pack. The second level in the hierarchy of grey wolves is beta. The betas are subordinate wolves that help the alpha in decision-making or other pack activities. The beta maintains the discipline of the pack that enforces the alpha's commands in the pack and hence, it takes the role of the advisor to the alpha. The third level in the hierarchy of grey wolves is delta and they need to submit to alphas and betas, but they dominate the omega. They are responsible for watching the boundaries of the territory, warning the pack in case of any danger, protecting and guaranteeing the safety of the pack, helping the alphas and betas when hunting prey, and providing food for the pack and caring for the weak, ill, and wounded wolves in the pack. The last grey wolf in the hierarchy is omega and it may not be an important individual in the pack, but it has been observed that the whole pack face internal fighting and problems in case of losing the omega, which is harmful to the group structure.
Group hunting is another interesting social behavior of grey wolves in addition to the social hierarchy.
The main phases of grey wolf hunting are as follows: searching for the prey; tracking, chasing, and approaching the prey; pursuing, encircling, and harassing the prey until it stops moving; attacking toward the prey.
The fittest solution is considered as the alpha (α) in designing mathematical model of the social hierarchy of wolves for designing GWO 9 . Beta (β) and delta (δ) are respectively the second and third fittest solution. Omega (ω) is considered for the rest of the candidate solutions. In the GWO algorithm, the hunting (optimization) is guided by α, β, and δ. The ω wolves follow these three wolves.

Preliminary of GWO Mathematical Model
The mathematical model of MGWO can be formed as per the equations below: Where, i denotes the current iteration, M ⃗⃗⃗ and N ⃗⃗ are coefficient vectors, Z ⃗ a is the position vector of the prey, and Z ⃗ denotes the position vector of a grey wolf.
The vectors M ⃗⃗⃗ and N ⃗⃗ are calculated as follows: Where, components of are linearly reduced from 2 to 0 over the number of iterations and and is used for controlling the trade-off between exploitation and exploration. The following equations will be employed for updating the value of variable: Z ⃗ (i + 1) = ( Z ⃗ 1 + Z ⃗ 2 + Z ⃗ 3 ) / 3 Where, X i denotes the number of iterations, s 1 and s 2 are random vectors between [0, 1] which are employed to find the optimal solution. Appropriate idea about the potential location of prey can be availed by Alpha, Beta and Delta, where they help the Omega to follow the suitable positions. The values of Z ⃗ 1 , Z ⃗ 2 and Z ⃗ 3 can be obtained through the equations below: In iteration i, the best 3 solutions are respectively, Z ⃗ 1 , Z ⃗ 2 and Z ⃗ 3 . Where, the values of P ⃗ ⃗ α , P ⃗ ⃗ β and P ⃗ ⃗ δ are as below: In this study, GWO is modified to suit it with stock data and train the MLP using GWO for achieving a precise neural network and for removing the drawback of the back-propagation algorithm. Here, two important steps are included for this method that comprises: firstly, train the neural network using GWO to determine the optimal initial weights and secondly, test the results of the proposed GWO approach. This approach can improve the efficiency of the back-propagation to seek global optima in the search space. For the proposed GWO approach, the weights are achieved as a vector of variables.
For this approach, Root Mean Square Error (RMSE) is the cost function which can determine the error between the actual value and predicted value which can be expressed as below: Where, n is the number of observations, a i is the number of actual values and p i is the number of predicted values from neural network. The lower RMSE value is expected for determining acceptable prediction and making the model acceptable.

Pseudocode of GWO
The steps used in MGWO are as follows: Step 1: Initialize the grey wolf population, P i (i = 1,2,3,…..n) Step 2: Initialize q, M and N Step 3: Calcualte the fitness of each search agent, where, Z , Z , Z are the best, second best and third best search agent consecutively Step Calculate the fitness of all search agents Update Z , Z , and Z i = i + 1 End While Step 5: Return Z Steps of MGWO algorithm are as follows:

Architecture of the proposed System
Literature has supported the application of data mining, classification and neural network technique for the prediction of non-linear stock market. In this study, we have collected data from New York Stock Exchange (NYSE) and NASDAQ through Yahoo Finance and from Dhaka Stock Exchange (DSE) through DSE Library/Website. We have collected about 6 years of stock data from 2011-2016. Kumar et al. have used five input parameters in predicting stock price applying Multi-Layer Perceptron with Back propagation neural network learning algorithm [18]. Many other prior researches also support us to consider the following parameter in stock prediction: Open price, Close Price, Low Price, High Price, and Volume We have pre-processed the data and then applied k-means clustering data mining technique to observe the growth of share price for each company. Consequently, k-means clustering helps us to identify the best company in terms of volume transacted, fluctuation of high price and low price of the shares. Classification algorithm GWO is applied on the selected company at this stage to determine the classification rate and decide whether the company can be selected for prediction or not. Then, we apply the optimized neural network Nonlinear Autoregressive Exogenous (NARX) is applied to predict the stock price, whether buy, sell or hold the shares. Finally, the prediction is evaluated by the cost function as explained in equation (13). We have also performed a comparative study of the prediction between prominent stock market and emerging stock market. The proposed system includes the following architecture:

Experimental Results
The experiment for this work has been conducted in several stages. Firstly, the collected stock data is pre-processed and then clustering is applied to select the share to perform prediction. The raw stock data is pre-processed as per the Table 1 and Table 2 below to use it for clustering:

Clustering Result
K-means clustering places the data in two groups as we have selected two clusters to categorize the data based on number of volumes being traded. Clustering categorizes in a way that one cluster includes the pattern of data with highly growing, whereas another cluster contains the pattern with slowly growing. The following Table 3 lists the overall clustering data, though we will be using the highly growing data for classification. The close observation of data pattern and also considering the growth, it has been determined that ACI has high growth and hence it has been selected for classification through GWO.

Classification Result through GWO
The Table 4   The classification through GWO produces the result indicated in Figure 3 and the classification rate through the algorithm is 100, which indicates that the proposed stock data is good for prediction [19,20]. The six years of daily stock price for companies from NYSE, Nasdaq, Bursa Malaysia and DSE has been provided to predict the High Price through Non Linear Autoregressive Exogenous neural network model which categorizes the data into Training, Validation and Test Set as indicated in Table 5. Where, Training Set consists 70% of total data, Validation Set contains 15% of data and Test Set holds 15% of data. The neural network model indicated in Figure 4 contains 10 Hidden Neurons and Number of Delays (d) is 2 in this architecture.
Where, P(k) is the predicted Series, k is the time interval, d is the past values, P(k) is the actual price of the stock and A(k) is the target price to be predicted. The Table 6 lists Actual Value Vs Predicted value of stock price through Non Linear Autoregressive neural network algorithm for different stock market for a day, where the stock value for NYSE and Nasdaq in USD, stock value for Bursa Malaysia in Ringgit Malaysia (RM) and stock value for DSE in Bangladesh Taka (BDT).

Performance Evaluation
The performance of the predicted price is evaluated through the equation 13 for various instruments of different stock markets produced the Root Mean Square Error (RMSE) value as indicated in Table 7 and the forecasting error related to the prediction is indicated in Figure 5. The RMSE value close to 0 indicates no error and prediction is completely acceptable. The forecasting error remains lower and reasonable through the proposed system. Hence, it can be concluded that the proposed hybridized system can be applied for stock prediction that can also reduce the error.  The performance of a neural network can be also evaluated through generalization capability [21,22]. The proposed prediction system can perform well for various stock markets and hence it has good generalization capacity.

Conclusion
This research attempts to construct a hybridized model for stock prediction and compare the performance of prediction between various stock markets. The empirical results through the hybridized model are satisfactory and the error rate also remained reasonable. Investors look for making good profit through stock investment and hence the proposed system can assist the investors in stock investment decision.
For some instrument the forecasting error remained high which is due to the moving of stock trend through various other factors. Our future plan is to work with the effect of various factors in stock price movement and selection of parameters. We would also take into consideration the influence of company news either positive or negative in stock price movement. Stock indices are another important component of stock prediction which can also be predicted.