20 Days ahead forecasts using NAR

2 views (last 30 days)
I am having a challenge with doing 20 days ahead prediction with NAR. My data consists of 1367 days Price observation. Please advice on what I should do to get the 20 days ahead Prices forecast. The code I generated thus far is as follows;
% Solve an Autoregression Time-Series Problem with a NAR Neural Network % Script generated by NTSTOOL % Created Wed Oct 29 16:03:19 GMT 2014 % % This script assumes this variable is defined: % % Price - feedback time series.
targetSeries = tonndata(Price,false,false);
% Create a Nonlinear Autoregressive Network feedbackDelays = 1:2; hiddenLayerSize = 10; net = narnet(feedbackDelays,hiddenLayerSize);
% Choose Feedback Pre/Post-Processing Functions % Settings for feedback input are automatically applied to feedback output % For a list of all processing functions type: help nnprocess net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
% Prepare the Data for Training and Simulation % The function PREPARETS prepares timeseries data for a particular network, % shifting time by the minimum amount to fill input states and layer states. % Using PREPARETS allows you to keep your original time series data unchanged, while % easily customizing it for networks with differing numbers of delays, with % open loop or closed loop feedback modes. [inputs,inputStates,layerStates,targets] = preparets(net,{},{},targetSeries);
% Setup Division of Data for Training, Validation, Testing % For a list of all data division functions type: help nndivide net.divideFcn = 'dividerand'; % Divide data randomly net.divideMode = 'time'; % Divide up every value net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
% Choose a Training Function % For a list of all training functions type: help nntrain net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function % For a list of all performance functions type: help nnperformance net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions % For a list of all plot functions type: help nnplot net.plotFcns = {'plotperform','plottrainstate','plotresponse', ... 'ploterrcorr', 'plotinerrcorr'};
% Train the Network [net,tr] = train(net,inputs,targets,inputStates,layerStates);
% Test the Network outputs = net(inputs,inputStates,layerStates); errors = gsubtract(targets,outputs); performance = perform(net,targets,outputs)
% Recalculate Training, Validation and Test Performance trainTargets = gmultiply(targets,tr.trainMask); valTargets = gmultiply(targets,tr.valMask); testTargets = gmultiply(targets,tr.testMask); trainPerformance = perform(net,trainTargets,outputs) valPerformance = perform(net,valTargets,outputs) testPerformance = perform(net,testTargets,outputs)
% View the Network view(net)
% Plots % Uncomment these lines to enable various plots. %figure, plotperform(tr) %figure, plottrainstate(tr) %figure, plotresponse(targets,outputs) %figure, ploterrcorr(errors) %figure, plotinerrcorr(inputs,errors);
% Closed Loop Network % Use this network to do multi-step prediction. % The function CLOSELOOP replaces the feedback input with a direct % connection from the outout layer. netc = closeloop(net); [xc,xic,aic,tc] = preparets(netc,{},{},targetSeries); yc = netc(xc,xic,aic); closedLoopPerformance = perform(netc,tc,yc)
% Multi-Step Prediction Network % For some applications it helps to get the prediction a timestep early. % The original network returns predicted y(t+1) at the same time it is given y(t+1). % For some applications such as decision making, it would help to have predicted % y(t+1) once y(t) is available, but before the actual y(t+1) occurs. % The network can be made to return its output a timestep early by removing one delay % so that its minimal tap delay is now 0 instead of 1. The new network returns the % same outputs as the original network, but outputs are shifted left one timestep. nets = removedelay(net); [xs,xis,ais,ts] = preparets(nets,{},{},targetSeries); ys = nets(xs,xis,ais); perfc = perform(net,tc,yc)

Accepted Answer

Greg Heath
Greg Heath on 31 Oct 2014
Try
FD = 1:20;
net = narnet(FD,H=10);
net.divideFcn = 'divideblock'; % Never use 'dividerand' for timeseries.
For details see
help narnet
doc narnet
and search the NEWSGROUP and ANSWERS using
greg narnet
Hope this helps
Thank you for formally accepting my answer
Greg

More Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!