Predictive Analysis of Tesla's Stock Closing Prices Utilizing LSTM
and GRU Deep Learning Models
Yiheng Chi
Haide College, Ocean University of China, Qingdao, China
Keywords: LSTM, GRU, Stock Closing Price, Deep Learning, Tesla.
Abstract: This study delves into advanced deep learning methods, namely Long Short-Term Memory (LSTM) and
Gated Recurrent Units (GRU), to predict Tesla's stock prices from 2013 to 2023, a period marked by notable
market volatility. It aims to analyze these models' abilities in capturing complex financial trends, particularly
in the rapidly evolving electric vehicle sector. The research employs a hybrid approach, combining LSTM
and GRU layers to leverage their respective strengths in long-term and short-term forecasting.
Methodologically, the study involves comprehensive data processing, model building, and validation using
historical stock data from the Nasdaq platform. The models are evaluated through various statistical metrics,
including RMSE, MSE, and MAE, to assess their predictive accuracy. The findings reveal that while GRU
models excel in short-term forecasting, the hybrid model demonstrates stronger capabilities in long-term trend
analysis. This suggests the need for tailored model selection based on specific forecasting timelines in
financial markets. The study's implications extend to the practical application of LSTM and GRU models,
recommending an integrated approach for more accurate and responsive market forecasting. It also highlights
the potential for future research to incorporate real-time market data, enhancing the models' relevance and
adaptability in a rapidly changing financial landscape.
1 INTRODUCTION
The pursuit of forecasting stock market trends has
consistently intrigued numerous analysts and
researchers (Shah et al 2019). Analyzing movements
and price behaviors in the stock market is highly
challenging due to its dynamic, nonlinear,
nonstationary, nonparametric, and chaotic
characteristics, coupled with inherent noise in the
data (Abu-Mostafa and Atiya 1996). For investors,
this predictive ability is crucial in planning
investment portfolios and maximizing returns. For
financial institutions and policymakers, accurate
forecasts of stock prices are essential for a better
understanding and management of market risks, as
well as for formulating policies in line with economic
trends. Throughout the years, both investors and
researchers have shown keen interest in creating and
evaluating models related to the behavior of stock
prices (Fama 1970).
With increasing attention to climate change and
the rapid evolution of electric vehicle technology, the
new energy industry, led by electric vehicles, has
rapidly developed and become a significant part of
the stock market. As a leader in the electric vehicle
and new energy industry, Tesla plays an important
role in the global stock market. Particularly, the high
volatility of Tesla's stock makes it an ideal case study
for understanding and predicting dynamic market
trends.
A notable characteristic of these new energy
industries is the high volatility of their stock prices in
recent years. As Pettinger pointed out, fluctuations in
the stock market significantly influence both national
economies and individual consumer finances, and a
significant drop in stock prices can cause extensive
economic disruptions (Pettinger 2023). Therefore,
researching the prediction of Tesla's stock price is
greatly beneficial for understanding the capital
movements and investor sentiments in the clean
energy market. The notable volatility of Tesla’s stock
prices in recent years underscores the importance of
conducting a thorough analysis. This study aims to
evaluate the effectiveness and adaptability of specific
models in forecasting stock market trends, and hopes
to provide a deeper understanding of future financial
market trends by capturing the market dynamics and
trends of Tesla's stock.
422
Chi, Y.
Predictive Analysis of Tesla’s Stock Closing Prices Utilizing LSTM and GRU Deep Learning Models.
DOI: 10.5220/0012807500004547
Paper published under CC license (CC BY-NC-ND 4.0)
In Proceedings of the 1st International Conference on Data Science and Engineering (ICDSE 2024), pages 422-428
ISBN: 978-989-758-690-3
Proceedings Copyright © 2024 by SCITEPRESS Science and Technology Publications, Lda.
Machine learning techniques have been
extensively researched to automatically process a
wealth of financial data, such as historical stock
prices, thereby supporting investment decisions
(Yoshihara et al 2014). In the realm of financial
market prediction, especially in stock market
forecasting, deep learning techniques such as LSTM
and GRU have emerged as significant research tools.
Touzani and Douzi, in the Journal of Big Data,
demonstrate the application of LSTM and GRU in
market forecasting, showcasing their potential in
handling sequential data (Touzani and Douzi 2021).
Moreover, a study by Gao et al. emphasized that
traditional analysis methods fall short in addressing
the complexities of stock market data, while LSTM
and GRU exhibit superior predictive accuracy (Gao
et al 2021). Soni et al. explored various techniques in
stock price prediction, ranging from traditional
machine learning and deep learning methods to neural
networks and graph-based approaches (Soni et al
2022). Venkatarao et al. further contributed to this
field by introducing a novel normalization approach
in their study 'Stock Price Prediction by Normalizing
LSTM and GRU Models,' underscoring the
importance of optimizing these deep learning
techniques for enhanced stock market prediction
accuracy (Venkatarao et al 2023). Additionally,
Mukherjee et al. employed deep learning algorithms
for an in-depth prediction of stock market prices,
achieving significant accuracy (Mukherjee et al 2023).
Long Short-Term Memory networks (LSTMs)
and Gated Recurrent Units (GRUs) have garnered
considerable attention due to their exceptional ability
to handle sequential data, a crucial aspect in the
complex field of stock price prediction. This study is
dedicated to employing LSTM and GRU, two
advanced deep learning techniques, to analyze and
predict the stock prices of Tesla, Inc.
This study employs cutting-edge deep learning
techniques, specifically Long Short-Term Memory
(LSTM) and Gated Recurrent Units (GRU), to
analyze and forecast the stock prices of Tesla, Inc.
Utilizing historical stock price data from November
29, 2013, to November 27, 2023, sourced from the
Nasdaq platform, our approach innovatively
combines both LSTM and GRU models. This
methodology aims to leverage the unique strengths of
each model for more accurate and robust predictions.
The data selection focuses on recent years to capture
the significant fluctuations in Tesla's stock, reflecting
the evolving dynamics of the electric vehicle and
clean energy sectors.
2 METHODS
2.1 Data Acquisition
The historical daily stock data of Tesla from
November 29, 2013, to November 27, 2023, were
downloaded from the Nasdaq platform. The data's
scientific rigor and accuracy were validated against
actual stock prices. The dataset comprises Date, Open,
Close, Volume, High, and Low. Initial data
visualization was conducted to check for consistency
and outliers.
2.2 Data Visualization
The complete statistics of Tesla's stock prices over the
period are crucial for our research on time series
analysis. Therefore, understanding the changes in
Tesla's stock prices from November 29, 2013, to
November 27, 2023, is essential.
Figure 1: Stock Prices of TSLA (Picture credit: Original).
Predictive Analysis of Tesla’s Stock Closing Prices Utilizing LSTM and GRU Deep Learning Models
423
Fig. 1 illustrates the time series plot of Tesla's
daily stock values, comprising Date, Open, Close,
Volume, High, and Low. Observations from the
monthly time series plot of Tesla's stock prices reveal
key insights. Between 2013 and 2020, the stock price
remained relatively stable, demonstrating a degree of
steadiness. However, starting in 2020, a significant
shift occurred as the stock price began to exhibit
extreme volatility. Notably, from 2022 to 2023, there
was an overall upward trend, with the stock reaching
its peak in early 2022. Subsequently, a continuous
decline was observed until the beginning of 2023.
From early 2023 to the present, Tesla's stock price has
gradually recovered but has shown strong fluctuations.
Furthermore, no apparent seasonality or cyclical
pattern was demonstrated in this time series plot. These
observations not only highlight the dynamic changes in
Tesla's stock price but also provide valuable
perspectives for our time series analysis.
2.3 Data Cleaning and Selection
Data cleaning involved converting data types in the
Date column, setting it as an index, and checking for
null values. Given the continuity in stock closing
prices, missing values were filled using the mean of
adjacent days. Due to significant fluctuations in
Tesla's stock price since 2020, only data post-January
1, 2022, were selected for model training and testing
(Fig 2).
This subset of 478 data points was normalized to
a range of 0-1. The data was then split into training
(65%) and testing (35%) sets, and both sets were
visualized (Fig 3).
Figure 2: Stock Prices of TSLA after 2022 (Picture credit:
Original).
2.4 Model Building and Evaluation
Three models were built, trained, and evaluated:
LSTM, GRU, and an innovative model combining
LSTM and GRU layers. The models were assessed
using RMSE, MSE, MAE, MGD, MPD, and
regression R-squared coefficients for both training
and testing sets. This analysis aimed to comparatively
analyze the strengths and weaknesses of each model.
The predictive performance of each model was
visualized by plotting the predicted stock price trends.
2.5 Parameters Selection
LSTM, GRU and a combined models were selected.
Parameters of these models were carefully chosen to
ensure comparability across models (Table 1). All
models were trained with 200 epochs, using MSE as
the loss function, a batch size of 5, 32 nodes, and
'adam' optimizer. The LSTM model consisted of three
LSTM layers, the GRU model of four GRU layers,
and the innovative model of two LSTM layers
followed by two GRU layers.
Figure 3: Normalized Training set and Testing Set (Picture credit: Original).
ICDSE 2024 - International Conference on Data Science and Engineering
424
Table 1: Parameter Selection for Models.
Model Parameter Selection
LSTM
Epochs = 200
Batch = 5
loss = ‘MSE’
optimizer = ‘adam’
3 LSTM layers
with 32 nodes
GRU
Epochs = 200
Batch = 5
loss = ‘MSE’
optimizer = ‘adam’
4 GRU layers
with 32 nodes
LSTM & GRU
Epochs = 200
Batch = 5
loss = ‘MSE’
optimizer = ‘adam’
2 LSTM and 2 GRU layers with 32
nodes
2.6 Assumption and Limitation
As shown in Table 2, the model is based on the
following five assumptions to ensure its rigor.
Table 2: Assumption for Models.
Assumption Contents
Market Efficiency
Hypothesis
The stock market is semi-strong
efficient, meaning all publicly
available information is already
reflected in the current stock
p
rices.
Historical Trend
Repetition
Hypothesis
Historical price trends and
patterns are assumed to recur to
some extent in the future.
Locality of Market
Influence
Hypothesis
The primary factors influencing
stock prices are assumed to be
local and co
Ignoring Macro-
Economic and Non-
Structural Changes
Macro-economic factors and
policy changes are not quantified
in the model.
Non-Extreme Event
Hypothesis
The prediction period is assumed
not to include extreme market
events like financial crises or
significant political events.
The study primarily aimed to compare the
regression and predictive performance of LSTM,
GRU, and their combined model on a one-to-two-
year time series of tesla stock. The study's limitations
include a lack of consideration for various external
factors affecting the stock market, making real-world
applicability challenging. However, the approach is
viable for comparing LSTM and GRU through
statistical analysis and visualization, thereby
supporting the research's conclusions.
3 RESULTS AND DISCUSSION
3.1 Performance Metrics
In this study, a comprehensive analysis was
conducted on LSTM and GRU models for predicting
Tesla's stock prices. Key findings include (table 3):
Table 3: Evaluation Metrics of Models.
LSTM GRU
LSTM and
GRU
Metri
cs
Train Test Train Test Train Test
RMSE 9.8563 8.3645 9.5030 7.4402 9.0924 7.5828
MSE
97.146
0
69.965
5
90.306
6
55.356
9
82.672
0
57.499
0
MAE
7.5581 6.3781 7.4933 5.6884 7.1255 5.6682
MGD 0.0017 0.0012 0.0016 0.0010 0.0015 0.0010
MPD 0.3942 0.2899 0.3662 0.2342 0.3412 0.2396
0.9740 0.9447 0.9759 0.9563 0.9779 0.9546
EVR
Score
0.9764 0.9481 0.9765 0.9574 0.9781 0.9560
In comparing the performance of LSTM, GRU,
and the combined models, all displayed robust
regression. GRU and the combined models
demonstrated superior precision in predicting stock
price fluctuations. Despite higher MSE and MAE in
training, GRU showed more effective forecasting in
testing.
3.2 Major Findings
Comparing the performance of LSTM, GRU, and the
combined model, they all displayed robust regression.
GRU and the combined model demonstrated superior
precision in predicting stock price fluctuations.
Despite higher MSE and MAE in training, GRU
showed more effective forecasting in testing.
3.3 Minor Findings
The regression R-squared coefficients and explained
variance analysis indicate that LSTM
underperformed compared to GRU and the combined
model in both training and testing phases. Overall,
GRU excelled in forecasting Tesla's stock prices,
particularly in testing, whereas the combined model
showcased a robust predictive capacity.
Predictive Analysis of Tesla’s Stock Closing Prices Utilizing LSTM and GRU Deep Learning Models
425
3.4 Visual Comparison Results
As illustrated in Fig. 4, the closing stock prices of
Tesla, exhibit significant fluctuations and lack clear
patterns, indicating the challenging nature of
accurately forecasting its stock prices.
Figure 4: Stock Close Price for Training and Testing
(Picture credit: Original).
Following this, we visualized the regression
results from three distinct models-LSTM, GRU, and
a combined approach, and also depicted their
predictions for the closing stock prices over the next
ten trading days following November 27, 2023.
Figure 5: Comparison Between Original Close Price and
Predicted Close Price for LSTM (Picture credit: Original).
Figure 6: Whole Close Stock Price Chart with Ten-Day
Predictions for LSTM (Picture credit: Original)
From Figure 5 and 6, it can be seen that the LSTM
predicts an upward trend for the next ten days.
Figure 7: Comparison Between Original Close Price and
Predicted Close Price for GRU (Picture credit: Original).
Figure 8: Whole Close Stock Price Chart with Ten-Day
Predictions for GRU (Picture credit: Original).
From Figure 7 and 8, it can be seen that the GRU
predicts a downward trend for the next ten days.
Figure 9: Comparison Between Original and Predicted
Close Price for LSTM and GRU (Picture credit: Original).
Figure 10: Whole Close Stock Price Chart with Ten-Day
Predictions for the Combined Model (Picture credit:
Original).
ICDSE 2024 - International Conference on Data Science and Engineering
426
From Figure 9 and 10, it can be seen that the
combined model predicts an upward trend for the next
ten days.
Figure 11: Comparison Chart of Ten-Day Future Stock
Price Predictions (Picture credit: Original).
As illustrated in Figure 11, the LSTM and combined
models predict an upward trend in Tesla's stock prices
over the next ten days. Conversely, the GRU model
anticipates a decline.
3.5 Discussion
Through the calculation of multiple statistical metrics,
this study has proven the GRU model's high precision
in short-term stock market forecasting. This aligns
with the findings of Touzani and Douzi, who also
emphasized the effectiveness of GRU in volatile
market conditions. Additionally, the combined model
has shown strong predictive power in long-term trend
analysis, which is an innovative aspect of this study.
The effectiveness of GRU in short-term predictions
provides a strategic tool for navigating rapid market
changes, while LSTM supports more extended-term
investment. This offers insights for practical stock
market applications based on the data range used in
training models: the shorter the time, the more layers
of GRU should be chosen; conversely, the longer the
time, the more layers of LSTM should be selected.
Firstly, a limitation is its reliance on historical data
without real-time insertion of new data, which may
hinder capturing real-time market dynamics.
Secondly, the study's focus solely on Tesla's stock
with a single data pattern might limit the model's
general applicability across different market
conditions. This study implies that when researching
highly volatile time-series data, an appropriate ratio
of GRU to LSTM should be chosen according to the
time range. In the future, first, more market factor
constraints should be added to enhance the model's
predictive ability. Second, research could explore the
combined model's capability in handling other stock
data, such as fluctuation ranges, differences between
closing and opening prices, etc., to help improve
overall fitting accuracy.
4 CONCLUSION
In the comparative analysis of predicting Tesla's
stock prices using LSTM and GRU models, this study
has garnered profound insights. Not only did it affirm
the effectiveness of these deep learning models in
processing complex financial time series data, but it
also explored their unique strengths in forecasting the
highly volatile Tesla stock market.
The findings indicate that while both models
demonstrated capability in capturing the essential
trends and fluctuations of stock prices, they exhibited
differences in specific areas. Notably, the GRU model
showed enhanced performance in the testing phase,
illustrating its superiority in real-world forecasting
applications. Additionally, the innovative model
combining LSTM and GRU layers, although not
excelling in every performance metrics, showed
robust predictive capacity overall. These discoveries
highlight the potential of GRU and the combined
models in volatile financial time series contexts.
In terms of visual comparison, the study presented
regression results of past Tesla stock prices for all
three models and predicted their closing stock prices
over the next ten trading days. The outcomes revealed
that both the LSTM and the combined LSTM & GRU
models predict an upward trend for the next ten days,
while the GRU model forecasts a downturn. This
further confirms the distinct characteristics and
advantages of different models in handling specific
financial data.
In conclusion, this research not only demonstrates
the significance of LSTM and GRU in stock market
prediction but also offers new perspectives and
methodological guidance for deep learning
technology in financial time series forecasting.
Furthermore, the study suggests that a combination of
LSTM and GRU models might be particularly
effective in predicting stock prices in highly volatile
markets like Tesla's.
REFERENCES
D. Shah, H. Isah, F. Zulkernine, Int. J. Financ. Stud. 7(2),
26 (2019).
Y. S. Abu-Mostafa, A. F. Atiya, Appl. Intell. 6, 205-213
(1996).
E.F. Fama, J. Finance 25, 383-417 (1970).
T. Pettinger, Econ. Help, (2023).
Predictive Analysis of Tesla’s Stock Closing Prices Utilizing LSTM and GRU Deep Learning Models
427
A. Yoshihara, F. Kazuki, S. Kazuhiro, U. Kuniaki, Pac.
Inter. Conf. Arti. Intel., (2014).
Y. Touzani, K. Douzi, J. Big Data, 126 (2021).
Y. Gao, R. Wang, E. Zhou, Sci. Prog., (2021).
P. Soni, Y. Tewari, D. Krishnan, J. Phys.: Conf. Ser., 28-30
(2022).
J. Venkatarao, D. V. D. Chakravarthy, S. Meadi, K. L.
Durga, K. Pranay, N. Purushotham, J. Surv. Fish. Sci.
10(1), 5326-5332 (2023).
S. Mukherjee, B. Sadhukhan, N. Sarkar, D. Roy, S. De,
CAAI Trans. Intell. Technol., 8(1), 82-94 (2023).
ICDSE 2024 - International Conference on Data Science and Engineering
428