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.
ANSWER
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
Take a look at the line where I define Ypred here I specify nans for the number of forecasts I want to make. I specify 4 more for pre-samples. Hope this helps. And ofcourse Y is your data Ypred are the forecasts 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);
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
Take a look at the line where I define Ypred here I specify nans for the number of forecasts I want to make. I specify 4 more for pre-samples. Hope this helps. And ofcourse Y is your data Ypred are the forecasts
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);
SEE COMPLETE ANSWER CLICK THE LINK
Comments
Post a Comment