Prediction of Stock Market by BP Neural Network Model

BP neural network has a very powerful non-linear approximation ability, and the stock market is a nonlinear dynamic system, which is BP neural network for the stock market forecast provides a feasibility. This paper designs a 3-layer BP neural network model, uses the Shanghai Composite Index as the stock price, uses the closing price of the previous five days as the input variable to forecast the closing price of the next day, and uses 295 data as the training set to carry out the model training A good fit model; and then the 29th day of the data as a test set, and finally get a more accurate model can be used for stock price forecast.


Proposal of Research Questions
Stock forecast has strong practicability. It will collect all kinds of information of Companies in the stock market, international macro information, and then use the historical laws of the stock market to determine the company's share price. Stock price forecast is generally based on the following three assumptions: (1) efficient market hypothesis: stock price will be affected by every relevant information in the market, and price reflects all information (2) The price has the tendency: the price has the inertia, the price will increase or decrease along the historical trend. (3) The historical similarity principle: the law summarized by the historical data has included all the future stock market trends [1][2][3].
There are two kinds of traditional stock market forecasting analysis methods: (1) fundamental analysis, which refers to the analysis of macro-economy, the industry where the company's main business is located, the competition level of the same industry and the internal management level of the company;(2) Technical analysis refers to the total method of stock trading decision-making based on market behavior to judge market trend and follow the periodic change of trend [4][5][6].
However, the stock market is an extremely complex dynamic system. Applying the existing technical analysis methods, the prediction results are often unsatisfactory. In recent years, with the development and maturity of neural network theory, it has been widely used in many fields such as signal processing, pattern recognition and control. Because of its strong nonlinear approximation ability, self-learning and self-adaptive characteristics, neural network has a higher prediction accuracy than statistical methods, so it is a hot spot in the international stock forecasting research. The change of stock price is affected by many factors, but in fact, the stock price is also formed under the joint action of many factors, only some are linear relations, some are nonlinear relations. The BP neural network has incomparable advantages

Literature Review
Since the popularity of neural network in 2000, many scholars have tried to apply neural network to the prediction of stock market price. The following introduces the research status of neural network model used to predict the stock market in recent years at home and abroad (1) Foreign research results: 1 Murat (2008) used the neural network model to predict the price of TKC securities, and the results showed that the neural network prediction model was better than other prediction models. A. Murat oi Bayogly and Ismet Bahadir (2010) predicted stock prices with Bayesian and neural networks respectively, and found that both methods are feasible in operation, but the effect of neural network method is obviously better. To sum up, foreign scholars basically concluded that the prediction effect of neural network is better than other methods.
(2) Research achievements in China Domestic scholars&apos; research on neural network mainly focuses on empirical research, which is embodied in the technical details of building the model, including the selection of input variables, the optimization of BP network and the verification method of the model. In the selection of input variables, there are mainly two types, one is the direct use of transaction data, most scholars use this way. For example, Zhang Kun (2009) only used the closing price of the stock price as the input variable, and the data coverage was narrow, so it was difficult to express all the factors influencing the stock price. The other is to extract the input variables of the model by comprehensively considering the fundamental factors of the stock market. For example, the first mock exam of Wu Chengdong&apos; s (2002) is to build a unified model from the historical price, economic factors, policy and technology. The FAZ network structure and parameters are used to predict the stock index. Zhang Xiuyan et al. (2003) established "basic data model", "technical index model" and "macro analysis model" respectively in a similar way. Finally, the integrated system model was generated by simple average method. Although this method integrates the model formally, the simple average method can not explain the influence of different factors on stock price in essence. Zhu Yongming et al. (2013) only considered the company&apos;s financial factors as the input variables of BP neural network. Liu Xi (2016) combined financial indicators with transaction indicators to build a comprehensive index system, and then used principal component analysis to reduce dimensions, and input the reduced principal components into BP model. At the same time, thought evolution method was used to optimize the initial weights and thresholds of BP model, so as to improve the prediction accuracy of BP neural network.
In the verification of BP neural network, due to the different sample selection methods, the verification methods are different. Generally speaking, if the selected sample is a single stock or single index, the time series data is generally selected, and then the data of the previous period is used as the training sample, and the data of the later period is used as the verification sample. For example, Liu Lihua (2005)  In this paper, the classic BP neural network model is selected for stock price prediction, which is improved in two aspects: 1. The closing price of the previous five days is selected as the input variable; 2. 295 closing prices of the Shanghai stock index from June 1, 2016 to August 1, 2017 are selected as the training set, and 29 closing prices of the Shanghai stock index from August 1, 2017 to October 17, 2017 are selected as the test set.

Application of BP Neural Network. BP (back propagation) neural network is a concept put forward by scientists led by Rumelhart and McClelland in 1986.
It is the most widely used neural network at present. It is widely used in classification, identification, approximation, regression, compression and other fields. In practical application, about 80% of the neural network models adopt the form of BP network or BP network.

Structure of BP Neural Network.
The network is composed of multiple layers, which are fully connected with each other, and neurons in the same layer are not connected. It contains a number of hidden layers, which can realize complex mapping relationship.

Learning Algorithm of BP Neural Network.
The steepest descent method can find the minimum value of an index (objective function). If the objective function is taken as the mean square error, the LMS algorithm is obtained. For a real valued function, if it is defined and differentiable at a certain point, then the function will decline the fastest along the opposite direction of gradient at that point. Therefore, when using gradient descent method, we should first calculate the gradient of the function at a certain point, and then adjust the value of the independent variable in a certain step along the opposite direction of the gradient.
(1) When the step size is small enough: (2) The minimum value of the function is obtained by iteration (3)

Sample Selection and Data Collection
This paper selects 295 closing prices of Shanghai Composite Index from June 1, 2016 to August 1, 2017 as training set, and 29 closing prices of Shanghai stock index from August 1, 2017 to October 17, 2017 as test set. The data are all from the software of flush. First, the training set is used to train the model, and then the model is used to predict. The accuracy of the prediction effect is observed.

Preliminary Data Processing
Since the BP neural network requires the input eigenvector and the output result to be between 0-1, it is necessary to normalize the above data. The function selected for normalization is mapminmax function in MATLAB, and its mathematical formula is as follows: Y = (Ymax-Ymin)*(X-Xmin)/(Xmax-Xmin) + Ymin (4)

Construction of Neural Network
Model. The closing price of Shanghai stock index in the first five days is selected as the input variable of the model { } as the input variable, the hidden layer node number is set to 20, and the output variable is 1, that is y. The structure of the neural network is as follows:

Model Test
The training data are brought into the model again, and 295 output values of the model are obtained, and compared with the actual value, the fitting results are as follows:   It can be seen from the fitting effect chart that the model has a good fitting effect on the training data, and the actual value of Shanghai Composite Index almost coincides with the output value of the model. By analyzing the residual graph, it can be found that the residual basically fluctuates around 0. It can be seen that these residuals have the characteristics of white noise, so the network can learn the rules of training data well.

Prediction Analysis of the Model
The 29 closing prices of the Shanghai Composite Index from August 1, 2017 to October 17, 2017 are taken as test sets, which are brought into the model for prediction, and 29 output values are obtained.
The output values are compared with the actual values. The effect chart is as follows:  It can be seen that the model has a certain predictive ability, because the predicted value of the model is close to the actual value to a certain extent. From the trend point of view, the development trend of the output value of the model is roughly equivalent to the actual value. From the perspective of ups and downs, there are actually 13 turning points of trend, 5 turning points of accurate prediction, and the accuracy rate of rise and fall prediction reaches 38.5%. It can also be seen that the model has certain prediction ability.

Conclusion
BP neural network has a very good ability of nonlinear approximation, so it is very suitable for the stock market. Through the above empirical study, we can find that neural network is feasible in stock market forecasting, but its accuracy needs to be improved. This is because the stock market has a high degree of noise and human intervention, sometimes it can not reflect its inherent law, so how to use neural