Based on BP Neural Network Stock Prediction

The stock market has a high profit and high risk features, on the stock market analysis and prediction research has been paid attention to by people. Stock price trend is a complex nonlinear function, so the price has certain predictability. This article mainly with improved BP neural network(BPNN) to set up the stock market prediction model


Introduction
The stock market is full of uncertainty elements of capital market, and the rapid flow of information makes the stock market price changes more frequent, resulting in the fluctuation of stock market, which is the risk in the stock market (Shen, 2010, p.40-42).Investors always concern and analysis the stock market, trying to predict the trend of stock market, and establish the corresponding prediction model, gives a prediction method, to avoid large fluctuations in the stock market, reduces the risk of investment, in order to maintain economic prosperity and stability.This article through to the commonly used neural network stock forecasting method, establishes the corresponding network model, through the MATLAB software based on the Shanghai Composite index closing price of prediction model, simulation experiments, and the experimental results were analyzed.

BPNN
The BPNN, namely the error back propagation neural network, there is a hidden layer of multilayer feedforward network (Zhou, 2005, p.25-40).Structurally, it is a kind of hierarchical network, having an input layer, hidden layer and output layer of the three layer structure (seen in Figure 1).For a BP network, the hidden layer can have more than two, and has a hidden layer BP network is a kind of basic BP network model.
The method of neural network has the ability of learning, extensive adaptability and nonlinear mapping ability, by learning to obtain the dependency relations between sample data.Neural network for prediction of stock market, is the use of stock history data consisting of time series, through the self-learning ability of neural network to carry on the analysis, the law of excavation, the analog network between output and input function, and this function is used for the prediction of future price. .

BP algorithm
BP algorithm for learning from positive and reverse the spread transmission signals into two process (Zhou, 2005, p.50-75).Signal forward propagation, from the input layer of afferent input samples in the hidden layer to the output layer disposed behind.If the output layer of the desired output and the actual output does not match, then transferred to the error back propagation stage.Error back propagation is the expected output and the actual output error in some form through the hidden layer to the input layer by layer back propagation and its allocation to each layer of all units, thereby obtaining each layer unit error signal, and as amendments to the unit weight basis.Signal forward propagation, error back propagation, each layer of network weights go round and begin again the ground undertakes adjustment, so as to realize the network training process.This process has been carried out to the actual output and the expected output of the network error is reduced to an acceptable level, or to a predetermined number of learning before Application of BP neural network with strong nonlinear approximation ability, will determine the price variable sequence as the input matrix, and the stock price as output of the target matrix, with historical data as the training data used to train the neural network, the results of training is actually fitting a nonlinear mapping between input --output, and then use this input the output of the function, given the new input, the output is the prediction results.Neural network based on the inter-relationship of data modeling, can be automatically extracted from the historical data about the economic activities of the knowledge, can overcome the traditional quantitative prediction methods for many limitations and difficulties, but also to avoid many man-made factors, thus for stock market modeling and forecasting provides new method.

Various improved BP algorithm
According to the limitation of the BP algorithm, people made many improvements, the main purpose is to speed up the training speed, avoid into the local minimum value.The improved training of BP network convergence speed than the standard gradient descent method can fast several times and even hundreds times (Han, 2006, p.87-100).

Adding the momentum item
To quicken the convergence and prevent the vibration, one momentum factor  is introduced.
Where,  is the momentum item, and it is usually positive.
The third item is the modification of the weight at the last time, and the modification direction at the time of ) ( 0 n is the combination of the direction at the time of ) 1 ( 0  n and the direction at the time of ) ( 0 n .

Algorithm of variable step
BP algorithm is based on the gradient method, and in the common optimal gradient methods, the step length  is solved by the one-dimensional searching.Change the step is designed to make the error in the whole training process in a reasonable adjustment, the method has a lot of.One of the methods is: setting an initial learning rate, if the total error after a batch weight adjustment after the increase, the adjustment is invalid, and When the coefficient value  is very large, type into a step size smaller gradient descent method.Only trying iteration error performance increased cases increasing coefficient, in each iteration step is successful, have reduced coefficient, the algorithm for each step of the iteration error performance is reduced.

BPNN short-term price prediction
A prediction, through a number of known historical data on the unknown values of data estimation.A time series {Xi }, where the historical data of Xn, Xn+1, ... , Xn+m , In the futuren+m+k ( k > 0) time values were predicted, and prediction of Xn+m+k certain nonlinear function relation (Zhang, 2009, p.208-209): Commonly used the following three types of prediction:

Single-step prediction
When K = 1, and the network of all input data is the time sequence of the actual observed value, make prediction is one step prediction.Single step prediction is rolling prediction based, when carries on the forecast, the actual time sequence observation value Xn, Xn+1, ... , Xn+m m this data are input to the network, the output is the next time the predictive value of X'n+m+1, to continue on the X n+m+2 value predictive, with the actual observed value Xn+1, Xn+2, ... , Xn+m+1 as input data, get the predictive value of X'n+m+2.

Multi step prediction
When k > 1, namely the network input m historical data, the output Xn+m+1, Xn+m+2, ... , Xn+m+k.the predictive value.Experiments prove that the multi step prediction for stock price prediction error is large, this is because in the operation of the network to adjust weights and thresholds, each iteration to accumulate before k prediction error, thereby causing the network to convergence, and even lead to network oscillation.

Rolling forecast
Rolling forecast, also called iterative step prediction.One step iterative prediction is to first step prediction, then the network output in the predictive value of feedback to the input side of the network as part of the input, for the next step prediction.If the beginning of predictive input data is the actual sequence of observation value Xn, Xn+1, ... , Xn+m, the output is the next time the predictive value of X'n+m+1, X'n+m+1 and Xn+1, Xn+2, ... , Xn+m as input data for Xn+m+2 estimation, to receive the output of the predictive value of X'n+m+2, X'n+m+2 and Xn+2, Xn+3, ... , Xn+m, X'n+m+1 as input data for Xn+m+3 estimation, repeated iterations, get on the next period of predictive value.As shown in Table 1, predict the future q time value.
Visible, when q > 1, the input data is not only the timing of the actual observed value, also have predictive value, especially when q > m, all input data are predictive value, then the prediction error will be large.

BPNN stock forecasting principle
The price of the stock is a kind of discrete time series data.Set the K day stock price for the Xk, Xk, = g ( X k ).Where Xk = ( Xk-1, ... , Xk-t ), g (. ) is a nonlinear continuous function.g (. ) portrait of a generation of this time series dynamic mechanism, only to find the appropriate g (. ), will be able to make appropriate to the time sequence prediction.However, due to complexity in stock market, characterizing their specific dynamic process is extremely difficult, but the BP network for nonlinear function approximation is particularly suitable for use on the stock market, so its dynamic process modeling is suitable.
BPNN forecast of stock price is the principle of: Using BPNN through a group of data points Xn, Xn+1, ... , Xn+m fitting function g (. ), the future of n+m+k (k > 0) the predictive value of time data.It predicted the features are: multiple input, single output nonlinear mapping.For this highly nonlinear relationship, select the structure of multi-layer feed-forward neural network BP network modeling, clear and simple.

BPNN for the prediction model of stock
Selection of the Shanghai composite index yesterday, the day before yesterday 's closing price, trading volume, trading yesterday's closing price yesterday, today 's closing price, this volume and system status related to two index DMA and RSI were 8 parameters as the input of the network, tomorrow's closing price as output of network.The three layer BP network, two hidden layer, hidden layer nodes7, the network structure for 8-7-1, transfer function first layer adopts hyperbolic type S transfer function Tansig, second layer using linear transfer function Purelin, BP networks of neurons using Sigmoid transfer function.In the input of neural network, data must first after normalization, data normalization standard refers to the network's input, output data is processed, the limitation in [-1,1] interval.

BPNN to predict the stock price process
(1) To determine the predictive precision and network structure, which determine the number of input node, the hidden layers, each hidden layer nodes and the output node (Gao, 2007, p.27-29)..
(2) The sample data are segmented, generally divided into training and testing samples.
(3) Select the appropriate algorithm to train the network, making it fit the training samples.
(4) With the test sample to examine the trained network.If less than the allowable error value, using the trained network to predict the future price, if the result is not good, then adjust the structure of network, repeat step third, until get a better test results.
To sum up, neural network method of stock price prediction process with neural network for training and prediction of two steps.In the training phase, the network first randomly generated a set of connection weights, through the forward transmission output a result, and the expected output value comparison, if the error is less than the set value, then the correction network of each connection weights, network propagation.Forward propagation output calculation and backpropagation weight correction are performed alternately, until the network expected output and the actual output between the error meets the requirements, ultimately determine the network weights and thresholds.Network prediction process is the test sample was input into the trained network, output prediction value, so as to the price and forecast.

BPNN Simulation and Prediction
Experimental data from access software market derived from high speed, from May 6, 2010 to 2011 January in 23 in a total of 200 trading days of data, to be normalized, and then according to the above will be three days before the closing price and trading volume as well as third days of DMA and RSI as a network of input data, fourth day closing price as the desired output data, sequentially roll arrangement, generates 197 output of the input data, wherein the first 180 groups as training samples, the latter 17 groups as the test sample..The standard BPNN convergence speed, easy to fall into local minimum, the network structure and parameters are difficult to be determined, so to improve BP neural network.After several more after using LM algorithm to improve the generalization ability of the network normalization method, achieved satisfactory results.
Other parameters by default, training errors as shown in Figure 1.Seen by the graph, network after 55 iterations, will achieve convergence, training effect is very good, at this time MSEREG = 0.402551.
The test samples are normalized after simulation, draw predictive value and the real value of the scatter diagram, as shown in Figure 2, where" +" for real value," o " for the predictive value.As can be seen from the graph, predict the effect is good.But because of the influence of stock price of many factors, so the prediction effect is not very ideal.This marked the closing price is not the real meaning of the closing price, the network input is the closing price after normalization, the output of the network and therefore also in [-1,1] range.Also can predict data reverse normalization, relative error is small, showed that one-step prediction result is more accurate.

Conclusions
In stock investment returns and risks coexist, reduce a risk as far as possible, get the maximum profit is the goal of each investor, therefore the research on the inherent law of stock market and the development trend is predicted to have great theory meaning and application value.BP neural network is currently the most commonly used neural network, the neural network nonlinear mapping, a three layer BP neural network can approach any continuous function on the complex capacity.In this paper, by using the improved BP neural network to achieve the Shanghai stock index prediction, model has good generalization ability, to the stock market prediction has a certain reference value.

Figure
Figure 1.BPNN mode Design of LM algorithm is in order to approximate two order training rate correction to avoid calculation of Hessian matrix.The LM algorithm can be expressed as Reed correction: Shen, yuan.(2010).BP neural network in stock prediction.Zhongnan University of Economics and finance, 40-42 Zhou, Kaili.(2005).Neural network model and its simulation program MATLAB design.(3rd ed.).Beijing: Tsinghua University press, (Chapter 1).Han, Liqun.(2006).Artificial neural network.(2rd ed.).Beijing: Beijing University of Posts and Telecommunications press, (Chapter 3).Zhang, Yangwu.(2009).Based on time series and neural network structure which combines the study of stock price prediction.Computer knowledge and technology, 208-209 Gao, qin.(2007).Artificial neural network in stock market prediction model.Microelectronics and computer, 27-29