﻿ 基于Bi-LSTM深度学习的股票价格预测

# 基于Bi-LSTM深度学习的股票价格预测Stock Price Prediction Based on Bi-LSTM Deep Learning

Abstract: Stock price prediction has been widely concerned by financial investors and scholars, and it is also the research focus of scholars. The non-linearity and volatility of stock prices make the accuracy of stock prediction using traditional statistical methods less than ideal. LSTM model has great advantages in processing time series data. In order to further optimize the prediction model, this paper proposes a bidirectional propagating long and short time memory cycling network (Bi-LSTM), which can forecast stock prices by bidirectional propagating historical data. In addition, the traditional neural network BP, LSTM and GRU are introduced to compare with the Bi-LSTM model proposed in this paper, and four error evaluation methods of MSE, RMSE, MAE and R2 are introduced to evaluate the model to verify the prediction accuracy of the model. The empirical results show that the Bi-LSTM network based on ADAM optimization algorithm is superior to BP, LSTM, GRU and other traditional prediction models, and the accuracy is significantly improved, which verifies the effectiveness and feasibility of this model.

1. 引言

2. 模型和方法

2.1. Bi-LSTM的基本原理

LSTM (Long short-term memory)是循环网络RNN的一种，用来处理时间序列模型，LSTM模型采取了特殊的门结构，解决了RNN模型在训练过程中的梯度消失以及梯度爆炸等问题。LSTM模型的基本单元结构如图1所示，通过sigmoid函数对数据进行激活，充当门控信号；通过门控机制来控制信息的累积或遗忘。

Figure 1. Basic unit structure of LSTM

LSTM模型包含三个门结构：

1) 输入门：决定在t时刻是否会有信息输入到记忆细胞。

2) 遗忘门：决定将记忆细胞中的值遗忘掉还是保留下来。

3) 输出门：决定信息是否要从记忆细胞中输出。

LSTM的这种门控结构，能够更好适应于时间序列数据的处理，有效地解决长短时间序列变化上的问题。

LSTM的计算公式如下：

${f}_{t}=\sigma \left({w}_{f}\cdot \left[{h}_{t-1},{x}_{t}\right]+{b}_{f}\right)$

${i}_{t}=\sigma \left({w}_{i}\cdot \left[{h}_{t-1},{x}_{t}\right]+{b}_{i}\right)$

${\stackrel{˜}{C}}_{t}=\mathrm{tanh}\left({w}_{c}\cdot \left[{h}_{t-1},{x}_{t}\right]+{b}_{c}\right)$

${C}_{t}={f}_{t}\ast {C}_{t-1}+{i}_{t}\ast {C}_{t}$

${O}_{t}=\sigma \left({w}_{O}\cdot \left[{h}_{t-1},{x}_{t}\right]+{b}_{O}\right)$

${h}_{t}={O}_{t}\ast \mathrm{tanh}{C}_{t}$

Figure 2. The basic structure of Bi-LSTM

Table 1. Adam optimization algorithm to optimize the steps

3. 性能评价指标

$\text{MSE}=\frac{1}{N}{\sum }_{i=1}^{N}{\left({\stackrel{^}{y}}_{i}-{y}_{i}\right)}^{2}$ (5)

$\text{RMSE}=\sqrt{\frac{1}{N}{\sum }_{i=1}^{N}{\left({\stackrel{^}{y}}_{i}-{y}_{i}\right)}^{2}}$ (6)

$\text{MAE}=\frac{1}{N}{\sum }_{i=1}^{N}|{\stackrel{^}{y}}_{i}-{y}_{i}|$ (7)

4. 算例分析

Bi-LSTM是信息可以双向传播的LSTM结构，本文采用前9天股票的开盘价、最高价、最低价、收盘价、成交金额作为模型的输入，基于Bi-LSTM神经网络来对第10天的收盘价进行预测。

1) 将选取的数据分成训练集和测试集。在建立Bi-LSTM模型之前需要先对数据进行归一化处理，

2) 将归一化后的数据处理为可以批量运算的矩阵来训练Bi-LSTM神经网络，确定模型参数，对测试集进行预测，将预测结果进行反归一化处理后与真实收盘价进行比较。

3) 采用多种误差评估方法来对模型的预测效果进行度量。并将Bi-LSTM模型的预测误差与BP、LSTM、GRU模型的预测误差进行比较。

4.2. 实验数据

4.3. 数据描述

Figure 3. Line chart of Construction Bank stock

5. 参数设计

6. 实验结果分析

Figure 4. Comparison of predicted values and real values of different models

Figure 5. Fitting result graph of real value and predicted value

Table 2. Regression equation parameter table

Figure 6. Comparison of predicted and true values of different models

Figure 7. Error graph of different models

Table 3. Model prediction error table

7. 结语

[1] 许舒雅, 梁晓莹. 基于ARIMA-GARCH模型的股票价格预测研究[J]. 河南教育学院学报(自然科学版), 2019, 28(4): 20-24.

[2] 张倩倩, 林天华, 祁旭阳, 赵霞. 基于机器学习的股票预测研究综述[J]. 河北省科学院学报, 2020, 37(4): 15-21.

[3] 毛月月, 张秋悦. 基于机器学习的股票预测方法研究[J]. 现代计算机, 2020(23): 44-47.

[4] 张潇, 韦增欣. 随机森林在股票趋势预测中的应用[J]. 中国管理信息化, 2018, 21(3): 120-123.

[5] 张晶华, 莫文柯, 甘宇健. 基于SVM的上证指数预测研究[J]. 软件导刊, 2017, 16(8): 156-159+163.

[6] 崔文喆, 李宝毅, 于德胜. 基于GARCH模型和BP神经网络模型的股票价格预测实证分析[J]. 天津师范大学学报(自然科学版), 2019, 39(5): 30-34.

[7] Bahadur, S.T., et al. (2020) Stock Price Forecasting with Deep Learning: A Comparative Study. Mathematics, 8, 1441.
https://doi.org/10.3390/math8091441

[8] 方红, 韩星煜, 徐涛. 改进型基于LSTM的股票预测方法[J]. 安徽大学学报(自然科学版), 2019, 43(6): 36-42.

[9] 矫丰霞. 基于LSTM神经网络的股票价格预测研究[J]. 数字技术与应用, 2021, 39(3): 220-222.

[10] 陈伟斌, 林奕真, 王宗跃. 股票信息挖掘与LSTM预测[J]. 集美大学学报(自然科学版), 2020, 25(5): 385-391.

[11] 曾安, 聂文俊. 基于深度双向LSTM的股票推荐系统[J]. 计算机科学, 2019, 46(10): 84-89.

Top