MATLAB Answers

NARNET FOR BINARY CLASSIFICATION PREDICTION

17 views (last 30 days)
Mario Viola
Mario Viola on 19 Feb 2021
Commented: Mario Viola on 24 Feb 2021
Hi all, i am trying to implement a NARNET for predicting next day return direction (either up or down). In all the examples i saw, the prediction is made on the exact value of the time series cosnidered. However, i would like to simply get the positive or negative difference between two consecutive closing prices (in terms of 1 & 0, for example). I tried with simpler networks, such as patternnet or feedforward net, but the performance was very poor. With the NARNET and its delays feature, i thought it would be a more suitable netwrok for this kind of predictions. I will attach the code i wrote so far.
StockData = readtable('MSFT.csv');
Close = StockData.Close;
Date = StockData.Date;
T = timetable(Date,Close);
if any(any(ismissing(T.Close)))== 1
T = fillmissing(T,'linear');
end
r = NaN(size(T.Close,1),1);
r(2:end) = T.Close(2:end) ./ T.Close(1:end-1) - 1;
nextDayReturn = double(r(2:end) > 0);
nextDayReturn(nextDayReturn==0)=-1;
F = tonndata(nextDayReturn,false,false);
trainFcn = 'trainlm';
feedbackDelays = 1:5;
hiddenLayerSize = [10 10];
net = narnet(feedbackDelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t] = preparets(net,{},{},F);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.performFcn = 'mse';
net.trainParam.epochs = 15000;
net.trainParam.goal = 1e-15;
net.trainParam.min_grad = 1e-40;
net.trainParam.max_fail = 100;
[net tr] = train(net,x,t,xi,ai);
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
Another idea i had was to train the networks on the Closing Prices Series, and when predicting the values of the Prices, Calculating the difference of consecutive prices and setting it equal to 1 if positive or 0 otherwise. I need it coded in terms of 1 and 0 (or -1 eventually) for implementing a trading strategy based on these kind of signals.
Hope i was clear in the explanation, and hope you could help me in finding a solution. Any kind of suggestions or improvements on the kind of analysis i'm trying to implement would be appreciated as well. I'm Kinda Stuck!

Accepted Answer

Jack Xiao
Jack Xiao on 21 Feb 2021
you can refer the given demo for classification, in fact the given net in the demo can be applicative. the key is that you should prepare your trainding data carefully, the paried input and output (1 or 0) should be processed beforehand.
  1 Comment
Mario Viola
Mario Viola on 24 Feb 2021
Thank you for your answer! Could you please attach the demo you are reffering to, i am not sure to which one you are reffering.
I just would like to know if i can sonehow combine a NARNET and a PATTERNET, meaning for example using the latter one but with a delayed set of inputs, in order to better capture the patterns in the financial series.
This refers also to the processing of inputs and outputs, as i should pair the return (output) in one day (1 or 0), with a series of inputs (for ex. not only returns in previous day, but also technical indicators and other variables). I know this refers to the NARXNET architecture, but i just wanted to know if, theoretically, something like this could be implemented.

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by