NARNET FOR BINARY CLASSIFICATION PREDICTION
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Jack Xiao
2021-2-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!