Case-Based Teaching for Stock Prediction System Based on
Deep Learning
FENG LI, LINGLING WANG*
School of Management Science and Engineering
Anhui University of Finance and Economics
Bengbu 233030, CHINA
Key-Words: Stock Prediction; Long and Short Term Memory; Stock Trend Analysis; Deep Neural Network.
Received: August 22, 2021. Revised: June 21, 2022. Accepted: July 14, 2022. Published: September 2, 2022.
1 Introduction
Recently, with the continuous improvement of
economy, the proportion of financial tertiary
industry in social economy is getting bigger and
bigger [1-3]. More standardized stock market and
perfect investment mechanism attract investors to
participate in the stock market [4]. The stock market
can enhance the flexibility of investment, promote
the circulation of economy, open up new investment
channels for investors, and increase the choice range
of capital investment [5]. To some extent, stocks
satisfy the possibility of higher target returns for
investors. From the perspective of enterprises,
stocks can play an important role in the management
and development of listed enterprises, and is
conducive to the self-renewal and development of
enterprise business management mechanism [6].
The stock market is characterized by the
coexistence of high return and high risk [7]. Since
the issue of stock, people hope to analyze the
specific stock market rules through the historical
trend of stock, in order to guide investors to choose
investment strategies [8]. At the same time, the
stock market is affected by various factors such as
the adjustment of national financial and fiscal
policies and the influence of external international
relations, so the stock market is complicated and
changeable. In order to respond to stock prediction,
people have carried on statistical analysis to the
stock historical transaction data, and summarized
the stock prediction law method after long-term
practice and research. However, this traditional
stock prediction method is difficult to accurately
study the basic law of the stock market [9].
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1325
Volume 19, 2022
Abstract: In recent years, securities investors hope to obtain certain income from securities investment by buying stocks.
By referring to the historical trading data of the stock market, investors take into account various technical indicators and
related financial data of listed companies to analyze and determine the investment plan, and select the appropriate stock
for investment, which is relatively time-consuming and energy consuming. In this paper, LSTM short and long-term
memory neural network is used for data modeling analysis, in-depth analysis of the inherent characteristics of the data,
research on stock trend prediction, stock price prediction model is constructed, and the prediction effect of the stock market
is explored. To examine different model structures to forecast the effect of future stock prices, and optimize the stock
prediction model, by controlling the stock prediction model of variable of the factors affecting the prediction effect of
contrast experiment results were analyzed, and the evaluation model prediction accuracy, to build and train a good stock
prediction model. Finally, combined with the optimized stock price prediction model, it can help investors make better
investment decisions and bring relatively stable income for investors.
The financial tertiary industry has a relatively
large proportion in the whole social and economic
system, and the stock is an important part of the
financial market. Stock investment is the choice of
most investors in popular financial management.
However, as the current financial market is still full
of artificial manipulation, it is difficult for ordinary
investors to study stock market through some
financial research methods [10]. Due to the lack of
technical strength, it is difficult for ordinary
investors to make correct decisions for their
investment behavior through some technical
theories.
Therefore, it is of great significance to study
stock prediction. In this paper, LSTM deep neural
network is used to replace the traditional neural
network for modeling. In the in-depth analysis of
the basic characteristics of stock data, the paper
explores the prediction of stock market, so as to help
ordinary investors and investment institutions to
predict stock trends more effectively. It can not
only avoid some elementary mistakes, so as to
stabilize the stock market to benefit, bring certain
economic benefits, has a high reference significance.
2 Related Work
With the development of computer technology
and artificial intelligence, deep neural network has
become an important research object. Its
application has entered into every field of life, and
has been widely used in the field of financial
information [11]. Tech companies in the financial
sector have been using breakthroughs in machine
learning algorithms to improve financial services,
opening up markets and bringing more significant
economic benefits. Therefore, in the continuous
development of artificial intelligence and machine
learning, the application of deep learning in finance
has also attracted people's attention.
Stock prediction is an important subdivision of
financial data analysis. Usually, use the basic data of
stock trading to predict the development and change
of the stock [12]. Because of machine learning
technology of continuous innovation, the new
algorithm can bring remarkable economic benefits
to the financial sector, a growing number of
researchers converts research direction to use
machine learning techniques, by machine learning
to analyze stock data, and studies some excellent
models, more accurate and more efficiently predict
the evolution of the future trend of the stock. For
example, Logistic regression, genetic algorithm,
support vector machine and so on are all classic
machine learning algorithms. According to the data
analysis results, many researchers have carried out a
lot of research work on quantitative stock selection,
such as decision tree, Bayesian network and KNN
for predictive analysis [13]. The back propagation
(BP) neural network has a good classification effect
and can predict the dynamic trend of the stock
market with the characteristics of the stock market
[14]. However, these algorithms still have some
shortcomings and stock prediction is a very
challenging problem. Because the stock market
transaction is a nonlinear and complex dynamic law,
its price trend has strong fluctuation and is disturbed
by many factors that affect the price. Linear models
do not predict efficiently. Traditional machine
learning algorithms are usually unable to clearly
analyze the depth features of the data, resulting in
low accuracy of the model [15].
The accuracy of the traditional machine
learning algorithm to analyze the changing rules of
the stock market still has some disadvantages, often
cannot explicitly mining the depth of the data
features [16]. With the continuous production of a
large amount of data in various industries, in order
to accurately predict and analyze the stock trend,
deep neural network began to play an important role
in the data analysis work, and people began to pay
extensive attention to the establishment of deep
neural network to describe the law of stock price
and research stock prediction. Scholars in the field
of finance and data analysis have also carried out in-
depth research in related aspects. Many algorithms
and optimization strategies have appeared, and the
effect of stock trend prediction has been
successfully improved. Deep neural network
technology solves many problems of large data and
complex relationship. Therefore, many scholars
continue to study new deep neural network models
to predict stocks. The long term memory (LSTM)
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1326
Volume 19, 2022
model proposed by Hochreiter and Schmidhuber is
optimized based on RNN structure, which solves the
problem that RNN model cannot describe long term
memory of long time series [17]. LSTM model can
describe the long memory of time series well, so
LSTM deep neural network has a good effect on
stock price prediction.
LSTM depth of neural networks in
combination with the characteristics of time series
data, through the study of the internal structure of
loop feedback to data with time sequence logic, and
then through the oblivion gate control signal to
selective memory of memory units of information,
which improves the RNN circulation problems
gradient disappeared in the neural network, made up
for the long memory of RNN sexual problems [18].
3 Deep neural network model
3.1 Recurrent Neural Network
Recurrent Neural Network (RNN) is capable
of processing sequence data with contextual logic in
a better way, and has the characteristic of node
directionally connecting into a loop [19]. Such as
speech recognition, text language prediction, stock
data sample sequence, etc., the data of each node in
the sequence is correlated with the data before and
after the sequence. To meet the needs of these
dynamic time sequence situations, RNN recurrent
neural network can retain the previous information
and take the memory information of the last moment
as the input information of the next moment, so it is
good at dealing with these application scenarios
with time sequence correlation in Fig.1.
Fig.1. Structure expansion diagram of RNN
3.2 Deep neural network of short and long
duration memory
Long short-term Memory (LSTM) model
proposed by Hochreiter and Schmidhuber [17]
solved the problem that RNN model lacked the
ability of Long Term Memory. The internal
structure of LSTM neural network solved the defect
of gradient disappearing phenomenon in RNN
model and the problem that it could not describe the
long-term dependence of time series by introducing
gated logic unit.
The gated logic unit is composed of three parts:
input gate, output gate and forgetting gate, which
together with memory cells constitute the internal
structure of LSTM in a moment [20]. The structure
diagram of multiple moments is spliced horizontally
in the Fig.2.
Fig. 2. LSTM unit structure diagram
For RNN, at every moment, the information in
memory cells will be covered, while the processing
of memory information in LSTM will be different.
It multiplicates the value of the original memory cell
by the value of the Forget Gate and the value of the
input into the information memory cell as the input
information at the next time point. Its memory
information and input information are added
together, so unlike the RNN, which will be
overwritten at every time point. As soon as the
information from the previous moment is
overwritten, the effect disappears. In this way, short-
term memory can be carried out in the LSTM neural
network structure, unless the information in the
A
X(t-1)
H(t-1)
A
X(t)
H(t)
A
X(t+1)
H(t+1)
σ σ σ
tanh
×
× ×
+
tanh
Xt-1
Ct-1 Ct
Ht-1 Ht
Forget gate
FtInput
gate
It
Output
gate
Ot
Candidate
gate
Ct
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1327
Volume 19, 2022
memory unit is selectively forgotten by the forget-
gate control signal. Therefore, LSTM deep neural
network model can better conform to the long
memory of stock data and time series correlation,
that is, can reduce the gradient disappearance and
other problems.
4 Stock prediction model based on
LSTM deep neural network
As the stock market is a complex and
changeable dynamic system with large trading
volume, the problem of predicting stock price has
become an important problem in financial data
analysis. LSTM deep neural network with long and
short memory is good at mining the depth features
of data and dealing with the problems of long time
series data and complex nonlinear relations. It has
achieved excellent results in natural language
processing, text prediction and speech recognition.
Construct LSTM stock prediction model and study
and train basic stock historical data. For stock
prediction model, design a performance well and
achieve relatively accurate projections for stock
movements, it will influence the prediction effect of
stock time series data sample length and hidden
layer structure of network to carry on the contrast
experiment, modeling analysis, respectively, and
evaluate its effect on the prediction effect. And
finally, choose the optimal parameters to build stock
prediction model.
4.1 Design of stock prediction model based
on LSTM deep neural network
When modeling and analysis based on LSTM
deep neural network, it is necessary to set and
optimize the parameters of the stock prediction
model, such as the number of nodes of the input
layer and output layer, the number of hidden layers
and nodes of the stock prediction model according
to the input basic stock trading data, so as to
improve the accuracy of the stock prediction model.
4.1.1 Node setting of input and output layers
The basic stock data of the previous N trading
days are used to predict the stock closing price of
the next trading day, that is, the stock closing price
of the N+1 trading day. The input variable is the
sample with a time series length of N formed by the
basic data of the stock price trend, so the number of
neurons in the input layer is N. The output layer of
the stock prediction model is set with 1 neuron.
4.1.2 Hidden layer node setting
The setting of the hidden layer is mainly to set
the number of hidden layers and nodes. For the
construction of the hidden layer structure of LSTM
deep neural network model, there is no standard
conclusion and rule on how to set it [15]. To solve
different problems, it is necessary to adjust the
hidden layer setting according to different
situations. The comparative analysis shows that
increasing the number of hidden layer nodes can
improve the performance and accuracy of the
prediction model better than increasing the number
of hidden layer nodes. The hidden layer number is
set to 2, which can avoid the influence of the
complexity of stock data relationship as far as
possible, and the overall effect is good.
Additionally, for setting the number of hidden
layer nodes, it is generally believed that the number
of hidden layer neuron nodes has a great influence
on the complexity of the stock prediction model,
and also directly affects the performance of the
prediction model. By increasing the number of
hidden layer neuron nodes, the prediction error is
smaller, which is more effective than increasing the
number of hidden layer.If the number of nodes in
the hidden layer is too small, the model training will
not learn the characteristics of the training data
sample, and the learning effect of the data sample
will be greatly reduced. On the contrary, if the
number of nodes in the hidden layer is too large, the
over-fitting phenomenon will easily occur, and the
complexity of the network model will greatly
increase, and the prediction time will also increase.
Based on the analysis, the initial number of nodes in
the hidden layer of the stock prediction model is set
as 64 nodes.
4.1.3 Other parameters
In order to optimize the neural network model
and speed up the convergence of the gradient
descent of the stock prediction model, some
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1328
Volume 19, 2022
optimization methods are usually adopted to avoid
the over-fitting phenomenon with weak
generalization ability of the
Fig. 3. Experiment results
model (that is, the error on the training set is small,
but the relative error between the prediction result
and the test set is large). To mitigate model
overfitting usually requires collecting more data or
reducing model complexity. The stock prediction
model using LSTM neural network is constructed
and trained based on the basic stock data, and other
parameters of the stock prediction model are set:
The time series length N of the stock sample data set
was initially set as 5, and the model was constructed
for experimental comparison by increasing the time
series length continuously. The number of nodes in
the hidden layer was initially set as 64, the number
of iterations was set as 50, the activation function
was set as Tanh by default, and Adam algorithm
was selected by the optimizer. After optimization,
the data of various parameters would not fluctuate
greatly. The loss function is set as the mean square
error (MSE) loss function. In the establishment of
multiple comparison models, change the time series
length and hidden layer network structure and other
factors that affect the actual effect of the stock
prediction model, build a model with comparison
effect, and conduct repeated experiments to verify
the results.
We collect the stock market data from Kaggle.
The dataset represents 5 years of end-of-day data
from member stocks of the S&P 500.. It contains the
date, high, low, open, close and volume data points
typically found in stock-market trading data.
A stock data sample with a time series length
of N is taken as input and the forecast price of the
next trading day is obtained through the prediction
of the stock prediction model. At the same time,
because the standard unit and value range of the
basic data of each stock in the basic data set of stock
trading is different, it is necessary to preprocess the
stock data designated for prediction and divide the
processed data set. The sequence length of the input
data sequence is N, and the N value is set to 10. The
stock price of the next trading day predicted by the
stock prediction model is taken as the prediction
result.
Finally, the whole stock historical data samples
are divided into training sets and test sets. 80%
stock data samples are used as training data sets to
construct and train stock prediction models. The last
20% is divided into test data sets, and the accuracy
of the stock prediction model is calculated and
optimized. The prediction price is $85, and
accacracy of prediction is 95.63% in Fig. 3.
4.2 Experiment results
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1329
Volume 19, 2022
This paper mainly realizes the stock prediction
problem based on LSTM. Due to the nonlinearity of
stock data and strong temporal logic, LSTM is used
to construct the stock prediction model combining
with the historical stock trading data. Through the
stock prediction system, the stock prediction effect
is displayed, the model with better effect is called,
and the stock price specified by the user is
predicted. The operation is simple and the prediction
result is clear. To a certain extent, it can solve the
problem of stock selection and earnings expectation
of investors. Through the system, it can predict the
stock price and choose the relatively correct stock
investment strategy, so as to obtain relatively stable
investment income. It has high maneuverability and
practical value.
Acknowledgment
We thank the anonymous reviewers and editors
for their very constructive comments. This work
was supported in part by the Natural Science
Foundation of the Higher Education Institutions of
Anhui Province under Grant No. KJ2020A0011,
Innovation Support Program for Returned Overseas
Students in Anhui Province under Grant No.
2021LCX032. the Science Research Project of
Anhui University of Finance and Economics under
Grant No. ACKYC20085, Undergraduate teaching
quality and teaching reform project of Anhui
University of Finance and Economics under Grant
No. acszjyyb2021035.
References:
[1] Hipp, Christiane, and Hariolf Grupp.
"Innovation in the service sector: The demand
for service-specific innovation measurement
concepts and typologies." Research policy 34.4
(2005): 517-535.
[2] Xu, Li, and Junlan Tan. "Financial
development, industrial structure and natural
resource utilization efficiency in China."
Resources Policy 66 (2020): 101642.
[3] Gallouj, Faïz, and Maria Savona. "Innovation
in services: a review of the debate and a
research agenda." Journal of evolutionary
economics 19.2 (2009): 149-172.
[4] Khwaja, Asim Ijaz, and Atif Mian. "Unchecked
intermediaries: Price manipulation in an
emerging stock market." Journal of Financial
Economics 78.1 (2005): 203-241.
[5] Yeo, Khim T., and Fasheng Qiu. "The value of
management flexibilitya real option
approach to investment evaluation."
International journal of project management
21.4 (2003): 243-250.
[6] Schindehutte, Minet, Michael Morris, and
Jeffrey Allen. "Beyond achievement:
Entrepreneurship as extreme experience."
Small Business Economics 27.4 (2006): 349-
368.
[7] Gaunersdorfer, Andrea, and Cars Hommes. "A
nonlinear structural model for volatility
clustering." Long memory in economics.
Springer, Berlin, Heidelberg, 2007. 265-288.
[8] Siegel, Jeremy J. Stocks for the long run: The
definitive guide to financial market returns &
long-term investment strategies. McGraw-Hill
Education, 2021.
[9] Xiao, Chenglin, Weili Xia, and Jijiao Jiang.
"Stock price forecast based on combined model
of ARI-MA-LS-SVM." Neural Computing and
Applications 32.10 (2020): 5379-5388.
[10] Khwaja, Asim Ijaz, and Atif Mian. "Unchecked
intermediaries: Price manipulation in an
emerging stock market." Journal of Financial
Economics 78.1 (2005): 203-241.
[11] Pouyanfar, Samira, et al. "A survey on deep
learning: Algorithms, techniques, and
applications." ACM Computing Surveys
(CSUR) 51.5 (2018): 1-36.
[12] Zhang, Jing, et al. "A novel data-driven stock
price trend prediction system." Expert Systems
with Applications 97 (2018): 60-69.
[13] Zhu, Rongchen, et al. "Application of machine
learning techniques for predicting the
consequences of construction accidents in
China." Process Safety and Environmental
Protection 145 (2021): 293-302.
5 Conclusions
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1330
Volume 19, 2022
[14] Lahmiri, Salim. "Wavelet low-and high-
frequency components as features for
predicting stock prices with backpropagation
neural networks." Journal of King Saud
University-Computer and Information Sciences
26.2 (2014): 218-227.
[15] Khumprom, Phattara, and Nita Yodo. "A data-
driven predictive prognostic model for lithium-
ion batteries based on a deep learning
algorithm." Energies 12.4 (2019): 660.
[16] Wu, Xindong, et al. "Data mining with big
data." IEEE transactions on knowledge and
data engineering 26.1 (2013): 97-107.
[17] Hochreiter, Sepp, and Jürgen Schmidhuber.
"Long short-term memory." Neural
computation 9.8 (1997): 1735-1780.
[18] Zhang, Jianfeng, et al. "Developing a Long
Short-Term Memory (LSTM) based model for
predicting water table depth in agricultural
areas." Journal of hydrology 561 (2018): 918-
929.
[19] Mou, Lichao, Pedram Ghamisi, and Xiao Xiang
Zhu. "Deep recurrent neural networks for
hyperspectral image classification." IEEE
Transactions on Geoscience and Remote
Sensing 55.7 (2017): 3639-3655.
[20] Wei, Wangyang, Honghai Wu, and Huadong
Ma. "An autoencoder and LSTM-based traffic
flow prediction method." Sensors 19.13 (2019):
2946.
Sources of funding for research
presented in a scientific article or
scientific article itself
Creative Commons Attribution
License 4.0 (Attribution 4.0
International , CC BY 4.0)
This article is published under the terms of the
Creative Commons Attribution License 4.0
https://creativecommons.org/licenses/by/4.0/deed.en
_US
WSEAS TRANSACTIONS on BUSINESS and ECONOMICS
DOI: 10.37394/23207.2022.19.119
Feng Li, Lingling Wang
E-ISSN: 2224-2899
1331
Volume 19, 2022