👨🎓个人主页:研学社的博客
💥💥💞💞欢迎来到本博客❤️❤️💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
📋📋📋本文目录如下:🎁🎁🎁
目录
💥1 概述
通过文献调研,现阶段大部分股票择时的研究还是集中在传统的统计学模型上,将深度学习的理念应用于股票择时领域的研究寥寥无几。近年来,深度学习模型取得了长足的发展,正因为如此,CNN模型和RNN模型越来越多的进入到了人们的视野之中,而由CNN和 RNN组合形成的混合CNN-RNN模型势必有着良好的发展前;景。本文模型构建的大体思路就是将先进的CNN-RNN混合模型理念应用到股票择时令顶域,建立出能解决股票择时问题的模型,填补该领域的空白。
要点
贝叶斯优化分别用于调整混合CNN-RNN和浅层网络。
贝叶斯优化算法使用一个简单的过程来包含离散值。
此代码中使用了生成类似股票市场的过程(股票序列)。
📚2 运行结果
部分代码:
Lag = 1:optVars.Lag;
MiniBatchSize = str2double(char(optVars.MiniBatchSize));
% validation data
cv = cvpartition(size(TrainStandardizeddata,2),'HoldOut',0.2);
dataTrain = TrainStandardizeddata(cv.training);
dataValida = TrainStandardizeddata(cv.test);
% Data Preparation Train
XTrain = lagmatrix(dataTrain,Lag);
XTrain = XTrain(max(Lag)+1:end,:)';
YTrain = dataTrain(max(Lag)+1:end);
XrTrain = cell(size(XTrain,2),1);% independent variable lagged Lag months
YrTrain = zeros(size(YTrain,2),1);
for i=1:size(XTrain,2)
XrTrain{i,1} = XTrain(:,i);
YrTrain(i,1) = YTrain(:,i);
end
% Data Preparation Valida
XVal = lagmatrix(dataValida,Lag);
XVal = XVal(max(Lag)+1:end,:)';
YVal = dataValida(max(Lag)+1:end);
XrVal = cell(size(XVal,2),1);% independent variable lagged Lag months
YrVal = zeros(size(YVal,2),1);
for i=1:size(XVal,2)
XrVal{i,1} = XVal(:,i);
YrVal(i,1) = YVal(:,i);
end
% Testing data is calculated once the optimixation is finished
if exist('mviz')
XTest = lagmatrix(TestStandardizeddata,Lag);
XTest = XTest(max(Lag)+1:end,:)';
YTest = TestStandardizeddata(max(Lag)+1:end);
XrTest = cell(size(XTest,2),1);% independent variable lagged Lag months
YrTest = zeros(size(YTest,2),1);
for i=1:size(XTest,2)
XrTest{i,1} = XTest(:,i);
YrTest(i,1) = YTest(:,i);
end
end
numFeatures = size(XTrain,1);% it depends on the roll back window (No of features, one output)
% CNN-RNN
% you can follow this template and create your own Architecture
layers = [...
% Here input the sequence. No need to be modified
sequenceInputLayer([numFeatures 1 1],'Name','input')
sequenceFoldingLayer('Name','fold')
% from here do your engeneering design of your CNN feature
% extraction
convolution2dLayer(optVars.FilterSize1,optVars.NoFilter1,'Padding','same',...
'WeightsInitializer','he','Name','conv');
eluLayer('Name','elu')
convolution2dLayer(optVars.FilterSize2,optVars.NoFilter2,'Padding','same',...
'WeightsInitializer','he','Name','conv1');
eluLayer('Name','elu1')
maxPooling2dLayer(5,'Padding','same','Name','MPL')
% here you finish your CNN design and next step is to unfold and
% flatten. Keep this part like this
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
% from here the RNN design. Feel free to add or remove layers
bilstmLayer(128,'Name','bilstm','RecurrentWeightsInitializer','he')
dropoutLayer(0.25,'Name','drop1')
% this last part you must change the outputmode to last
lstmLayer(64,'OutputMode',"last",'Name','lstm',...
'RecurrentWeightsInitializer','he')
% here finish the RNN design
% use a fully connected layer with one neuron because you will predict one step ahead
fullyConnectedLayer(1,'Name','fc')
regressionLayer('Name','output') ];
🎉3 参考文献
部分理论来源于网络,如有侵权请联系删除。
[1]杨昊宇. 基于混合CNN-RNN模型的股票择时研究[D].首都经济贸易大学,2021.DOI:10.27338/d.cnki.gsjmu.2021.000966.
[2]H Sanchez (2023). Stock Market Prediction Using Bayes Optimized Hybrid CNN-RNN .