I want to predict the future prices, I have used only the daily historical prices as input. I can predict only one step ahead using this code: clear all; clear all; load('prices.mat'); set_size = 1413; targetSeries =prices(1:set_size); targetSeries = targetSeries'; targetSeries_train = targetSeries(1:set_size * (4/5) ); targetSeries_test = targetSeries(set_size * (4/5): end); targetSeries_train = num2cell(targetSeries_train); targetSeries_test = num2cell(targetSeries_test); feedbackDelays = 1:4; hiddenLayerSize = 10; net = narnet(feedbackDelays, hiddenLayerSize); net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; [inputs, inputStates, layerStates,targets] = preparets(net,{},{}, targetSeries_train); [inputs_test,inputStates_test,layerStates_test,targets_test] = preparets(net,{},{},targetSeries_test); net.trainFcn = 'trainrp'; % Levenberg-Marquardt net.performFcn = 'mse'; % Mean squared error net.plotFcns = {'plotperform','plottrainstate','plotresponse', ... 'ploterrcorr', 'plotinerrcorr'}; [net,tr] = train(net,inputs,targets,inputStates,layerStates); outputs = net(inputs_test,inputStates_test,layerStates_test); errors = gsubtract(targets_test,outputs); performance = perform(net,targets_test,outputs) view(net) % netc = closeloop(net); % [xc,xic,aic,tc] = preparets(netc,{},{},targetSeries_test); % yc = netc(xc,xic,aic); % perfc = perform(net,tc,yc) % nets = removedelay(net); % [xs,xis,ais,ts] = preparets(nets,{},{},targetSeries_test); % ys = nets(xs,xis,ais); % stepAheadPerformance = perform(net,ts,ys) how I can predict multistep ahead, for example the prediction of 10 days in advance.
Prashant Kumar answered .
2025-11-20
net = narnet(1:4,10);
net.trainParam.showWindow = false;
T = tonndata(Y,false,false);
[Xs,Xi,Ai,Ts] = preparets(net,{},{},T);
net = closeloop(train(net,Xs,Ts,Xi,Ai));
Ypred = nan(14,1);
Ypred = tonndata(Ypred,false,false);
Ypred(1:4) = T(end-3:end);
[xc,xic,aic,tc] = preparets(net,{},{},Ypred);
Ypred = fromnndata(net(xc,xic,aic),true,false,false);