How can I predict future values of currency prices, in a neural network time series trained with daily data, predicting 30 days into the future from the last day's data.
Ältere Kommentare anzeigen
I am using neural network time series tool to predict the values of currency exchange rates. I have trained the network using NARX model, delay - 2 hidden layers - 2 I trained the network with 4000 timesteps of data. I have also trained another network with hourly data - around 70000 timesteps data.
I used NaN values in the inputs and the targets, for the future 30 days that the network has to predict.
I am getting values like 0.0323, 0.0339, etc., close to zero and nowhere closer to the values that i need to see, somewhere around 0.9343 something.
I opened the loop and then also it came like that. I closed the loop, and increased the delay to 21, and then also it came like that.
I will paste my code here.
| | *
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by NTSTOOL
% Created Sat Sep 21 13:26:03 IST 2013
%
% This script assumes these variables are defined:
%
% input - input time series.
% output - feedback time series.
inputSeries = tonndata(input,false,false);
targetSeries = tonndata(output,false,false);
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 2;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
% Choose Input and 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
% Customize input parameters at: net.inputs{i}.processParam
% Customize output parameters at: net.outputs{i}.processParam
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.inputs{2}.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,inputSeries,{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
% The function DIVIDERAND randomly assigns target values to training,
% validation and test sets during training.
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
% The property DIVIDEMODE set to TIMESTEP means that targets are divided
% into training, validation and test sets according to timesteps.
% For a list of data division modes type: help nntype_data_division_mode
net.divideMode = 'value'; % 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
% Customize training parameters at: net.trainParam
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
% Customize performance parameters at: net.performParam
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
% Customize plot parameters at: net.plotParam
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, plotregression(targets,outputs)
%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);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(netc,tc,yc)
% Early 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);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,inputSeries,{},targetSeries);
ys = nets(xs,xis,ais);
earlyPredictPerformance = perform(nets,ts,ys)* | |
Can anyone tell me what I should be doing? How to predict the future values? I don't have any idea how to. Please help me.
I tried using the following code
testinseries = tonndata(testinput,false,false); testtargetSeries = tonndata(testoutput,false,false); netCL = openloop(net); [X,Xi,Ai,T] = preparets(net,testinseries,{},testtargetSeries); y = sim(net,X,Xi,Ai)
to predict the future output, but i am getting values like these.
Columns 1 through 7
[0.9182] [0.9161] [0.9168] [0.9182] [0.9181] [0.9183] [0.9179]
Columns 8 through 14
[0.9168] [0.9170] [0.9177] [0.9164] [0.9176] [0.9212] [0.9214]
Columns 15 through 21
[0.9212] [0.9195] [0.9199] [0.9202] [0.9190] [0.9189] [0.9190]
Columns 22 through 28
[0.9192] [0.9217] [0.9215] [0.9206] [0.9221] [0.9212] [0.0397]
Columns 29 through 35
[0.0569] [0.0569] [0.0569] [0.0569] [0.0569] [0.0569] [0.0569]
Columns 36 through 42
[0.0569] [0.0569] [0.0569] [0.0569] [0.0570] [0.0570] [0.0570]
Columns 43 through 44
[0.0570] [0.0570]
From the 28th value, they are the predicted output for the future, where i have given the input and targets as NaN.
I think that since the targets are given as NaN-0 , the values are being predicted like this. I have used closeloop method also, and i am getting similar results. ( i have given the openloop code here)
I really need to complete this project. If i complete this prediction it is over.
Can anyone help me? Please.
Thank you, in advance.
P.S:
Any code snippets would be helpful. If anyone has predicted future values using the tool, please help me.
1 Kommentar
ahmed salem
am 19 Mai 2018
How can I predict future values of currency prices, in a neural network time series trained with daily data, predicting 3 days into the future from the last day's data.y(t+1)depend on y(t),x(t)and history how predict y(t+2)such that depend on y(t+1),x(t+1)and history but x(t+1)unknown
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Signal Modeling finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!