You are on page 1of 5

Application Study of BP Neural Network on Stock Market Prediction

Feng Li, Cheng Liu


Economic Management Institute
University of Science and Technology Beijing
China, Beijing, 100083
lifeng670312@sina.com


AbstractAiming at the complexity of interior and variety
of exterior structure of stock price system, this paper
analyzes principles of stock prediction based on BP neural
network, provides prediction model for stock market by
utilizing three-layered feed forward neural networks,
presents topology of network, principles of determining the
number of hidden layers, selection and pretreatment of
sample data and determination of preliminary parameters.
In order to avoid local extremum and promote convergence
speed, Levenberg-Marquardt BP algorithm has been
adopted. Simulation experiment based on representative
index from Shanghai stock exchange market, through
training on selecting samples and prediction model,
indicates that this algorithm can make efficient short-term
prediction.
Keywords-stock index prediction, BP neural network,
number of hidden nodes, strategy of sampling
I. INTRODUCTION
Stock price prediction is a heated topic in prediction
study of financial area. Excellent algorithm has been
applied to predict stock price. Many efforts of methods
have been focused on traditional statistical economics and
artificial neural network. Limitation of traditional
statistical economics consists of inflexibility in dynamic
situation and complexity of modeling. Stock price,
however, can be affected by various factors. In the long
term, we have to admit that there are some essential fixed
elements under change tendency as well as uncertainty in
certain time. Change of stock price is perhaps a
nonstandard economic fact. Traditional statistical
economics could only generally predict stock price in
certain period time. Comparatively, artificial neural
network, a massively parallel processing non-linear
system with self-learning ability and adjustability,
modeling on inherent relationship between data, has
obtained satisfactory achievement on short term prediction
on stock price. Neural network is substantively a statistical
method in terms of deduction. From the perspective of
statistics, it is similar to a non- parameter and non-linear
attenuation mode [1]. It is a novelty for neural network to
conduct process simulation under little hypothesis
preference. This novelty is especially meaningful in
financial area. This is due to the fact that there are few
fixed elements which determine capital price, but
excessive hypothesis in traditional model.
II. STOCK INDEX PREDICTION MODEL BASED ON BP
NEURAL NETWORK

A. Arithmetic Principles
BP algorithm, a back propagation algorithm, is a feed
forward neural network supervision algorithm. Its
proposal has essentially promoted the development of feed
forward neural network [2].
Feed forward neural network is capable to tackle
complex non-linear signals. It has been proved
theoretically that feed forward neural network has function
approximation: arbitrary
function
:[0,1]
n n m
f R R
has a three-layer feed
forward network. With strong generalization ability, this
function can approximate
f
in arbitrary precision.
Therefore, neural network is able to predict time order in
non-linear by designing a neural network to fix time order,
without hypothesis of stability on time order.
General steps of multi-layer feed forward BP neural
network for prediction [3]:
Determine network structure and prediction
precision, determination of input nodes number
and output nodes number, hidden layers and
number of nodes in each layer.
Divide sample data, including study sample data
and testing sample data.
Select appropriate algorithm to train network, in
order to fix study sample time order as much as
possible.
Use testing sample data to test trained network. If
the result is satisfactory, this trained network can
be applied to predict. Otherwise, adjust network
structure, follow step 3 again till more satisfactory
testing result appears.
Prediction on stock price by neural network consists of
two steps: training or fitting of neural network and
prediction. In the training step, network generates a group
of connecting weights, getting an output result through
positive spread, and then compares this with expected
value. If the error has not reached expected minimum, it
turns into negative spreading process, modifies connecting
weights of network to reduce errors. Output calculation of
positive spread and connecting weight calibration of
negative spread are doing in turn. This process lasts till the
error between practical output and expected value meets
the requirements, so that the satisfactory connecting
weights and threshold can be achieved. Network
prediction process is to input testing sample to predict,
through stable trained network (including training
parameters), connecting weights and threshold. Above all,
we can draw a conclusion that a three-layer feed forward
could fit non-linear continuous function arbitrarily.
2009 Ninth International Conference on Hybrid Intelligent Systems
978-0-7695-3745-0/09 $25.00 2009 IEEE
DOI 10.1109/HIS.2009.248
174

Consequently, this paper adopts
1 n r
neural network
structure,
i
x
as an input layer node,
1
y
as an output
node
ij
w
as output layer weight
j
v
as hidden layer
weight
{1,..., } i n
,
{1,..., } j r
n as number of
input node, r as number of hidden layer nodes. Number of
output node is 1. Topology is illustrated in Fig. 1.
B. Pretreatment on Feature Data of Stock Index
1) Sampling standard
Price of single stock is more sensitive, can be
influenced by some specific elements and then changes.
Comprehensive stock index is more stable, reflecting
development of national economy. Due to this, this
paper predicts and analyzes stock index of Shanghai Stock
Exchange Center. There is close relationship between
stock index and volume. Based on this, this paper selects
stock index and closing price of each week in Shanghai
Stock Exchange Center as training data.
Change of stock price has close connection with the
following macro-economic standard. Having this in mind,
the input data consist of monthly social retail goods,
consumer price index and amount of investment in fixed
assets (exchange into points based on radix of the same
period of previous year as 100 points). Output data is
closing price of following week in Shanghai Stock
Exchange Center. Through training, we can get weight
matrix and then form a three-layer BP network prediction
model. The chosen macro- economic standard has the
following affects on stock price: social retail goods, on the
one hand represents purchasing power. On the other hand,
with the increase of retail goods, saleroom of each
company will do the same, together with the increase of
interests, and benefits of investors. Furthermore, stock
price will multiply. Consumer price index reflects level of
price which significantly influences investors, whereas
rising of price causes more expenditure on durable
consumable products and lower benefits for investors
which results in the decrease of stock price. On the other
hand, price increasing could give enterprises more
benefits, so as to the investors income, and then stock
price will multiply. Amount of investment on fixed assets
represents the development of fixed assets including real
estates in China.












Figure 1. 1 n r neural network structure
As we all know, the development of real estates has
close relation with comprehensive stock market in China,
reflects extent of capital flow.
2) Sampling normalization and time span
Applying Sigmoid function as excitation function of
neural cell in network, in order to use feature of S function
to make sure non-linear function of network neural cell,
we should do normalization for the studying sample:
Sample data is set as
( 1, 2,..., )
i
x i n =
, following
formula
min
max min
i
i
x x
x
x x

, change sampling data to 0


1 range. The output data should be reverted, to recovery
the practical value. That is to say, we need to have the
inverse algorithm, using
( )
i max min min i
x x x x x +
to revert [4].
The normalization of data in BP neural network is
contrary to the traditional method which applies sample
data to determine prediction data boundary in advance.
Keeping this in mind, we should notice that stock price
index in Shanghai Stock Exchange Center could not
decide the maximum and minimum of prediction data.
Therefore, we could not predict the continuous increase or
decrease with the trained model. That is to say we can not
do the normalization of the prediction data. Considering of
this, choosing the time span for neural network in
sampling, wed better select the time which can include
the time to reflect prediction of stock index.
This paper selects weekly closing price and volume
from Shanghai Stock Exchange Center as studying data
ranging from January 2004 to September 2007.
C. Determination of Number of Node in Hidden Layers
It is an unsolved problem to determine the best node in
hidden layer. If the nodes are not enough, the convergence
speed of the whole neural network will slow down and it
is difficult to conduct. On the contrary, if there are
excessive nodes, the topology of neural network will be
more complicated, and more calculation work on iterative
study and error may not be perfect.
The determination principles of number of node in
hidden layer are as following: based on formula
1
n n m a = + +
is applied to determine selecting
range of number of node in hidden layer. (
1
n
is number
of perfect number of node in hidden layer,
n
is number
of neural cell in network input layer,
m
is number of
neural cell in output layer,
a
is a number between
0~10) [5].
Choose same sample to train topology of BP neural
network for number of node in each hidden layer. Use
same testing sample to do the test. By using minimum
error as standard, we can find the equivalent perfect
number of node in hidden layer.
D. LM (Levenberg-Marquardt) Algorithm
This paper adapts batch method to study sample, to
train network by using modifying self-adapt
Levenberg-Marquardt algorithm. Different from gradient
method, the algorithm based on numerical optimization


Inputlayer
hidden layer output layer
x
1

x
2

x
n

y
1

w
ij

v
j

1
r
175

utilizes not only first derivative information of objective
function, also second derivative. LM
Levenberg-Marquardt is one of them. The detailed
algorithm is as following.
( 1) ( ) ( ) ( )
( 1) ( ) ( ) ( )
( ) min ( ( ))
( )
k k k k
k k k k
f X f X S X
X X S X

+
+
= +

= +


In the formula,
( ) k
X
represents vector which is
composed by all of weight value and threshold of the
network.
( )
( )
k
S X
is the direction of search of vector
which is composed by component vector of X.
( ) k

is
the step length in the direction of
( )
( )
k
S X
which
makes
( 1)
( )
k
f X
+
minimum. Consequently, seeking
control of network can be carried in the following two
steps: firstly determine the best current direction of
searching; secondly, search the best iterative step length
based on step one.
Formula of weight value of calibration of LM:
1
( 1) ( ) ( )
T T
ij ij
w t w t J J I J e

+ = +
.
( 1)
ij
w t +
is the weight value of t+1 times iterative.
( )
ij
w t
is the weight value of t times iterative.
J
is the
Jacobian matrix of error on weight value differential
calculus.

is a scalar which is bigger than zero and can


self-adapt. When

is extremely big, the formula is


similar to gradient method. When

is extremely small,
the formula becomes Gauss-Newton method. I is unit
matrix. And e is error vector.
Gradient decrease method descends greatly at the first
steps. When it approaches the best value, the gradient is
coming to zero, which can slow down the objective
function. Newton principle could generate an ideal
direction of searching when formula reaches the best
value. Levenberg-Marquart algorithm is actually a
combination of gradient decrease method and Newton
principle. Its advantage lies in the fast convergent speed
when the number of network weight value is relative
small.
E. Steps of BP algorithm BP
Based on the standard algorithm of BP, this method
uses LM algorithm to modify weight value and threshold
ranging from input layer to hidden layer and hidden layer
to output layer [See Fig.2].
III. SIMULATION EXPERIMENT
Use Matlab language in PC
Pentium4/CPU3.0GHz/RAM1.0G to program to realize
the BP algorithm mentioned in the previous section. In
order to guarantee the efficiency, we need to compare the
prediction of stock index with the practical stock index in
Shanghai Stock Exchange Center on the basis of BP
model.
Set up parameter: compose a BP network model of 10
`10`1. The input number of 10 input layer are the
closing price and volume stock A in Shanghai Stock
Exchange Center and monthly social retail goods, price
index, added value of industry at the same period of time
in the following: n-1, n week ( n=2, 2, , 188). The
output value is the closing price of Shanghai Stock
Exchange Center in the n+ 1 week.
Use the trained network to predict the weekly
closing price of stock index of Shanghai Stock
Exchange Center from 2nd November 2007 to
11th July 2008. Through 21 times of iterative
calculation, the error of network reaches 0.
0962624% which meets the requirement of
expected error 0.1% [See Fig.3].
Figures of BP network simulation prediction
curved line trend and the practical stock index of
Shanghai Stock Exchange Center trend are as the
following. We can see from the two figures the
result of our BP network simulation model is
identical to the practical data during the 20 weeks
from 2nd November 2007 to 14th March 2008.
Furthermore, our BP network simulation model
has achieved satisfactory result in the prediction
of turning point [See Fig.4].
The error remains in 10% ranging from 2nd
November 2007 to 1st February 2008. The error
remains in 20% ranging from 5th February to 14th
March 2008 as is shown in Fig.5. In the following
time, the error begins to widen. Therefore, we
highly suggest remaining the time span in 20
weeks for prediction.

Figure 3. BP model simulation convergence trend curved line
based on LM algorithm
2007/10/26 2007/11/30 2008/01/04 2008/02/05 2008/03/14 2008/04/18 2008/05/23 2008/07/04 2008/08/08
1000
1500
2000
2500
3000
3500
4000
4500
5000
5500
6000
BP


ANN-BP


176

Figure 4. The training result of BP network simulation model
based on LM algorithm
2007/10/26 2007/11/30 2008/01/04 2008/02/05 2008/03/14 2008/04/18 2008/05/23 2008/06/27 2008/08/01
-0.7
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
BP

Figure 5. Trend of errors of BP network model for stock index of
Shanghai Stock Exchange Center based on LM algorithm
IV. CONCLUSION
This paper studies principles and general steps of
application of BP model to stock market prediction. In this
paper, we mainly discuss steps and methods of using BP
network to predict stock market, including sampling
principles, principles of determining the number of node
in hidden layers. This paper presents the setting up of
model, and actually predicts the closing index of Shanghai
Stock Exchange Center. This prediction has achieved the
expected result. With the aid of examples, this paper
proves that the BP network based on LM algorithm can fit
the stock data to predict after received studying and
training. Therefore, we can draw the conclusion that this
BP network model is appropriate for prediction for time
order.
REFERENCE
[1]Chengdong Wu and Changtao Wang, Application of artificial neural
cell BP network in stock prediction, Control Engineering, 2002(3).
[2]Jianli Yu, Zengqi Sun and Valeri.Kroumov, Modeling and decision
making in stock market based on BP neural network, Theory and
Practice of System Engineering ,2003(5).
[3]Hagan M T and Menhaj M B, Training feed forward net-works with
the marquardt algorithm, IEEE Transactions on Neural Netwoks, 1994,
5(6), pp.989-993.
[4]Dezhong Han, Study of prediction of stock market in China based
on neural cell network, Southern economy, 2006,(7).
[5]Jianli Yu, Zengqi Sun and Valeri.Kroumov, Modeling and
decision making in stock market based on BP neural network, Theory
and Practice of System Engineering, 2003(5).
177


Figure 2. LM flowing chart of BP algorithm
start
initialize weight value and threshold
study model is provided to BP network
calculate input and output node in hidden layer
calculate input and output node in output layer
calculate calibration error in hidden layer
modify weight value ranging from hidden layer
to input layer and threshold in input layer
modify weight value ranging from input layer
to hidden layer and threshold in hidden layer
update study input model
update study time
finish study
calculate calibration error in output layer
LM algorithm
yes
no
no
yes
finish all model training
error<o training times>N
178

You might also like