Singular, Hybrid Sequential, and Parallel LSTM and
GRU-based Arrangements for Stock Prices
Prediction
Eric Savero Hermawan Gabriel Asael Tarigan, Abba Suganda Girsang
Computer Science Department Computer Science Department, Computer Science Department,
Binus Graduate Program BINUS Graduate Program, BINUS Graduate Program,
Master of Computer Science Program Master of Computer Science Program, Master of Computer Science Program,
Bina Nusantara University Bina Nusantara University, Bina Nusantara University,
Jakarta, Indonesia 11480 Jakarta, Indonesia 11480 Jakarta, Indonesia 11480
[email protected] [email protected] [email protected] Abstract—Stock price prediction has been an extensively Several studies aiming to predict stock prices have used
researched topic, especially since the rise of deep learning and the LSTM-GRU hybrid method has used the LSTM-GRU
its capabilities. The volatile nature of the market makes stock hybrid to predict stock prices in certain market regions such
price prediction a precarious task. Recurrent Neural Network as the Moroccan market [1] where the proposed method is
(RNN) has the virtue of being able to analyze time series data, quite promising, and its total performance is very satisfactory.
making it ideal for stock forecasting, and such. In this research Their suggested model has an annualized return of 27.13
models to predict GOOGL stock prediction for three future percent and a monthly return of 2.02 percent, whereas the
days are being compared. These models use Long-Short Term greatest performance of a rival Indice (excluding Software &
Memory (LSTM) and Gated Recurrent Unit (GRU) by
IT Services Indice) is 19.94 percent and 1.53 percent,
themselves, with them being combined in a parallel and
sequential manner, to compare each result as well. LSTM-GRU
respectively, for annualized return and monthly return. [3]
Parallel is used as the baseline model and is expected to have uses regularized LSTM-GRU and their testing findings
better prediction compared to the comparator models. This revealed that the model performed better in the short-term
result will be seen by its Root Mean Squared Error (RMSE) estimate of the stock closing price. It offers high forecast
result, in which if the result is closer to zero, it will be seen as the accuracy as well as a fast convergence speed. Also, while not
better model. It is found that the baseline has the best RMSE for stock prediction, a similar experiment using LSTM-GRU
result. was done by [4] LSTM has been proven to be the state-of-the-
art among all methods of time series for predicting
Keywords—Deep learning, Parallel, Sequential, Stock prices, cryptocurrency prices. This is owing to their capacity to recall
Time series, LSTM (Long-Short Term Memory), GRU (Gated and extract data's temporal properties. They suggested a
Recurrent Unit) bitcoin price prediction technique based on a hybrid model of
GRU and LSTM and the suggested strategy has proven to be
I. INTRODUCTION superior to the LSTM network, as evidenced by prediction
errors. [5] found that the ensembles do not outperform the
Forecasting stock prices is difficult due to the high LSTM network, which is present in all the top-performing
volatility and the number of variables that impact it (political, ensembles. The LSTM and GRU ensemble beat the hybrid
economic, social, etc.). Predicting the closing price gives model, which is a deep non-sequential network that mixes
valuable information and assists the investor in making the LSTM and GRU.
best selection. Deep learning, specifically recurrent neural
networks (RNN), is increasingly used in stock market A comparison of LSTM and GRU is also done by [6]
predictions. RNN has the adaptability to sequential data, Long found that the GRU model has a higher return ratio, showing
Short-Term Memory (LSTM) and Gated Recurrent Unit that it forecasts trends better and has a more robust approach,
(GRU) designs are among the most extensively utilized forms but it predicts with less confidence than the LSTM model. As
of RNNs [1]. In this research, comparisons of LSTM, GRU, a result, is suboptimal for the LSTM model. Despite
hybrid sequential LSTM-GRU, and hybrid parallel LSTM- producing excellent outcomes, the LSTM model cannot
GRU, will be explained further in the subsequent chapter. simulate dramatic market falls or rapid price spikes.
Their purpose is to see which method gives the best result for
stock market prediction. III. METHODOLOGY
The architectures used in this project consist of LSTM and
II. RELATED WORKS GRU with different arrangements; LSTM only, GRU only,
Continuous development in Artificial Intelligence (AI) LSTM-GRU sequential, and LSTM-GRU Parallel.
leads to the wide use of deep learning techniques in many
research fields and practical scenarios. Financial researchers A. Dataset
around the world have been studying and analyzing the The model uses Google stock prices (GOOGL) taken from
changes in the stock markets. The broadening application of Yahoo Finance dated back from the last three years until the
artificial intelligence has led to an increasing number of most recent data. The raw dataset contains multiple features,
investors using deep learning models to predict and study but price prediction will focus on using the close price. Min-
stock and prices [2]. max scaler is used as a normalization technique to maintain
the large variation of prediction and forecasting, the
XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE
normalization technique is required to make the range of data
closer [7]. The input and the prediction are three days apart.
As shown in Table III.1, the scaled_close column is the min-
max scaled price, and the future column contains the price
after three days from the scaled_close value offset by 3.
Figure III.2. GRU architecture
TABLE III.1. GOOGL stocks dataset
close Date scaled_close future
3) LSTM-GRU Sequential Model
75.247… 2020-08-06 0.0602… 0.0448… The LSTM-GRU Sequential Model is used to gauge
74.918… 2020-08-07 0.0560… 0.0616… its performance when carrying time series information
between the different GRU and LSTM architectures. The
74.841… 2020-08-08 0.0550… 0.0675… LSTM comes in front of the more complex model to
74.027 2020-08-09 0.0448… 0.0599… retain more information, followed by GRU to streamline
the information output, the expected result is the more
information-packed output of LSTM can be generalized
more when being used as the input of GRU, as shown in
B. Model Architecture Figure III.3.
LSTM and GRU are well-known RNN architectures
capable of passing information from past stages and using it
for future predictions [8], as such, the usage of both models
(mainly LSTM) in stock prediction needs RNN as it is time-
series data. LSTM and GRU are both widely used in a hybrid
manner to predict stock prices [1], [3], [6], [9], [10].
1) LSTM
The LSTM architecture is notable for employing the cell
state as a continuous data sequence for short-term memory
through the layer [11]. Forget gate selects which information
is carried through the cell state, outputting between 0 and 1
denoting forget or keep the information from the past state
respectively. The input gate regulates information from the
current input into the cell state. Lastly, the output gate is
responsible for passing the information in the hidden state, as
shown in Figure III.1.
Figure III.3. LSTM-GRU Sequential Model
4) LSTM-GRU Parallel Model
This model is used as the baseline. The parallel
architecture combines the first two models with the
expectation of the model having a more nuanced result to the
prediction by utilizing the complexity of LSTM and the lesser
complex model of GRU in which both of their results are then
concatenated to produce better prediction results, he model
Figure III.1. LSTM architecture
can be seen in Figure III.4.
2) GRU
GRU is a refined RNN that resembles LSTM, it addresses
the vanishing gradient of RNN while being lighter than
LSTM. GRU only transfers information through the hidden
state, it applies a reset gate that works like the LSTM forget
gate and an update gate for picking information to add or
drop. Having fewer tensor operations than LSTM, it is also
quicker to train [12]. GRU Architecture is shown in Figure
III.2.
TABLE IV.1. Model loss results
Model Parallel Sequential LSTM GRU
RMSE 0.0519 0.0557 0.0547 0.0524
From the results gathered in Table IV.1, the baseline
LSTM-GRU Parallel model shows the lowest amount of
RMSE of 0.0519, and it is closer to 0 when compared to other
comparators, which can be interpreted as the model having
the best accuracy.
B. Prediction Graph
The stock prediction was run on the 23rd of August 2023.
Therefore, the models predict the stock price of 24th – 26th of
August 2023. With the lines in Figure IV.1, that shows (a)
LSTM-GRU Parallel, (b) LSTM-GRU Sequential, (c) LSTM
Only, (d) GRU Only models, explained in Table IV.2.
TABLE IV.2. Graph line
Actual price for GOOGL stock
Figure III.4. LSTM-GRU Parallel Model Predicted price for GOOGL
Predicted price for the next 3 days
C. Training Hyperparamers
To ensure fairness for obtaining the results, all the models
used in this paper are trained using the same hyperparameters
across all four models, as shown in Table III.2 with the Epoch
of 100, batch size of 32, and used Adam as the optimizer.
TABLE III.2. Hyperparameter Setup
Epoch 100
Batch size 32
Optimizer Adam
(a) (b)
IV. RESULTS
Several results were gathered to see which model gives the
best result when being evaluated using RMSE and with
matching hyperparameters mentioned.
A. Model Evaluation
The models are evaluated using RMSE, so when the
predicted result is closer to zero, that result is closer to the
actual value that is trying to be predicted. (c) (d)
Figure IV.1. (a) LSTM-GRU Parallel, (b) LSTM-GRU
𝑛 Sequential, (c) LSTM Only, (d) GRU Only
(𝑦̂𝑖 − 𝑦𝑖 )2
𝑅𝑀𝑆𝐸 = √∑
𝑛 The predictions are then compiled in Table IV.3. to make
𝑖=1
it easier to interpret, which shows what model predicts the
results of the 24th-26th of August as Day 1-3.
The loss results of the models are provided in Table IV.1, TABLE IV.3. Prediction Result
where the RMSE results are compiled. The LSTM-GRU Day
Parallel model achieved an RMSE result of 0.0519, the Model
LSTM-GRU Sequential model achieved 0.0557, the LSTM 1 2 3
Only Model achieved 0.0547, the GRU Only model achieved LSTM-
0.0524, the result is compiled in Table IV.1. GRU 127.51$ 130.2$ 129.35$
Parallel
LSTM- [3] Y. Liu, Z. Wang, and B. Zheng, “Application of
GRU 127.8$ 128.6$ 129.54$ Regularized GRU-LSTM Model in Stock Price
Sequential Prediction,” 2019 IEEE 5th International
LSTM Only 129.26$ 126.74$, 129.44$ Conference on Computer and Communications,
ICCC 2019, pp. 1886–1890, 2019, doi:
GRU Only 128.63$ 129.62$, 129.87$ 10.1109/ICCC47050.2019.9064035.
[4] M. M. Patel, S. Tanwar, R. Gupta, and N. Kumar,
“A Deep Learning-based Cryptocurrency Price
Prediction Scheme for Financial Institutions,”
C. Conclusion
Journal of Information Security and Applications,
Stock price prediction has been a very challenging task vol. 55, no. June, p. 102583, 2020, doi:
for researchers due to the external or exogenous social and 10.1016/j.jisa.2020.102583.
psychological factors that affect its price prediction. It is [5] K. Murray, A. Rossi, D. Carraro, and A. Visentin,
found that the baseline model of LSTM-GRU Parallel when “On Forecasting Cryptocurrency Prices: A
compared to LSTM-GRU Sequential, LSTM, and GRU, is Comparison of Machine Learning, Deep Learning,
shown to learn the patterns of the stock, and it is confirmed and Ensembles,” Forecasting, vol. 5, no. 1, pp. 196–
by the loss value. As a result, it can be assumed that the 209, 2023, doi: 10.3390/forecast5010010.
LSTM-GRU Parallel model has the highest probability of [6] A. Sethia and P. Raut, Application of LSTM, GRU
giving price predictions closer to real life, as compared to the and ICA for stock price prediction, vol. 107.
other models, and this result is also found in cryptocurrency Springer Singapore, 2019. doi: 10.1007/978-981-13-
prediction as well by [4] where their proposed hybrid LSTM- 1747-7_46.
GRU combination is shown to have the best prediction result. [7] S. G. K. Patro and K. K. sahu, “Normalization: A
The second-highest result is GRU, followed by LSTM, this Preprocessing Stage,” Iarjset, pp. 20–22, 2015, doi:
result is also found by [6] in which their GRU result is shown 10.17148/iarjset.2015.2305.
to be better than LSTM. Surprisingly, the LSTM-GRU [8] A. Moghar and M. Hamiche, “Stock Market
Sequential model comes last. The reason for this can be Prediction Using LSTM Recurrent Neural
pointed to having LSTM’s output as the input of GRU, in Network,” Procedia Comput Sci, vol. 170, pp.
which the LSTM’s more complex output is then lost as, as 1168–1173, 2020, doi: 10.1016/j.procs.2020.03.049.
GRU will create a less complex prediction. [9] P. L. Seabe, C. R. B. Moutsinga, and E. Pindza,
“Forecasting Cryptocurrency Prices Using LSTM,
D. Discussion GRU, and Bi-Directional LSTM: A Deep Learning
Approach,” Fractal and Fractional, vol. 7, no. 2, p.
While it is shown that the baseline model has the best
203, Feb. 2023, doi: 10.3390/fractalfract7020203.
prediction, there are still possible ways that the prediction can
[10] H. Song and H. Choi, “Forecasting Stock Market
be improved upon, where hyperparameter values and the
Indices Using the Recurrent Neural Network Based
addition of layers can still be experimented on further.
Hybrid Models: CNN-LSTM, GRU-CNN, and
Ensemble Models,” Applied Sciences (Switzerland),
REFERENCES vol. 13, no. 7, 2023, doi: 10.3390/app13074644.
[11] S. Hochreiter and J. Schmidhuber, “Long Short-
[1] Y. Touzani and K. Douzi, “An LSTM and GRU Term Memory,” Neural Comput, vol. 9, no. 8, pp.
based trading strategy adapted to the Moroccan 1735–1780, 1997, doi: 10.1162/neco.1997.9.8.1735.
market,” J Big Data, vol. 8, no. 1, 2021, doi:
[12] J. Chung, C. Gulcehre, K. Cho, and Y. Bengio,
10.1186/s40537-021-00512-z. “Empirical Evaluation of Gated Recurrent Neural
[2] Z. Hu, Y. Zhao, and M. Khushi, “A survey of forex Networks on Sequence Modeling,” pp. 1–9, 2014,
and stock price prediction using deep learning,” [Online]. Available: http://arxiv.org/abs/1412.3555
Applied System Innovation, vol. 4, no. 1, pp. 1–30,
2021, doi: 10.3390/ASI4010009.