Filter löschen
Filter löschen

Stock market prediction using Neural Networks.

1 Ansicht (letzte 30 Tage)
Vineet
Vineet am 23 Apr. 2013
I'm using a neural network under supervised learning mode and I aim to predict the Buy, Sell or Hold Signals for future values.
The inputs to the output function are Positive Directional Index, Negative Directional Index and Average Directional Index defined here: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:average_directional_index_adx
The output function is as follows:
function Y=test_decision(DIP, DIN, ADI)
if (DIP>DIN)&&(ADI>25)%+ve DI greater than -ve DI and ADX>25
buy=(abs(DIP-DIN))/ADI;
ratio=DIP/DIN;
if(ratio>=1)
ratio=1/ratio;
end
sell=(1-buy)*ratio;
hold=1-buy-sell;
Y=[buy sell hold];
elseif (DIN>DIP)&&(ADI>25)%-ve DI greater than +ve DI and ADX>25
sell=(abs(DIP-DIN))/ADI;
ratio=DIP/DIN;
if(ratio>=1)
ratio=1/ratio;
end
buy=(1-sell)*ratio;
hold=1-sell-buy;
Y=[buy sell hold];
else
ratio=(abs(DIP-DIN)/ADI);
if ratio>1
ratio=1/ratio;
end
hold=1-ratio;
ratio1=DIP/DIN;
if ratio1>1
ratio1=1/ratio1;
buy=(1-hold)*ratio1;
sell=1-hold-buy;
else
sell=(1-hold)*ratio1;
buy=1-hold-sell;
end
Y=[buy sell hold];
end
Now, the output of this function is a nx3 array, where n is the number of input data and 3 values in each data element, which are (DIP, DIN, ADI)- Positive Directional Index, Negative Directional Index and Average Directional Index, respectively.
I'm using the following code to define and train the neural network:
for loop=1:n
y(loop,:)=test_decision(DI_P(loop), DI_N(loop), ADX(loop));
end
P=[DI_P DI_N ADX];
T=y;
net=newff(P,T, [10 10], {'tansig', 'purelin'},'trainlm', 'learngdm');
net.trainParam.show = 10; %showing results after every 10 iterations
net.trainParam.lr = 0.01; %learning rate
net.trainParam.epochs = 50; %no. of iterations
net.trainParam.goal = 0.0001; % percentage error goal
net1 = train(net, P, T);%training the network
Am I training using the right values? Am I using the right parameters for prediction of stock market decision? If yes, I need to plot the output values and the predicted values and find out the mean square error.

Akzeptierte Antwort

Greg Heath
Greg Heath am 23 Apr. 2013
Why don't you use all of the defaults you can?
You have specified two hidden layers. One is sufficient.
You have not specified enough transfer functions for 2 hidden and 1 output layer.
You have not included the VERY IMPORTANT training history structure, tr:
[ net1 tr Y E ] = train(net, P, T);% output Y, error E = T-Y
tr = tr % Will reveal more than you want to know.
Hope this helps.
Thank you for formally accepting my answer
Greg
  1 Kommentar
Vineet
Vineet am 24 Apr. 2013
I changed the code as follows: net=newff(P,T, [10], {'tansig', 'purelin'},'trainlm', 'learngdm');
net.trainParam.show = 10; %showing results after every 10 iterations
net.trainParam.lr = 0.01; %learning rate
net.trainParam.epochs = 50; %no. of iterations
net.trainParam.goal = 0.0001; % percentage error goal
net1 = train(net, P, T);%training the network
[net1 tr Y E]=train(net , P, T);
tr=tr;
% P0=get_test_data();
z=sim(net, P);
figure();
plot(z, 'r');
hold all
plot(Y);
d=(T-Y).^2;
mse=mean(d);
disp('MSE = ');
figure();
plot(mse);
disp(mse);
Now, plotting z and Y on a graph gives me a number of lines, but I want only two. That is, I want only TWO lines that plot the actual output and the neural network trained output. Please help. Btw, I didn't understand what 'tr' does. Kindly elaborate.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by