Modeling and Computing of Stock Index Forecasting Based on Neural Network and Markov Chain

The stock index reflects the fluctuation of the stock market. For a long time, there have been a lot of researches on the forecast of stock index. However, the traditional method is limited to achieving an ideal precision in the dynamic market due to the influences of many factors such as the economic situation, policy changes, and emergency events. Therefore, the approach based on adaptive modeling and conditional probability transfer causes the new attention of researchers. This paper presents a new forecast method by the combination of improved back-propagation (BP) neural network and Markov chain, as well as its modeling and computing technology. This method includes initial forecasting by improved BP neural network, division of Markov state region, computing of the state transition probability matrix, and the prediction adjustment. Results of the empirical study show that this method can achieve high accuracy in the stock index prediction, and it could provide a good reference for the investment in stock market.


Introduction
The stock market is filled with the coexistence of high-risk and high-yield characteristics. As a barometer of the stock market, the stock index is an important reference for investors to make investment strategies. However, the stock price index is influenced by many factors such as the economic situation, policy changes, and emergency. Although faced with complicated challenges, the forecast of stock index has still attracted the attention of many industrial experts and scholars. Lendasse et al. used a nonlinear time series model to forecast the tendency of the Bel 20 stock market index [1]. Lee et al. forecasted Korean Stock Price Index (KOSPI) by three forecasting models including back-propagation neural network model (BPNN), Bayesian Chiao's model (BC), and the seasonal autoregressive integrated moving average model (SARIMA) [2]. Fan and Gao proposed "Grey Neural Network model (GNNM(1, N))" and argued that the combined model could improve the prediction accuracy and reduce the computation [3].
Up to now, stock prediction has still been a hot topic. In this field, there have been a lot of methods, such as artificial neural networks [4,5], time series model [6,7], decision trees [8], Bayesian belief networks [9], evolutionary algorithms [10], fuzzy sets [11], and Markov model [12][13][14]. However, the single method is usually limited to achieving an ideal precision in the dynamic market due to complicated influencing factors. In recent years, some new hybrid models have shown the potential superiorities [15][16][17]. Especially, the approach based on adaptive modeling and conditional probability transfer may be suitable for matching the problem's characteristics.
In order to explore the new solution for improving the forecast precision, this paper presented a new method based on BP neural network and Markov chain, studied its modeling and computing technology with the data of Chinese Growth Enterprise Market, and hereafter conducted an empirical analysis of the prediction results. This paper is arranged as the following five sections: Section 1 is the introduction of research background and the most related The Scientific World Journal literature; Section 2 expounds the methodology and technology as well as the combined model based on BP neural network and Markov chain; Section 3 discusses the modeling and computing technology of the presented method; Section 4 is the empirical analysis of prediction results; and the conclusion and discussion are finally in Section 5. (BPNN). BPNN is a one-way propagation of BP algorithm based on multilayer network. It is based on gradient descent method which minimizes the total of the squared errors between the actual and the desired output values. The structure of three layers BPNN includes the input layer, the hidden layer, and the output layer. The BP learning algorithm of three layers can be described as follows [18,19].

BP Neural Network
Step 1. Initialize all the values of ( ), ( ), ( ), ( ) to small random values within the range [−1, 1], where ( ) means the connection weights between neurons in the input layers and neurons in the hidden layers during the th learning process, ( ) represents the connection weights between neurons in the hidden layers and neurons in the output layers during the th learning process, ( ) means the threshold value in the hidden layers, and ( ) means the threshold value.
Step 5. Calculate the error terms ( ) for the hidden nodes: Step 6. Update weights on the output layer: where Step 7. Update weights on the hidden layer: where Step 8. Calculate error; repeat Steps 2-8 until the error falls below a predefined threshold: where means the number of output node.
Although BP algorithm is successful, it has some disadvantages such as lower convergence speed and easy to get into local minima points. Therefore, improved BP algorithm was applied in our study. Our improved method is based on the additional momentum and adaptive learning rate combined. The formula with the momentum factor weight adjusting is as follows: where represents network weight, is number of training, lr is the learning rate, mc is the momentum coefficient, 0 < mc < 1, and is the error function. In addition, adaptive learning rate method can be described as follows: where lr is the learning rate, is the number of training, is the error function, = ∑ =1 ( −̂) 2 , is actual output value, and̂is anticipative output value; usually = 1.05, = 0.7, and = 1.04 [20].  positive integer step , when this sequence of variables has the following attributes:

Markov
We call such stochastic variable sequence { ( ), ∈ } Markov chains, where is the transition probability from state to state . These transition probabilities satisfied ∑ ∈ = 1, ∈ , and the matrix = ( ) is the transition matrix of the chain. If the transition probabilities in (12) do not depend on the time parameter , it will be called "timehomogeneous Markov chains. " Since the state space is countable, we can label the states by integers, such as = {0, 1, 2, . . .}. Under this label, the transition matrix can be described as follows: ] .

Modeling of Forecast Based on Improved BPNN and Markov
Chain. The modeling process can be described as follows.
Step 2. Initialize forecasting by using model of Step 1.
Step 3. Normalize the error of prediction. The normalized formula is as follows: Step 4. Set Markov state zoning by normalized upper and lower thresholds.
Step 5. Divide the Markov state region by using the sample average-mean square deviation method. Five ranges are divided as follows [21]: Step 6. Define the initial state and calculate the state transition probability matrix.
Step 7. Markov chain test: use chi-square statistics test for Markov property.
Step 8. Forecast. Get the state vector of step from formula (13) and forecast based on this model.

Modeling and Computing
3.1. Sample Data. In this paper, we select "Chinese Growth Enterprise Market Index (GEMI, 399006.SZ)" for the data set to empirical study, and then we will finish short-term Chinese GEM index price prediction based on this data set. The data set is total of 58 days, which is from 2013-5-24 to 2013-8-16 of trading data. Among them, divided into in-sample and out-of-sample, the first 41 days of data are in-sample as training data and then the data from 42 days are out-ofsample and used as prediction. Due to closing index price, the most important indicator for investment reference, our study focuses on the closing index price forecasting. The daily trading data including opening price, highest price, lowest price, closing price, and trading volume are used for modeling. The sample data of Chinese GEM index are shown in Table 1.

Construct BP Neural Network Model
(i) Definition of Layer Number. According to Kolmogorov theorem, three layers can approach any continual function.

4
The Scientific World Journal Therefore, an input layer, a hidden layer, and an output layer are selected in this model.
(ii) Activation Function and Training Target. Here, the activation function of hidden layer neuron is tansig, the output layer neurons traditional function is purelin. The training function is traingdx. The end of training conditions is the mean square error of the accuracy of = 0.005.
The circulation is 10000 times. In this model, the initial learning rate is 0.1. The initial momentum factor value is 0.9.
(iii) Number of Neural Node. The input layer node number is five, namely, items of opening price, highest price, lowest price, closing price, and trading volume. Meanwhile, data of "day 1" were regarded as the first input data in input layer. In this model, the output layer node number is set to one; meanwhile, "closing price" of "day 2" was regarded as the first output data in output layer.
Numbers of hidden layer node depend on experience and repeated training, how many of the nodes depend on the network error; the number corresponding to the minimum network error in training will be chosen as the number of the hidden layer nodes.
The network errors which correspond to different number of neurons are shown in Table 2. It can be seen that this neural network has the minimum network error of 0.2689 when the neuron number is eleven. Therefore, we select eleven as the number of hidden layer nodes. The data in Table 2 indicate that network error cannot be reduced even if we contiune to increase the number of hidden layer nodes.

Training.
Training of the network is completed in MATLAB software. First, the training sample data is selected; then, the data is normalized. Normalization means to limit the data in a certain interval. Here, in order to limit training data in [−1, 1], the premnmx(⋅) function is called. After normalization, start training network with a training set of 41 sample data; the learning rate is 0.1 and the momentum is 0.9. The network was in training till the Mean Squared Error (MSE) was less than 0.005. Finally, we get the ideal model after training the neural network. The dependence of MSE on epochs is shown in Figure 1.
It can be seen from Figure 1 that the network MSE reaches the expected MSE after 8078 steps of training, in which the training MSE is less than 0.005.

Forecast
(i) Initial Forecasting Based on Improved BPNN. According to trained network and sample data, we used rolling forecasting method to predict the closing index price. Part of the code in MATLAB software is shown in Algorithm 1.
The Chinese GEM index of daily closing price of simulation is shown in Figure 2. Both actual value and predicted value are shown when trading day from 42 days to 56 days.

(ii) Computing of Normalization
Step 1. Calculate the absolute residual rate of prediction days. The calculation formula is as follows: The Scientific World Journal where is the actual value of closing index price, is the predicted value of closing index price, and is the absolute residual rate of day.
Step 2. Normalize the data set of absolute residual rate in MATLAB software; the mapminmax(⋅) function is called. The absolute residual rate and normalized results are shown in Table 3.

Empirical Markov Model
(i) State Definition. According to the normalization value of Table 3, sample average-mean square deviation was used in state classification. Usually five intervals are divided: (−∞, − Taking into account the fact that the data is not that much, Markov state was divided into four ranges according to  Table 4.   (3) it has 0 times, and from the state (1) to (4) it has 0 times; then, the sate transition probability can be calculated as follows: Thus, the state transition probability matrix can be described as follows: ] .
The probability matrix has the Markov property after chi-square statistics test.

(iii) The
Step State Vector of Prediction. According to the state transition probability matrix and the Markov forecast model, the step state vector of prediction can be calculated as follows: Thus, the step state vector of prediction can be described as shown in Table 5. Step 5 Step 6 Step 7 Step Step 9 Step 10 Step 11 Step Step 13 Step 14 Step 15 Step

Empirical Analysis
According to the step state vector of prediction of Markov model, prediction result from 2013-7-25 to 2013-8-15 was shown in Table 6. Among them, col6 is adjustment value and col6 = max 5 ∧ col4 , where max 5 means the maximum probability of someday in fifth column and col4 means the average of interval of fourth column.
It can be seen from column "error of absolute residual rate" in Table 6, during sixteen trading days, that most of the prediction results by this model are better than a single improved neural network prediction except during the first day and the fifth day.

Conclusion and Discussion
Due to the complicated influencing factors in dynamic stock market, the comprehensive method with hybrid models throws off more superiorities than a single method in the forecast of stock index. This paper presented a new method based on the combination of improved back-propagation (BP) neural network and Markov chain, which took the advantages of neural network and Markov model, and obtained the results better than that of the single improved BPNN method. This method could provide a good reference for the investment in stock market.
As an open complex adaptive system constantly affected by all kinds of emergency events and people's psychological and behavioral effects, although many scholars including the famous financial experts pointed out that the changes of stock market cannot be predicted, we had to break those traditional ideas which rely only on the financial theory models and explore new combined methods such as the TDF The Scientific World Journal 7