Sunteți pe pagina 1din 5

Short-term prediction of stock market price based on GA

optimization LSTM neurons


Moule Lin Changxi Chen*
Tianjin Agriculture University Tianjin Agriculture University
No.22 Tianjin Jing Road, Xiqing District, Tianjin No.22 Tianjin Jing Road, Xiqing District, Tianjin
Agricultural University Agricultural University
+8618322760891 +8615302138777
moulelin@163.com changxichen@163.com

ABSTRACT this theory is also accepted by the scientific community.


Long-Short Term Memory Network stands out from the In 2017, David M. Q. Nelson [2] used the LSTM recurrent neural
financial sector due to its long-term memory predictability, network to predict the accuracy of a specific stock's price
however, the speed of subsequent operations is extremely slow, movement over the next 15 minutes to 55.9%, which is currently a
and the timeliness of the inability to meet market changes has small breakthrough in stock forecasting. It is proposed that the
been criticized. In this paper. Aiming at the shortcomings of the GA-optimized LSTM neurons overcome the LSTM and that due
slow running of three gates in each neuron of LSTM in back to the 1backward propagation, the neuron trinary needs to perform
propagation, we propose to use GA to optimize the internal frequent weight updates and the cell state updates depend on data
weights of LSTM neurons to optimize the defect. In this from a previous point in time, which causes the network to fail
experiment, GA optimization could not change the accuracy of the parallel computing and the network is running slowly.
model, but it achieved better results than the original LSTM in
terms of speed, and satisfied the demand of the future business 2. Related work
field for rapid response to market changes in terms of timeliness. 2.1 Long-Short Term Memory Network
The earliest LSTM was proposed by Hochreiter & Schmidhuber
CCS Concepts [3] (1997) and was recently improved and promoted by Alex
• Mathematics of computing → Mathematical analysis → Grave[4]. In many problems, LSTM has achieved considerable
Mathematical optimization → Discrete optimization → success and has been widely used.
Optimization with randomized search heuristics → Compared to the traditional BP neural network[5] theoretically
Evolutionary algorithms not suitable for time series prediction [6], RNN-LSTM network
with time-series concept can obviously bring better results.
Keywords
In principle, RNNs can use their feedback connections to store the
Keywords :LSTM; GA; Stock prediction; Timeliness; representation of the most recent input event in an activated form
[7], while LSTM control the access of information through cells
1. Introduction state. The LSTM unit is composed of input gates, cell states,
In recent years, the stock market has always been the focus of forget gates, output gates, active layer and dot multiplication
attention of researchers. Researchers have investigated the operations [8], as follows:
characteristics, defects, and reform measures of the stock market
Input gate: Input gate is derived from input , through the
from the micro and macro perspectives. However, due to the
activation function
volatility of the stock market, there are random and excessive
Independence and other factors, its research has not been able to It  (Wi  [ht 1 , xt ]  bi )
achieve major breakthroughs. In the stock market, due to the
inherent complexity of the stock, its high degree of non-linearity, ·The tanh layer generates a new vector and will be added
and its excessive variability and timeliness of forecasting, and it is to the network
more important that B.G. Malkiel mentioned in the random walk
hypothesis [1] that the stock price is independent of its historical Ht  Ot * tanh(Ct )
change. Therefore, looking back from history, the stock prediction
task is very arduous. Fortunately, A. Lo and A. MacKinla ·Sigmoid layer generates numbers between 0 and 1
proposed that the stock price can be predicted to some extent, and
1
Permission to make digital or hard copies of all or part of this work for S ( x) 
personal or classroom use is granted without fee provided that copies are
not made or distributed for profit or commercial advantage and that
1  ex
copies bear this notice and the full citation on the first page. Copyrights ·Cell state affects final output
for components of this work owned by others than ACM must be
honored. Abstracting with credit is permitted. To copy otherwise, or
republish, to post on servers or to redistribute to lists, requires prior
C%t  (Wc  [ht 1 , xt ]  bc )
specific permission and/or a fee. Request permissions from
Permissions@acm.org. 1
ICDLT '18, June 27–29, 2018, Chongqing, China
Facility agriculture precision control technology and intelligent
© 2018 Association for Computing Machinery. equipment innovation team project
ACM ISBN 978-1-4503-6473-7/18/06…$15.00
https://doi.org/10.1145/3234804.3234818

66
More importantly, LSTM reduces the computation time of weight complexity of each time step as O(1).
the network by guaranteeing the computational complexity and
idealized manner, and the most important reorganization is the
cross-exchange of biologically mature germ cell staining, that is,
introduction of cross breeding. From the initial population P(t),
the concept can be selected heuristically or randomly [14]
between the parent and the parent, as shown in the following
figure 3:

Figure 1. LSTM Cell.


The LSTM network also uses backpropagation (BP) for weight
updates, but the difference is that since the LSTM processes data
with time series, the error feedback updates all the time errors, as
shown in Figure 2 below.
Figure 3.Cross way.
After the crossover is completed, more excellent individuals will
be mutated by individual selective mutation. The experiment set a
constant mutation rate.

2.3 GA Optimizes BP Neural Network


Figure 2.LSTM Back Propagation Mechanism.
Connection Weights
From the above figure, we can find that the error of is determined
by and. That is, the error value of each neuron is determined by GA optimization has two aspects for the optimization of neural
the linear or nonlinear relationship between the error at the current networks. One is the fixed neural network topology (Topology),
time t and the error after t time. which optimizes the link weights. Maintain network topology, use
LSTM can be used for price data to predict price changes [9], but evolutionary algorithms to replace the original back-propagation
apparently, LSTM networks also have certain flaws. For example, to update link weights (in fact, there is no back propagation
the disadvantages of local extremum or low efficiency due to mechanism for biological neural networks). By continuously
frequent update of neuron weights. We tried to use some experimenting with reproduction and mutation, the direct link
algorithms to combine these with LSTM to fix these shortcomings. weights of neurons are corrected, the prediction results are more
And in machine learning, the genetic algorithm [10] can accurate, and poor quality offspring are eliminated. This
effectively help the network out of local extremum problems. In experiment is based on this optimization concept, and further
this paper, we combine genetic algorithm with LSTM to update optimizes the ideas for the optimization of the link weights of the
the neural network to overcome the slow problem of LSTM. internal three doors of LSTM neurons. Another evolutionary
approach is to optimize the topology of
2.2Genetic Algorithm the network. Although no topology
optimization was discussed in this
Genetic algorithm (GA) is a commonly used solving method, experiment, this is one of the directions
which is usually used to optimize the problems in engineering, of neural network optimization.
computer science, economic management and other fields. In the Since this experiment is a further
process of evolution, organisms have the concept of survival of improvement based on the GA
the fittest. Unlike evolutionary algorithms such as ant colony optimization of BP neural network
algorithm [11] and simulated annealing [12], GA selects the best connection weights, we also performed
species for biological reproduction by selecting, crossing, and GA optimization of simple BP network
mutating individuals. It is the evolution of simulated organisms to connection weights. Figure 4 is a
optimize certain models [13]. schematic diagram of network
The related work of this article mainly introduces reproduction connections evolved in one experiment.
and mutation methods. In Figure 4. If the connection is a
In general, GA is an iterative process to maintain the constant size solid line, it indicates that the link is
of individuals in the population. In the original population, connectable. If it is a dashed line, Figure 4. GA Optimized
individuals with similar prediction results and real results are such as input->output, it indicates BP
retained, and unsuitable individuals are eliminated. In relation to that the link is disabled. The red line
the performance of other individuals, individuals are selected in represents weight <= 0, and the green line represents weight > 0.
proportion to their performance on the final result. In order to The width of the line is related to the size of the weight.
search for more excellent individuals in the search space, some Through the implementation of the model, the feasibility of
changes introduce new genetic recombination operators in an optimizing the weight of the network connection by GA is proved,

67
and the basic model of the LSTM neuron optimized by GA is
provided. Parameter Ranges

3. Model fusion method LSTM hidden layers [1,3]


The key to achieving GA-optimized neurons is the encoding of
DNA. In this experiment, the internal weights and connections of Single-layer neurons [100,300]
neurons will be used as bases in DNA to encode a single DNA.
Genetic algorithm iteration [10,100]
3.1 Model specific method number

3.1.1 DNA coding way 4.2 Parameter and model results


For the updated weight of the LSTM neuron [15], the weight of Optimizing the update of weights inside neurons through GA does
the oblivion gate, the weight of the input gate, the weight of the not change the accuracy of the model. Based on this concept, we
output gate, and the weight of the calculation unit state are can use the original LSTM to determine the optimal number of
respectively encoded. Among them, due to the existence of partial hidden layers and neurons. After determining the number of
interconnections between the LSTM neurons, we then add the neurons and number of hidden layers [20], we can determine the
connection state value, which is represented by the binary 1 optimal number of iterations by adjusting the number of iterations
connection. 0 indicates no connection, and the position represents of the genetic algorithm.
the number of neurons. For example=1010 indicates that the first a): Determine some parameters through the original LSTM
nerve and the third neuron are connected in two directions, and
By recovering the code from David M. Q. Nelson's
the second and third neurons have a one-way connection.
experiment, we have the following figure 5 data:
Individual coding is shown in Table 1 below:
Table 1.Coding method.

Forget Input Output Unit Connection


weigh weight weight status Status

In experiments, the weight of neurons was set in a reasonable


range [16], reducing the time required for GA.

3.1.2 Fitness function


The sum of the squared error [17] between the actual output value
and the expected output value that is chosen in this paper is the
same as the general network. The formula is as follows
ml 1 Figure 5. Different LSTM parameter accuracy (The X-axis is
1
Ep    yk  tk 
2

2 the number of neurons per layer, In each group (the three


k 1
boxes are a group), the first box indicates that the entire
Where m is the number of learning samples, is the actual output
value of the network, is the expected output value of the network, network has one hidden layer, the second box means two
and is the error between the actual output value of the network
hidden layers, and the third box means three hidden layers.)
and the expected output value
A small sum of squared errors indicates that the network From the experimental data analysis, when the number of neurons
performance is good, and individuals with low fitness are is greater than 200, the accuracy begins to decline. Therefore, we
eliminated and individuals [18] with high fitness are reproduced. chose the most reasonable hidden layer for the next step, with 150
neurons per layer.
4. Hyper-parameter determination By determining the number of neurons and the number of hidden
4.1 Model parameter range value selection layers, we use GA for updating the neurons and get the optimal
breeding algebra by traversal attempts, as shown in Figure 6
In this experiment, we only studied how to optimize the process of below:
updating the weights of neurons through GA to reduce the running
time of the network model, so that it can meet the needs of the
stock market [19] or other fields that require rapid response to the
market. Therefore, the number of neurons, the number of hidden
layers, and the number of iterations of the genetic algorithm need
to be set in the following table 2:

Table 2.Range of parameters.

68
5. Summary of issues
This experiment is based on the study of GA's optimization of
LSTM neurons as a core goal. Based on the model proposed by
Jian Yi [21], the model is further modified. Through a series of
experimental procedures, it is proved that the complex calculation
of GA-optimized LSTM internal neurons can reduce the running
time of the model to a certain degree, which has great application
in the field of financial forecasting and other commercial fields.
As shown in Table 3 and Figure 6 above, the feasibility of GA
optimization of LSTM neurons was compared with that of David
M. Q. Nelson.
There are differences in the operating model time for different
hardware devices. The main processing parameters of this
experimental environment are: Intel(R) Core(TM) i7 8700K CPU
@2.40GHz, programming language is Python.
Figure 6.Different propagation algebraic accuracy. This paper proposes a GA optimization method for LSTM
neurons. By comparing the running time of predecessor models, it
As the picture shows. We obtained 22 iterations and 23 GA is possible to overcome the shortcomings of slow operation of
optimization neurons to achieve the highest accuracy and minimal LSTM to a certain extent by optimizing the internal weight of
difference from the original LSTM. neurons through GA update.
b): Study the effect of GA on neurons speed In addition, this article does not discuss the generalization ability
Based on the given parameter range and the data obtained in of the network and other parameters of the network at the same
experiment a, we selected a set of parameters with the highest time. The research purpose is too single. However, for the short-
accuracy score to test the effect of GA on the neuron operating term prediction of financial markets, the importance of research
speed. The parameters are shown in the following table 3. on the timeliness and advancing of the model is much higher than
that of the generalized network model.
Table 3.Determined parameter list.

Parameter Value
6. REFERENCES
[1] B. G. Malkiel, A Random Walk Down Wall Street. Norton
LSTM hidden layers 2 [M], 332.6.dc21 [S.l], 1973
[2] Nelson D M Q, Pereira A C M, Oliveira R A D. Stock
Single-layer neurons 150
market's price movement prediction with LSTM neural
networks[C]//International Joint Conference on Neural
Genetic algorithm iteration 22 Networks. IEEE, 2017:1419-1426.
number
[3] S. Hochreiter and J. Schmidhuber. Long short-term memory
Network iterations 100 [J] Neural computation, vol. 9, no. 8, pp. 1735–1780, 1997.
[4] Graves A. Supervised Sequence Labelling with Recurrent
Pass the parameters that have already been confirmed into
Neural Networks[J]. Studies in Computational Intelligence,
two networks, run the same data, in order to guarantee the
2008, 385.
accuracy of the experiment, we carry on three times of
experiments, get the running time of the model as shown in Figure [5] Akerkar, Rajendra, Sajja, et al. Intelligent Techniques for
7 Data Science[M]. Springer International Publishing, 2016..
[6] SUN Rui-qi. Research on Forecast Model of Stock Market
Price Trend Based on LSTM Neural Network[D]. Capital
University of Economics and Business, 2015
[7] S. Hochreiter and J. Schmidhuber. Long short-term memory
[J] Neural computation, vol. 9, no. 8, pp. 1735–1780, 1997.
[8] Ren Zhihui, Xu Haoyu, Feng Songlin, et al. Chinese
segmentation method based on LSTM network for sequence
labeling[J]. Journal of Computer Applications, 2017, 34(5):
1321-1324.
[9] Sreelekshmy.Selvin, Vinayakumar R, et al. Stock price
prediction using LSTM, RNN and CNN-sliding window
Figure 7.Running time comparison chart. model[J], Centre for Computational Engineering and
As can be seen from the above figure, the LSTM model based on Networking, 2017 IEEE.
GA-optimized neurons achieves better results in operating [10] Lin Y F, Huang C F, Tseng V S. A Novel Methodology for
efficiency than the traditional LSTM. Stock Investment using High Utility Episode Mining and
Genetic algorithm[J]. Applied Soft Computing, 2017.

69
[11] Aguilar-Rivera R, Valenzuela-Rendón M, Rodríguez-Ortiz J [17] Cuprak T, Wage K E. Efficient Doppler Compensated
J. Genetic algorithms and Darwinian approaches in financial Reiterative Minimum Mean Squared Error Processing[J].
applications: A survey[J]. Expert Systems with Applications, IEEE Transactions on Aerospace & Electronic Systems,
2015, 42(21):7684-7697. 2017, PP(99):1-1.
[12] Kirkpatrick S, Jr G C, Vecchi M P. Optimization by [18] Ruiz G R, Bandera C F, Temes G A, et al. Genetic algorithm
simulated annealing [J]. Science, 1983, 220(4598):671-680. for building envelope calibration[J]. Applied Energy, 2016,
[13] Zhao Y, Zhao H, Huo X, et al. Angular Rate Sensing with 168:691-705.
GyroWheel Using Genetic Algorithm Optimized Neural [19] Zhang Zhihua, Xu Yuanhong. Application of GRNN Neural
Networks: [J]. Sensors, 2017, 17(7):1692. Network Based on Particle Swarm Optimization in Stock
[14] Grefenstette J J. Optimization of Control Parameters for Forecasting[J].Journal of Mathematical Learning and
Genetic Algorithms [J]. Systems Man & Cybernetics IEEE Research,2017(14):13.
Transactions on, 1986, 16(1):122-128. [20] Hu Zhaoju, Liang Ning. Special subject sentiment analysis
[15] Liang Jun, Chai Yumei, Yuan Huibin, et al. Sentiment based on deep attention LSTM [J/OL]. Journal of Computer
Analysis Based on Polarity Transfer and LSTM Recursive Applications, 2019(05):1-3[2018-03-23]
Networks [J]. Chinese Journal of Information, 2015, [21] Jian Yi, Lu Wei, Pu Yongji, Li Kunhe. Face Recognition
29(5):152-159. Algorithm Based on Genetic Optimization and GRNN
Neural Network[J].Ordnance Equipment
[16] WU Di , Y Nie , J Huang. Parametric Dropout in
Engineering,2018,39(02):131-135.
RNN[J].Advanced Science and Industry Research
Center.2017

70

S-ar putea să vă placă și