您的方法看起来很合理,而且是的RNN适合您的数据(时间序列)。然而,由于它们具有混乱的行为,并且股市预测是其中之一(其他包括缉获预测,地震预测,飓风预测......),所以存在相对较少的难以预测的问题。所以,如果你问是因为你没有收到好的结果,请牢记这一点。由于您使用的是MATLAB
,因此我建议您查看NARXNET
(具有外部输入的非线性自回归神经网络,https://www.mathworks.com/help/nnet/ref/narxnet.html)。这些就像类固醇上的递归神经网络一样。您想要开始以开环形式进行训练,然后以闭环形式进行再训练。这里有一个有用的链接,讨论开放/闭环形式:
https://www.mathworks.com/matlabcentral/answers/310535-narxnet-closed-loop-vs-open-loop。希望这可以帮助。这是一些让你开始的代码。
function a = myNARXNET(in, out)
X = tonndata(in,false,false);
T = tonndata(out,false,false);
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = [10,10,10];
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
net.layers{1}.transferFcn = 'radbasn';
net.layers{2}.transferFcn = 'tansig';
net.layers{3}.transferFcn = 'tansig';
net.inputs{1}.processFcns = {'mapminmax','mapstd'};
net.inputs{2}.processFcns = {'mapminmax','mapstd'};
[x,xi,ai,t] = preparets(net,X,{},T);
net.trainParam.max_fail = 10;
net.trainParam.goal = 1e-10;
net.performParam.regularization = 0.5;
net.trainParam.epochs = 1000;
net.trainParam.min_grad = 1e-10;
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'time'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.performFcn = 'mse'; % Mean Squared Error
net.plotFcns = {'plotperform','plottrainstate', 'ploterrhist', ...
'plotregression', 'plotresponse', 'ploterrcorr', 'plotinerrcorr'};
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
%Switch the network to closed loop form and retrain
net = closeloop(net);
[x,xi,ai,t] = preparets(net,X,{},T);
[net,t] = train(net,x,t,xi,ai);
y = net(x,xi,ai);
a = net;
end