Hi,
I am using a Time Dalay NARX Neural Network to predict the next day prices of stocks from a particular industry sector (marine and offshore, Singapore Exchange). I am using the attached dataset along with the following code for the prediction attempt. The prediction results are quite bad.
I had read that autocorelation and cross-correlation is required to get the number of delays, but I have been unsuccessful in implementing it. Could you modify the code below to implement auto-correlation and cross-correlation for getting the appropriate delays? It would be great if you have any suggestions to improve prediction accuracy. (Using additional data, different training algorithm, using additional algorithms etc.)
data=csvread('keppelcorp.csv',1,1); inputSeries = tonndata(data(2:end,:),false,false); targetSeries = tonndata(data(1,:),false,false); input = data(1:end,2:end); target = data(1:end,1); N=int32(0.7*size(input,1)); % how much data to use for training
inputSeries = tonndata(input(1:N,:),false,false); targetSeries = tonndata(target(1:N,:),false,false); inputSeriesVal = tonndata(input((N+1):end,:),false,false); targetSeriesVal = tonndata(target((N+1):end,:),false,false); inputDelays = 1:10; feedbackDelays = 1:10; hiddenLayerSize = 20; net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize); [inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries); net.divideFcn = 'divideblock'; % Divide data in blocks
net.divideMode = 'time'; % Divide up every value
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates); plotperform(tr) Y = net(inputs,inputStates,layerStates); % Prediction Attempt
N=size(inputSeriesVal,2); delay=length(inputDelays); inputSeriesPred = [inputSeries(end-delay+1:end),inputSeriesVal]; targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))]; netc = closeloop(net); [Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred); yPred = netc(Xs,Xi,Ai); perf = perform(net,yPred,targetSeriesVal); perf_mae = mae(net,targetSeriesVal, yPred); perf_mse = mse(net,targetSeriesVal, yPred); close all; targetSeriesVal = targetSeriesVal(2:end); targetSeriesVal(end+1) = targetSeriesVal(end); figure; plot([cell2mat(targetSeries),nan(1,N); nan(1,length(targetSeries)),cell2mat(yPred); nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]') legend('Original Targets','Network Predictions','Expected Outputs') figure; plot([cell2mat(yPred);cell2mat(targetSeriesVal)]') legend('Network Predictions','Expected Outputs') disp('Performance is') perf disp('Mean absolute error performance is') perf_mae disp('Normmalized MSE Performance is') perf_mse disp('Next day closing price was forecasted to') yPred(end) csvwrite('Real 1st column and 2nd column Predicted Prices.csv',[targetSeriesVal',yPred']);
Best Answer