Research Article

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

Algorithm 1

Part of the code of MATLAB.
sample = xlsread(‘data.xls’)
m,n = size(sample);
ts = sample(2:m,4);
tsx = sample(1:m-1,:);
TS = ts’;
TSX = tsx’;
Pn1,minp1,maxp1 = premnmx(TS)
Pn2,minp2,maxp2 = premnmx(TSX)
rand(‘state’,0);
PR = −1,1; −1,1; −1,1; −1,1; −1,1 ;
net=newff(PR, 11,1 ,{‘tansig’,‘purelin’},‘traingdx’,‘learngdm’,‘mse’)
net.trainparam.show = 50;
net.trainparam.lr = 0.1;
net.trainparam.mc = 0.9;
net.trainparam.epochs = 10000;
net.trainparam.goal = 0.005;
net = init(net);
net = train(net,Pn2(:,1:41),Pn1(1:41));
% Forecast
test = Pn2(:,42:end);
Y = sim(net, test)
P = postmnmx(Y, minp1, maxp1)
e = (sample(42:m-1,4)’-P)./sample(42:m-1)
% Calculate total error of network
res = norm(e)
figure(1)
t = 42: m-1
% Draw figure
plot((1:m-1), sample(1:m-1),‘-*’,t, P, ‘o’)