0% found this document useful (0 votes)
41 views10 pages

Algo Trading

1. The document proposes a stock trend prediction algorithm based on a deep recurrent neural network that uses historical stock data, news data, and investor sentiment data. 2. The model combines bidirectional LSTM and contextual LSTM to extract features from the data and predict stock trends, outputting the probability of a stock going up or down. 3. Experiments on CSI 300 stock data show the proposed method improves prediction accuracy over a single LSTM model and can effectively predict stock trends to some extent.

Uploaded by

lijanamano6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views10 pages

Algo Trading

1. The document proposes a stock trend prediction algorithm based on a deep recurrent neural network that uses historical stock data, news data, and investor sentiment data. 2. The model combines bidirectional LSTM and contextual LSTM to extract features from the data and predict stock trends, outputting the probability of a stock going up or down. 3. Experiments on CSI 300 stock data show the proposed method improves prediction accuracy over a single LSTM model and can effectively predict stock trends to some extent.

Uploaded by

lijanamano6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Hindawi

Wireless Communications and Mobile Computing


Volume 2021, Article ID 5694975, 10 pages
https://doi.org/10.1155/2021/5694975

Research Article
Stock Trend Prediction Algorithm Based on Deep Recurrent
Neural Network

1
Ruochen Lu and Muchao Lu2
1
The University of Queensland, Brisbane 407s, Australia
2
Taiyuan University of Technology, Taiyuan 030024, China

Correspondence should be addressed to Ruochen Lu; [email protected]

Received 2 August 2021; Revised 23 August 2021; Accepted 24 August 2021; Published 14 September 2021

Academic Editor: Yuanpeng Zhang

Copyright © 2021 Ruochen Lu and Muchao Lu. This is an open access article distributed under the Creative Commons
Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work
is properly cited.

With the return of deep learning methods to the public eye, more and more scholars and industry researchers have tried to start
exploring the possibility of neural networks to solve the problem, and some progress has been made. However, although neural
networks have powerful function fitting ability, they are often criticized for their lack of explanatory power. Due to the large
number of parameters and complex structure of neural network models, academics are unable to explain the predictive logic of
most neural networks, test the significance of model parameters, and summarize the laws that humans can understand and
use. Inspired by the technical analysis theory in the field of stock investment, this paper selects neural network models with
different characteristics and extracts effective feature combinations from short-term stock price fluctuation data. In addition,
on the basis of ensuring that the prediction effect of the model is not lower than that of the mainstream models, this paper
uses the attention mechanism to further explore the predictive K-line patterns, which summarizes usable judgment experience
for human researchers on the one hand and explains the prediction logic of the hybrid neural network on the other.
Experiments show that the classification effect is better using this model, and the investor sentiment is obtained more
accurately, and the accuracy rate can reach 85%, which lays the foundation for the establishment of the whole stock trend
prediction model. In terms of explaining the prediction logic of the model, it is experimentally demonstrated that the K-line
patterns mined using the attention mechanism have more significant predictive power than the general K-line patterns, and
this result explains the prediction basis of the hybrid neural network.

1. Introduction turnability: once sold, stocks cannot be returned to the com-


pany and cannot be requested to be refunded but can only be
For investors, stocks meet different investment desires and sold to a third party through the secondary market; (2)
investment needs, expand the range of investment options, uncertainty of earnings: the profit and loss of stocks depend
expand investment channels, to some extent meet the possi- on the company’s operation and the stock exchange market,
bility of investors to obtain the corresponding income, and both of which are uncertain and changeable, so investors
to some extent enhance the flexibility and liquidity of capital need to take greater risks; and (3) speculative: the stock mar-
[1]. If we look at the enterprise side, the stock can play an ket fluctuates frequently and the market price is unstable.
important role in the management and development of the Market prices are unstable and speculative, so stocks are very
joint-stock enterprise, which is conducive to the establish- risky [3]. There are many reasons that affect the volatility
ment and improvement of the self-restraint and self- of stock prices, and these frequently changing factors
development of the enterprise management mechanism cause stock market volatility [4]. The objective risks of
[2]. For the country, stocks are also a great tool to counteract the stock market can bring gains to investors and at
inflation. Stocks have three main characteristics: (1) nonre- the same time can cause economic losses and may also
2 Wireless Communications and Mobile Computing

negatively affect the operating conditions of shareholding the whole stock trend prediction model. Secondly, on top
companies and even bring side effects to the national of the original LSTM, this model is constructed by a mixture
economic construction. of Bi LSTM [17] and CLSTM, with Bi LSTM extracting stock
These problems are inevitable, so stock trend prediction trading data and investor sentiment index-related features
has become an issue of great concern for all parties [5]. The and CLSTM integrating and processing the contextual fea-
research of stock trend prediction has also become an tures of the news, and finally outputting the prediction
applied research direction of financial big data, and many results through the fully connected layer. In the experimen-
scholars have adopted deep neural network methods to pre- tal model, the stock trend is experimented with using the
dict the stock trend, which has become one of the popular classification method [18–20], and the classification is
research problems in the current academic field. In recent obtained as the probability of the stock going up and the
years, with the rapid development of computer technology, probability of the stock going down. The experiments use
the deep neural network [6–8] has become the key research the CSI 300 stock data as the data set. The prediction effect
object nowadays, and the application field has been is evaluated by accuracy and return, and the experimental
expanded and extended, including the financial information results show that compared with a single LSTM prediction
field [9]. At present, the financial market occupies a pivotal model, the proposed method has a certain improvement in
position in the whole economic system of the country, and the accuracy of stock trend prediction and can predict stock
stocks are an important component of the financial market, trend accurately and effectively to a certain extent. At the
so buying stocks has become a popular financial manage- same time, a deep neural network stock trend prediction
ment method nowadays, and a stock analysis software with [21] system is designed and implemented, and the trained
various performance can meet the real needs of investors prediction model is uploaded to the stock prediction mod-
[10]. This paper designs and implements a stock trend pre- ule. By analyzing the requirements of the stock trend predic-
diction system by combining historical stock trading data, tion system and designing each functional module, the
news data, and investor sentiment to recommend stocks whole stock trend prediction system is completed after
and stock trend prediction services for investors to reduce development and testing. Investors can make stock selection
or avoid investment risks, thus bringing investors relatively and investment with the help of this system.
stable economic returns. Due to the continuous innovation
of machine learning techniques [11–13], more and more 2. Related Work
researchers are turning to the use of machine learning tech-
niques to analyze stock data and create well-performing The researchers constructed a denoising hybrid stock price
methodological models to predict stock movements in the prediction model based on a decision tree, which first
future. Stock market prediction models are built by learning extracts relevant features from stock data, then uses the prin-
from historical price data to predict future prices [14]. cipal component analysis algorithm to dimensionally reduce
Common machine learning algorithms such as logistic the features with the decision tree algorithm, and the dimen-
regression, genetic algorithms, and support vector machines sionally reduced data [22] is fed into the fuzzy model to pre-
have been used with good results in forecasting [15]. With dict stock prices [23]. The researchers created a Bayesian
the rise of neural network technology, building deep neural neural network model that does not require preprocessing
networks to portray stock prices and predict stock move- operations and cycle analysis of the data but simply feeds
ments has received a lot of attention, and some scholars have market prices and technical indicators into the prediction
conducted in-depth research in this area [16]. In order to model, which is used to predict the future closing price of
improve the accuracy of stock trend prediction, many the stock [24]. The researchers constructed a support vector
improved algorithms and optimization strategies have machine model with a genetic algorithm to optimize the data
appeared one after another and have been successfully by dimensionality reduction and used a quantitative stock
applied in practice. selection method to empirically analyze its stock selection
Compared with existing stock trend prediction models, performance and prediction accuracy in the short and
the improved model used in this paper combines stock price medium to long term, respectively [25]. The researchers first
trend, news information, and investor sentiment for predic- used wavelet decomposition of stock price series to screen
tion, not only using trading data in the stock market but also out the low- and high-frequency information in the nonsta-
taking into account the influence of financial and political tionary time series and then constructed an ARIMA model
news and stock forum speech on the stock market. In this from the high-frequency information and fitted the SVM
work, a framework for predicting stock price trends using model to the low-frequency information to obtain better
financial news and sentiment dictionaries combines a two- results [26].
stream gated recurrent unit for stock price trend prediction The researchers performed feature construction based
and a Stock2Vec embedding model trained on stock news on relevant technical indicators and used data mining tech-
and sentiment dictionaries. Firstly, we propose a plain niques for feature modelling [27]. The main method relies
Bayesian model based on the sentiment classification of on the idea of maximizing returns and proposes a support
stock forum speech and experimentally confirm that the vector machine for genetic parameter search with AUC
classification effect is better when using the plain Bayesian values under the ROC curve, which solves the problem of
classifier, which can obtain the investor sentiment more poor availability of forecasting with traditional methods.
accurately and lay the foundation for the establishment of The researchers used Tensor Flow, a Google AI learning
Wireless Communications and Mobile Computing 3

system, and thus built a multiperceptron MLP neural net- but there is still very little research on the domestic stock
work model for predicting each closing price, comparing market, which may be related to the fact that the domestic
Tensor Flow with a traditional BP neural network [28] based stock market was established late and many aspects are still
on the stock price prediction problem [29]. The researchers not well developed. However, the Chinese stock market has
used a different number of features and multivariate data grown to have more than 3,000 listed companies with a cir-
preprocessing to study the effect of long- and short-term culating market capitalization of tens of trillions of yuan,
memory networks (LSTM networks) on the prediction which occupies a significant share in the whole national
results, and the LSTM models increased the accuracy of financial system, so it is significant to study the domestic
stock return prediction compared to random prediction stock market. In this paper, we construct a long- and
methods [30]. Researchers use LSTM to predict stock prices short-term memory neural network model to predict the
and propose variable step integration methods and an domestic stock trend.
improved MSE loss function with improved prediction per-
formance, but the drawback is that no generalized optimal 2.1. Deep Recursive-Based Stock Trend Prediction Model
step range is derived.
Many factors can affect stock markets and cause market 2.1.1. Factors Influencing Stock Price and Fundamental
volatility, such as global economic conditions, domestic Analysis Method. Like other countries in the world, the Chi-
macroeconomic factors, and highly correlated foreign stock nese stock market is complex and dynamic. From the spe-
markets. However, most time series models use stock indices cific business environment of listed companies, the
as the only factor for prediction and do not consider more transparency of financial statements, and the psychological
variables, while the opposite can lead to better prediction sentiment of investors to the national policies and regula-
results [31]. Therefore, some scholars have developed senti- tions, unexpected news events, and the world economic sit-
ment analysis models for predicting the correlation between uation, all of them have a certain impact on it. Because the
investor sentiment and financial markets, and researchers stock market is affected by many factors, it is difficult to pre-
have studied the relationship between public sentiment dict and determine the future trend of stocks, and there is a
states obtained from Twitter and the Dow Jones Industrial large risk and unknown. At the same time, a stock is only
Average (DJIA) [32]. Two sentiment analysis models were marketable security, which does not have real value itself.
used to analyze the text content of daily Twitter feeds to Stock price refers to the trading price of a stock in the securi-
obtain and analyze changes in the public’s sentiment. ties market, and dividend income is obtained by buying and
Researchers’ sentiments were classified as positive and nega- selling stocks. Stock prices are influenced by various economic
tive, while GPOMS meticulously classified sentiments into and political factors and other external circumstances. Techni-
six categories, including calm, alert, sure, vital, kind, and cal analysis is a basic forecasting method that determines the
happy, with six different dimensions to measure sentiments future movement of the stock market by analyzing and judg-
[33]. Through the Granger causality test, a close relationship ing graphical charts and related technical indicators.
between public sentiment and the Dow Jones Average Index It is a method of making judgments about stock price
(DJIA) was found. Next, using a self-organizing fuzzy neural changes and stock trends based on market behavior itself,
network model, the public sentiment time series was used as combined with theories and methods related to psychology
the independent variable, and the model was found to be effec- and statistics, and based on historical stock trading data such
tive in predicting the change of DJIA closing price, which can as existing prices, rates of change, and volume in the stock
largely improve the accuracy of DJIA prediction [34]. market, as well as combining investors’ subjective judgments
The researchers propose a framework for predicting and analysis to find patterns. The actual trading history of a
stock price trends using financial news and sentiment dictio- particular stock or “average” is usually recorded in graphical
naries, combining a two-stream gated recurrent unit form, and then possible future trends are inferred from that
(TGRU) for stock price trend prediction and a Stock2Vec history. Technical analysis is based on the theory that mar-
embedding model trained on stock news and sentiment dic- ket behavior contains all information and is based on three
tionaries [35]. The researchers predict stock trends through theories: that all information is fair and open, that stock
the impact of financial news on stock market sentiment, prices move along a trend, and that historical stock prices
using more expressive features to represent the text and aug- repeat themselves. It mainly includes the indicator, K-line,
menting existing text mining methods by including market pattern, and wave methods. Because the stock system is
feedback as part of the feature selection process. Powerful highly nonlinear and stochastic, it requires the investor to
feature selection can greatly improve classification accuracy analyze graphical movements and data tables to obtain fore-
when used in conjunction with complex feature types, and casts, while understanding the role of relevant parameters
the approach allows the selection of semantically relevant and corrections. Therefore, this method is not applicable in
features, thus reducing the problem of overfitting when today’s increasingly large and complex stock market. In
applying machine learning methods. It can also be trans- addition to low efficiency, difficulty, and overreliance on
ferred to any other application area that provides textual manual experience, it also has a series of problems such as
information and corresponding effect data. In summary, poor integrity of stock content information, redundancy of
many applications have been made by many scholars using feature data, low utilization of stock data, poor results, and
neural network models for stock prediction analysis. But poor generalization, which brings certain difficulties in pre-
most of them have been analyzed for foreign stock markets, dicting stock prices and makes it difficult to meet the needs
4 Wireless Communications and Mobile Computing

of market development. Fundamental analysis is a method 16,000


to calculate the intrinsic value of a stock by looking at
the basic economic factors that may affect the stock price,
i.e., fundamentals. 14,000
Relevant factors considered include turnover, revenues Logical gains
and expenses, financial statements, the company’s growth
prospects, competitive factors facing the company, and the
expected return on equity or assets for the industry. The 12,000
purpose of this analysis is to determine a value for the stock
that takes all of these potential factors into account. Inves-
tors rely on a variety of financial tools to determine a com- 10,000
pany’s past, present, and future profitability in order to Fundamental disk growth
make investment decisions. Some of the key financial state-
ments that investors rely on include balance sheets, cash 8,000
flow statements, and income statements. Accurate financial 2009 2010 2011 2012 2013
statements are used to analyze the corresponding value of
Dow jones industrial average
a company. In order to determine the accuracy of such state-
Financial stability
ments, investors rely on independent auditors’ reports to
ensure the accuracy of the financial statements. The method Figure 1: Correlation between stock price and financial factors.
is considered a long-term investment approach because it
does not take into account short-term pricing and trading
fluctuations. The method also involves some element of bols, need to be deleted and processed. The authenticity and
forward-looking expectations, and it may take some time reliability of the research results are ensured by data prepro-
to realize the intrinsic value, so forward-looking information cessing operations.
needs to be evaluated before considering the use of this
method. Meanwhile, the method requires a comprehensive (1) Handling Missing Data. The initial data obtained
analysis of both macro- and microinformation. Micro is dif- may suffer from data loss, which may be due to
ficult to guarantee access to real and valid financial informa- incorrectly unentered data, data that is inconsistent
tion because of the asymmetry of corporate information, as with data from other records and therefore deleted,
shown in Figure 1. The specific parameters can be from data that was ignored at the time of entry, and unre-
the raw data collected by sensors, which are continuous data corded data changes. Missing data can be handled in
sequences generated by user movements over a period of a number of ways: by ignoring records, by manually
time. Macroscopically, it is also difficult to predict the filling in missing values or using global constants, or
national plan support policies and key development indus- by using attribute means or most likely values
tries. Therefore, the analysis method still needs to be through inference based on Bayesian formulas or
improved in terms of accuracy and timeliness, and it relies decision trees. Missing values were observed when
too much on the ability of analysts, and the analysis method certain stocks or indices were recorded as null on
is relatively difficult to apply and has certain limitations, certain dates, and to appropriately reduce the
especially for ordinary stock market investors, with poor fea- workload of this study, only stocks with up to ten
sibility and universality. To sum up, the fundamental analy- null values were selected for processing, which
sis method mainly analyzes the long-term trend of stocks, included skipping entire records containing missing
which is difficult to obtain, organize, categorize, and analyze values, or filling missing values with the mean, or
information, requires high analytical ability of investors, and using inference (e.g., based on most similar
does not allow reliable and accurate short-term forecasting. instances). All null values appearing in this experi-
ment are filled using the average of their closest left
2.1.2. Stock Trend Forecasting Model. The operational status and right nonnull values, making the stock time
of a listed company can be reflected by news information series data complete.
about the company’s stock. Based on the common feature
that news information is highly correlated with stock move- (2) Data Noise Reduction. Data contain a certain
ments, people often rely on news information to forecast amount of noise due to the complexity of market
stock movements. Due to the time-sensitive nature of news, dynamics. Noisy data are attributed to random
the information in news articles has a short time effect on errors or variations in measured variables, as well
the stock market, and in general, recent news has a large as errors in data collection tools, data entry errors,
impact on stock movements. In order to encode stock- etc. The noise present in stock datasets can usually
related news information, data preprocessing work is first be classified into three main categories: duplicate
performed on the text to reduce the repetition rate and cor- records, inconsistent stock names, and incomplete
rect the comment data with wrong formatting to improve files. Some files contain duplicate records. Therefore,
the integrity and quality of the comment data. Unreasonable all files are thoroughly checked to ensure that only
cases such as noisy data, such as null values and special sym- unique records are available on the same date. When
Wireless Communications and Mobile Computing 5

a public company changes its name or a company corpus, and the more frequently a word appears in a docu-
merges, there may be inconsistencies in stock names. ment to which it belongs, but hardly appears in all documents,
In this case, some of the data can use the old name the more it represents the key content. The importance of each
while the rest of the data can use the new name. word is determined by counting the total number of financial
The standard is set in solving this inconsistency commentary documents, the number of document words, the
problem, and all the old names appearing in the number of times the word appears in a particular document,
records are modified in bulk with the updated and the number of times the word appears in all documents.
records. Noise reduction is done by pywt library The formula for calculating the importance of a word in a
wavelet transform. given stock forum comment document is
(3) Data Normalization. Normalization is the “scaled n
down” transformation of data. If the value of one T f = 〠 wi + IDF : ð2Þ
component of an attribute is too large, the other i=1
attributes may lose their moderation effect. For
example, when stock price and trading volume are TF stands for word frequency and gives the frequency of
taken together as characteristic values, the difference words in each document in the corpus. It is calculated by the
between the two in terms of data volume is great ratio of the number of occurrences of a word in a document
because the stock trading volume is huge and can to the total number of words in that document. It increases
reach the level of billions, while the stock price is as the number of occurrences of the word in the document
only a few tens or hundreds, but it cannot be shown increases. Each document has its own TF. The formula is as
that the impact on price is proportionally greater follows:
because the value of the trading volume is larger.
The convergence of the model is often affected ni, j
Tf = : ð3Þ
because the data scale is not consistent, the gradient ∑ni=1 wi
is not “uniform,” the model is not stable when train-
ing, and the gradient descent algorithm does not eas- IDF stands for inverse data frequency and is used to calcu-
ily converge to the optimal solution. Therefore, in late the weights of rare words in all documents in the corpus.
this paper, the data are normalized. When normali- When T f measures word frequency, the weight of words such
zation is performed, the size of all values is scaled
as “of” or “and” must be reduced since they occur frequently in
to a fairly low value. The two most common
all documents, i.e., the document inversion frequency compo-
methods of data normalization are min–max nor-
nent. If a word appears frequently in each document, the less
malization and z-score normalization.
likely it is to be used as a keyword for a given document.
In order to improve the training efficiency of the samples The inverse document frequency of a word in a set of docu-
and the generalizability of the training results, this paper ments means how common or rare the word is in the entire
uses min–max normalization to normalize the input feature set of documents. Thus, if the word is very common and
sequences by which the data inputs are mapped to a prede- occurs in many documents, the number will be close to 0. Oth-
fined range [0, 1] or [-1, 1]. The min–max method normal- erwise, it will be close to 1. Designed to retain distinctive words
izes the value of attribute A of the dataset according to the as markers, words that occur rarely in the corpus have a high
minimum and maximum values of the dataset. It converts IDF score. This metric can be calculated by dividing the total
the value a of attribute A to a in the range [low, high] by number of documents by the number of documents contain-
the following calculation: ing the word and then calculating the logarithm. It is given
by the following formula:
high − low !
a= n
+ low: ð1Þ
max A − min A IDF,n = log 〠 wi : ð4Þ
i=1
In particular, when low is set to 0 and high is set to 1, it is
easy to see that a = 0 when a = min and a = 1 when a = max. Combining these two, IDF,n extracts high-frequency words
This means that the minimum value in A maps to 0 and the from the text as candidate keywords and the text inverse fre-
maximum value in A maps to 1. Thus, the entire range of A quency IDF weights the TF-IDF scores of the words in the doc-
values from the minimum to the maximum value maps uments in the corpus w. Multiplying these two numbers will
between 0 and 1. give the TF-IDF scores of the words in the documents. The
The data is then subjected to word separation process- higher the score, the more relevant the word is in that partic-
ing. Since Chinese word separation techniques are relatively ular document, i.e., the one with the higher weight is taken as
mature and are not the focus of this thesis, the existing jieba the keyword:
word separation technique, which is suitable for large-scale !
text separation scenarios, is used here. The TF-IDF method n
is a common word weighting measure that indicates the wi, j = TFi, j + log 〠 wi , ð5Þ
importance of a particular word in the whole document or i=0
6 Wireless Communications and Mobile Computing

Data input Stock historical data

Data flowing Opening price


Waiting list

Price1simulate Price2simulate Price3simulate Price1simulate Price2simulate Price3simulate

Data produce

Highest price
Price1close Price2close Price3close Price1close Price2close Price3close

Data output Encoder-decoder Guide price

Figure 2: Deep recursive process.

where TFi, j denotes the number of occurrences of i in j texts, Hidden layer Dropout layer
Input layer
dfi denotes the number of corpora containing i words, and
Output layer
N denotes the number of all corpora. Regarding the embed- 1 1
ding layer, this model maps each word in a set K of size n to 1
a corresponding word vector iw by using the Word2Vec 2 0 1
method. For the set of vectors w, the information is extracted
0
using a fully connected neural network:
3 1 2

 + Rn ,
Word2 Vec = aw ð6Þ 1
4 0
where a is the weight size of each word vector, a belongs to Rn , Training time
b is the weight size of the bias vector b, b belongs to Rn , and
New is the news information extraction result vector.
Figure 3: Schematic of adding dropout neural network.
In order to correspond the stock names to the news data,
each stock name is transformed into the corresponding
stock vector S by embedding operation. By the Word2Vec by training the neural network, as shown in Figure 2. It also
method, it is transformed into the corresponding word vec- takes into account the effect of some randomness to avoid
tor cv . The generated word vector is fed into CLSTM, and the occurrence of falling into a local minimum that leads
the stock name Name is used as Topic to process the stock to a global minimum not being reached.
news keyword Keys; in particular, the output matrix of The type of optimizer used optimizes the efficiency with
CLSTM is used here as output to obtain the corresponding which the algorithm converges to a minimum. The model is
implied layer matrix information ch : optimized with the Adam optimizer, which combines the
advantages of both ADAgrad and RMSprop optimizers.
ch = clastmðname, keysÞ: ð7Þ The reason behind ADAgrad is that infrequently used
parameters must have a large learning rate, while frequently
2.1.3. Deep Recursive Process. The input layer of the model used parameters must have a small learning rate. The sto-
includes three major parts: stock historical data information, chastic gradient descent update of ADAgrad becomes
news information, and investor sentiment. The main part of
the model firstly uses Bi LSTM to process the features in βt+1,i = βt,i − η, ð8Þ
terms of data information separately, secondly uses news
data as the contextual information input of CLSTM, and
ηt,i = ∇J i, j K: ð9Þ
introduces the attention mechanism to give different atten-
tion to the news text sequences to ensure that the model cap- The learning rate is derived by calculating the historical
tures information from the news that is more relevant to the gradient of each parameter. Thus,
stock price movement. Secondly, a plain Bayesian-based
sentiment classifier is used to analyze the data from the
θ
forum, and the sentiment data obtained from it is combined βt+1 − βt = pffiffiffiffiffiffiffiffiffiffiffi ht , ð10Þ
with other parts of the data to serve as training data for the Q+χ
long- and short-term memory time series learning model.
Finally, a multilayer fully connected neural network is used where H is the sum-of-squares matrix of the historical
to process all the data. Satisfactory results can be obtained gradients. The problem with this optimization is that as
Wireless Communications and Mobile Computing 7

The data clearly Running algorithm

Building the database Third-party data


Information processing
and analysis
Crawler collection node1 Crawler collection node1 Crawler collection node1

Collection Collection Collection

Node information Node information Node information

Send Send Send

Crawler server Crawler server Crawler server

Figure 4: Web crawler flow.

the number of iterations increases, the learning rate begins sponding to each URL by determining the queue of URLs to
to rapidly decrease and disappear. RMSprop slows down be crawled, parse the web page content, and store the corre-
the decline in the learning rate by using a certain number sponding data. In order to efficiently and accurately obtain
of historical gradients. Updated to comment data, the crawler should start from the entry
URL of the forum. Web crawlers are classified into several
θ categories according to the system structure and technical
βt+1 − βt = qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
pffiffiffiffiffiffiffiffiffiffiffiffiffi ht , ð11Þ mode, such as general-purpose web, focused web crawlers,
Q ½t 2 − r  incremental web crawlers, and deep web crawlers. In this
paper, we use a general-purpose web crawler to crawl the
pffiffiffiffiffiffiffiffiffiffiffiffiffi pffiffi stock forum comment data. It is very expansive, crawling
Q ½t 2 − r = Q t + 0:1t 2 : ð12Þ objects involving URLs all the way to the entire Web, collect-
ing data for web search engines and large web service pro-
After using two hidden layer neural networks in this viders. Due to the large scope and number of crawls, high
model, as shown in Figure 3, two hidden layer standard neu- requirements for crawl speed and storage space, and low
ral networks are used, and the dropout method is adopted to requirements for the order of crawled pages, usually web
randomly discard some neurons, and the neurons marked crawlers work in parallel. Therefore, the application value
with a fork in the right figure are randomly inactivated neu- is strong. The specific flow chart of the generic web crawler
rons. In practice, the dropout value is set too low, and the operation is shown in Figure 4.
effect can be ignored; if the dropout value is set too high, it
may lead to underfitting results. Therefore, the dropout is 2.2.2. Evaluation Based on Accuracy and Yield. The training
set to 20% in this model. performed on the above data is used to predict the stock
2.2. Experiments and Result Analysis trend of that day. After trying methods such as fitting stock
movements and classifying stock movements, experiments
2.2.1. Experimental Data. Stock forums provide a platform were conducted using the classification method, which is a
for investors to discuss online. Stock forum sites allow users dichotomous classification (up/down) of stock movements
to request and exchange information therein. In addition, to make predictions. The experiments show that reducing
the stock forum site also allows users to view forum posts the problem to a classification problem is more accurate
and post messages therein. When posting a message, users than fitting stock movements. To evaluate the impact of
can create a new topic or post in an existing topic. Stock financial news on stock prices over time, we set different
forums consist of user-generated content (UGC), and to time intervals (i.e., 1, 2, 5, 7, and 10 days) for the prediction
get investor sentiment from a forum site, its content should experiments. In the case of a one-day interval, it means that
be downloaded first. Use web crawler technology to crawl news affects stock prices within 24 hours. Similarly, the
content and obtain data. A web crawler, an important part impact of news varies at other time intervals. The results
of current search engines, is a computer program or auto- are shown in Figure 5, where the accuracy obtained by the
mated script that automatically crawls and downloads web prediction model proposed in this paper decreases with
information according to certain rules. In a narrow sense, time, with the highest accuracy of the experimental results
it is usually considered a software program that traverses in the first 24 hours and decreases with time. This also illus-
the information space of the World Wide Web based on trates the impact of financial news and the rapid reflection of
web hyperlinks and web document retrieval methods (e.g., the stock market.
depth-first or breadth-first) using the standard HTTP proto- The experiment uses the above stock selection strategy to
col. Web crawlers obtain the content of the web pages corre- backtest the test set by selecting one hundred consecutive
8 Wireless Communications and Mobile Computing

50 Model rate of return Normal daily return


1.2 1.2
40 1.0
Accuracy (%)

Rate of return (%)

Rate of return (%)


1.0
30 0.8
20 0.8
0.6
10 0.6 0.4

0 0.2
100 150 200 0.4
0.0
Days 0 10 20 30 40 50 0 10 20 30 40 50

Figure 5: Accuracy vs. number of days line graph. Days Days

Figure 6: Daily yield.


days of data and removing the cases where the data on the
day of backtest is less than 100 shares and conducting the
test using the return as a measure, the results of which are
40 10
shown in Figure 6. Daily return represents the relationship Model rate of return Normal daily return
between the return available for each investment and the
8
number of days, where the horizontal coordinate indicates 30
Rate of return (%)

Rate of return (%)


the number of days and the vertical coordinate indicates
the return, and the points in the figure are the return for 6
each investment with the dashed 0 coordinate, where the 20
number of days with a return greater than 0 is Gdays. The 4
results indicate that the actual probability of a daily return 10
greater than 0 is close to 0.7041. 2
Figure 7 shows the return versus time assuming that the
investment strategy given by the model is adopted every day, 0 0
0 10 20 30 40 50 0 10 20 30 40 50
where the horizontal coordinates indicate the number of
days and the vertical coordinates indicate the return Days Days
compared to day 0, where the coordinates of the highest
point are (98, 0.2849), i.e., if the stock selection is done with Figure 7: Total return.
this model, then at 98 days, a cumulative return equal to
28.49% of the principal can be obtained.
The number of input features of the network model is along with the corresponding stock name information as
adjusted, and the same training data and test data are experi- input, and according to its news release time, 4:00 p.m.
mented with in a single LSTM model, a news-based LSTM was used as the dividing line, with news released before
model, and a news- and investor sentiment-based LSTM 4:00 p.m. counted as financial news of the day and news
model, and the results are shown in Figure 8. In the training released after 4:00 p.m. counted as the next trading day.
process of the model, the accuracy of stock trend prediction Also, obtaining stock forum data relies on web crawlers. A
by LSTM with a different number of layers is compared by plain Bayesian classifier trained using the method described
continuously modifying the LSTM layers. However, the in Section 3 is used to obtain investor sentiment for predict-
number of layers is positively correlated with the computa- ing stock movements. After the above experiments, we veri-
tional redundancy and consumption, which is not conducive fied the conjecture that when the attention mechanism of the
to the efficiency of the overall model. Therefore, with the hybrid neural network assigns a weight to the K-line pattern
proper number of network layers, increasing the number of a sample that is significantly higher than the overall mean
of network layers is costly and the improvement of predic- of the sample, it is highly likely that the K-line pattern
tion accuracy is not significant. Therefore, a two-layer LSTM carries a stronger predictive power than the general K-line
network model is used to predict stock movements. pattern, and when the pattern appears, there is a high prob-
In this paper, stocks and their corresponding news are ability that the later market will appear to be consistent with
extracted to obtain information about possible stock trends the history. It is also true that K-line patterns are an intuitive
from the news, such as national policy support that may lead analysis tool, and when they show a strong trading signal,
to a rise in the stock. Since each news item is too long, thus, human researchers will also focus on the signal to make pre-
TF-IDF, a common weighting technique used for informa- dictions about the future of the market. Therefore, compared
tion retrieval and data mining, is used to process each news to other deep learning models, the hybrid neural network
item and extract the news-related keywords as input. In model proposed in this paper guarantees the predictive effect
order to align with numerical data, historical data from and performs the predictive inference work in a way that
November 5, 2018, to November 8, 2019, were collected, humans can intuitively feel and understand. In addition,
Wireless Communications and Mobile Computing 9

12 38

Out of control ratio (%)


11 36
10 34

Accuracy (%)
9 32
8 30
7 28
6 26
5 24
0 2 4 6 8 10 22 24 26 28 30 32

Data input Accuracy (%)

Single recursion LSTM


LSTM This work
Recursion
2-layer recursion
This work

Figure 8: Comparison of the accuracy of different prediction models.

using the powerful computing power and storage capacity of system, thus reducing the possible investment risks to a certain
computers, we can use the model to mine more K-line pat- extent and obtaining high and stable investment returns.
terns that may have strong predictive power and continu-
ously expand the knowledge base of human researchers.
Data Availability
3. Conclusion The data used to support the findings of this study are
This paper focuses on the problem of stock trend prediction included within the article.
based on deep learning. Due to the many factors affecting
the stock movement, the number of stocks and the huge
trading volume make this research challenging and difficult. Conflicts of Interest
In this paper, we consider multiple influencing factors at the All the authors do not have any possible conflicts of interest.
same time, combining three aspects: historical stock trading
data, news information, and investor sentiment index, and
use an improved LSTM to model the prediction. We also References
construct a stock trend prediction system and apply the
improved model to make stock recommendation and stock [1] M. Wen, P. Li, L. Zhang, and Y. Chen, “Stock market trend
trend prediction for investors. It has high operability and prediction using high-order information of time series,” IEEE
practical value. In this paper, we classify the sentiment of Access, vol. 7, pp. 28299–28308, 2019.
stock forum remarks and calculate to obtain the investor [2] W. Chen, M. Jiang, W.-G. Zhang, and Z. Chen, “A novel graph
sentiment index. Based on the sentiment dictionary, a stock convolutional feature based convolutional neural network for
market sentiment dictionary is formed by adding stock mar- stock trend prediction,” Information Sciences, vol. 556,
ket specialized vocabulary. A sentiment classification model pp. 67–94, 2021.
is constructed on the basis of the plain Bayesian algorithm to [3] M. Z. Asghar, F. Rahman, F. M. Kundi, and S. Ahmad, “Devel-
classify the sentiment of stock forum remarks. Experiments opment of stock market trend prediction system using multiple
show that the classification effect is better using this model, regression,” Computational and Mathematical Organization
Theory, vol. 25, no. 3, pp. 271–301, 2019.
and the investor sentiment is obtained more accurately,
and the accuracy rate can reach 85%, which lays the founda- [4] H. Ni, S. Wang, and P. Cheng, “A hybrid approach for stock
trend prediction based on tweets embedding and historical
tion for the establishment of the whole stock trend predic-
prices,” World Wide Web, vol. 24, no. 3, pp. 849–868, 2021.
tion model. In this paper, we design and implement a deep
[5] F. Zhou, H.-m. Zhou, Z. Yang, and L. Yang, “EMD2FNN: a
neural network-based stock trend prediction system and strategy combining empirical mode decomposition and factor-
upload the trained prediction model to the stock prediction ization machine based neural network for stock market trend
module. Through the requirement analysis of the stock trend prediction,” Expert Systems with Applications, vol. 115,
prediction system and the design of each functional module, pp. 136–151, 2019.
the whole stock trend prediction system is completed after [6] M. Zhao, A. Jha, Q. Liu et al., “Faster mean-shift: GPU-
development and testing. It enables investors to make rela- accelerated clustering for cosine embedding-based cell
tively correct investment decisions based on the stock rec- segmentation and tracking,” Medical Image Analysis, vol. 71,
ommendation results and stock prediction results of the article 102048, 2021.
10 Wireless Communications and Mobile Computing

[7] A. Moghar and M. Hamiche, “Stock market prediction using [23] J. P. Verma, S. Tanwar, S. Garg, I. Gandhi, and N. H. Bachani,
LSTM recurrent neural network,” Procedia Computer Science, “Evaluation of pattern based customized approach for stock
vol. 170, pp. 1168–1173, 2020. market trend prediction with big data and machine learning
[8] M. Zhao, Q. Liu, A. Jha et al., “VoxelEmbed: 3D instance seg- techniques,” International Journal of Business, vol. 6, no. 3,
mentation and tracking with voxel embedding based deep pp. 1–15, 2019.
learning,” 2021, https://arxiv.org/abs/2106.11480/. [24] Y. Chen, W. Lin, and J. Z. Wang, “A dual-attention-based
[9] J. Zhang, S. Cui, Y. Xu, Q. Li, and T. Li, “A novel data-driven stock price trend prediction model with dual features,” IEEE
stock price trend prediction system,” Expert Systems with Access, vol. 7, pp. 148047–148058, 2019.
Applications, vol. 97, pp. 60–69, 2018. [25] M. Y. Chen, C.-H. Liao, and R.-P. Hsieh, “Modeling public
[10] A. Thakkar and K. Chaudhari, “CREST: cross-reference to mood and emotion: stock market trend prediction with antic-
exchange-based stock trend prediction using long short-term ipatory computing approach,” Computers in Human Behavior,
memory,” Procedia Computer Science, vol. 167, pp. 616–625, vol. 101, pp. 402–408, 2019.
2020. [26] M. Ananthi and K. Vijayakumar, “Stock market analysis using
[11] W. Sun, P. Zhang, Z. Wang, and D. Li, “Prediction of cardio- candlestick regression and market trend prediction (CKRM),”
vascular diseases based on machine learning,” ASP Transac- Journal of Ambient Intelligence and Humanized Computing,
tions on Internet of Things, vol. 1, no. 1, pp. 30–35, 2021. vol. 12, no. 5, pp. 4819–4826, 2021.
[12] M. Nabipour, P. Nayyeri, H. Jabani, S. Shahab, and A. Mosavi, [27] S.-F. Huang, M. Guo, and M.-R. Chen, “Stock market trend
“Predicting stock market trends using machine learning and prediction using a functional time series approach,” Quantita-
deep learning algorithms via continuous and binary data; a tive Finance, vol. 20, no. 1, pp. 69–79, 2020.
comparative analysis,” IEEE Access, vol. 8, pp. 150199– [28] L. Huang, G. Xie, W. Zhao, Y. Gu, and Y. Huang, “Regional
150212, 2020. logistics demand forecasting: a BP neural network approach,”
[13] M. Vijh, D. Chandola, V. A. Tikkiwal, and A. Kumar, “Stock Complex & Intelligent Systems, pp. 1–16, 2021.
closing price prediction using machine learning techniques,” [29] Y. Fang, “Feature selection, deep neural network and trend
Procedia Computer Science, vol. 167, pp. 599–606, 2020. prediction,” Journal of Shanghai Jiaotong University (Science),
[14] S. Paul and S. Vishnoi, “Real-time stock trend prediction via vol. 23, no. 2, pp. 297–307, 2018.
sentiment analysis of news article,” Computer Engineering [30] C.-s. Lim, “Fair performance evaluation method for stock
and Intelligent Systems, vol. 9, no. 7, pp. 21–28, 2018. trend prediction models,” The Journal of the Korea Contents
[15] T. Kim and H. Y. Kim, “Forecasting stock prices with a feature Association, vol. 20, no. 10, pp. 702–714, 2020.
fusion LSTM-CNN model using different representations of [31] L. Lei, “Wavelet neural network prediction method of stock
the same data,” PLoS One, vol. 14, no. 2, article e0212320, price trend based on rough set attribute reduction,” Applied
2019. Soft Computing, vol. 62, pp. 923–932, 2018.
[16] W. Long, L. Song, and Y. Tian, “A new graphic kernel method [32] C. Patel, “Impact of the financial result on stock trend predic-
of stock price trend prediction based on financial news seman- tion using SVM and M-score,” International Journal for
tic and structural similarity,” Expert Systems with Applications, Advance Research and Development, vol. 3, no. 5, pp. 6–11,
vol. 118, pp. 411–424, 2019. 2018.
[17] M. A. I. Sunny, M. M. S. Maswood, and A. G. Alharbi, “Deep [33] A. Thakkar and K. Chaudhari, “A comprehensive survey on
learning-based stock price prediction using LSTM and bi- portfolio optimization, stock price and trend prediction using
directional LSTM model,” in 2020 2nd Novel Intelligent and particle swarm optimization,” Archives of Computational
Leading Emerging Sciences Conference (NILES), pp. 87–92, Methods in Engineering, vol. 28, no. 4, pp. 2133–2164, 2021.
Cairo, Egypt, 2020, October. [34] C.-s. Lim, “A study on stock trend determination in stock
[18] H. S. Ibrahim, A. Z. Khan, S. Attia, and Y. Serag, “Classification trend prediction,” Journal of the Korean Society of Computer
of heritage residential building stock and defining sustainable and Information, vol. 25, no. 12, pp. 35–44, 2020.
retrofitting scenarios in Khedivial Cairo,” Sustainability, [35] V. Gupta and M. Ahmad, “Stock price trend prediction with
vol. 13, no. 2, p. 880, 2021. long short-term memory neural networks,” International
[19] T. Colliri and L. Zhao, “Stock market trend detection and auto- Journal of Computational Intelligence Studies, vol. 8, no. 4,
matic decision-making through a network-based classification pp. 289–298, 2019.
model,” Natural computing, pp. 1–14, 2021.
[20] Y. Gu, A. Chen, X. Zhang, C. Fan, K. Li, and J. Shen, “Deep
learning based cell classification in imaging flow cytometer,”
ASP Transactions on Pattern Recognition and Intelligent Sys-
tems, vol. 1, no. 2, pp. 18–27, 2021.
[21] Y. Yan and D. Yang, “A stock trend forecast algorithm based
on deep neural networks,” Scientific Programming, vol. 2021,
Article ID 7510641, 7 pages, 2021.
[22] Z. Wang, P. Zhang, W. Sun, and D. Li, “Application of data
dimension reduction method in high-dimensional data based
on single-cell 3D genomic contact data,” ASP Transactions
on Computers, vol. 1, no. 2, pp. 1–6, 2021.

You might also like