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

Sourcelstm

Uploaded by

salma
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)
33 views10 pages

Sourcelstm

Uploaded by

salma
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

Available online at www.sciencedirect.

com
Available
Available online
online at
at www.sciencedirect.com
www.sciencedirect.com
Available online at www.sciencedirect.com

ScienceDirect
Procedia Computer Science 00 (2022) 000–000
Procedia
Procedia
Procedia Computer
Computer
Computer Science
Science
Science 00
00 (2022)
(2022)
207 (2022) 000–000
000–000
3830–3839 www.elsevier.com/locate/procedia
www.elsevier.com/locate/procedia
www.elsevier.com/locate/procedia

26th International Conference on Knowledge-Based and Intelligent Information & Engineering


26th International Conference on Knowledge-Based and Intelligent Information & Engineering
Systems (KES 2022)
Systems (KES 2022)
ARIMA vs LSTM on NASDAQ stock exchange data
ARIMA vs LSTM on NASDAQ stock exchange data
Dariusz Kobielaa,∗ , Dawid Kreftaa , Weronika Króla , Paweł Weichbrothbb
Dariusz aKobielaa,∗a,∗, Dawid Kreftaaa , Weronika Królaa , Paweł Weichbrothb
Gdańsk University of Technology, Gabriela Narutowicza 11/12, Gdańsk 80-233, Poland
a
a Gdańsk University of
b Gdańsk University of Technology,
GdańskFaculty of Technology,
of Electronics,
University Gabriela
Gabriela Narutowicza
Telecommunications
Technology, 11/12,
11/12, Gdańsk
and Informatics,
Narutowicza 80-233,
80-233, Poland
Department
Gdańsk of Software Engineering, Gabriela
Poland
bb Gdańsk University
Gdańsk University of
of Technology,
Technology, Faculty
Faculty of
of Electronics, Telecommunications
Narutowicza
Electronics, and
and Informatics,
11/12, Gdańsk 80-233,
Telecommunications Poland Department
Informatics, Department of
of Software
Software Engineering,
Engineering, Gabriela
Gabriela
Narutowicza
Narutowicza 11/12,
11/12, Gdańsk
Gdańsk 80-233,
80-233, Poland
Poland

Abstract
Abstract
Abstract
This study compares the results of two completely different models: statistical one (ARIMA) and deep learning one (LSTM) based
This
on a study
This chosencompares
study compares the
the results
set of NASDAQ of
of two
resultsdata. Both
two completely
models are
completely different
used tomodels:
different predictstatistical
models: one
one (ARIMA)
daily or monthly
statistical average
(ARIMA) and deep
deep learning
andprices of chosenone
learning one (LSTM)
(LSTM) based
companies listed
based
on aa chosen
on the NASDAQ
chosen set
set of NASDAQ
ofstock exchange.
NASDAQ data. Both
Both models
data.Research showsare
models used
which
are to
to predict
usedmodel daily
performs
predict or
or monthly
dailybetter in terms
monthly average
of the prices
average chosenof
prices chosen
ofinput data,companies
chosen parameterslisted
companies and
listed
on
on the
the NASDAQ
number of features.
NASDAQ stock
stockTheexchange.
exchange. Research
chosen models
Research shows
were which
which model
compared
shows using the
model performs better
relative
performs in
in terms
metric
better mean of
terms the
the chosen
square
of input
input data,
error (MSE)
chosen and parameters
data, and
mean absolute
parameters and
number
percentage
number of features.
of error
features. The
The chosen
(MAPE). Selected
chosen models
metrics
models were
are compared
were using
typically used
compared using in the relative
regression
the metric
metric mean
relativeproblems. The square
mean error
performed
square (MSE)
erroranalysis and
and mean
(MSE) shows which
mean absolute
model
absolute
percentage
percentage error
achieves better (MAPE).
errorresults
(MAPE). Selected
Selected metrics
by comparing the chosen
metrics are
are typically
metrics inused
typically in
in regression
different
used models. problems.
regression The
The performed
It is concluded
problems. analysis
that the ARIMA
performed analysis shows
model
shows which
which model
performs better
model
achieves
achieves better
better results
than the LSTM model by
results by comparing
in terms the
of using
comparing chosen
the just onemetrics
chosen feature in
metrics different
different models.
– historical
in It
It is
price values
models. is concluded that
that the
– and predicting
concluded ARIMA
more
the ARIMA model
than one performs
time
model period, better
performs using
better
than
the p,the
than the LSTM
LSTM model
q parameters model in
in terms
in the rangeof
terms using
from
of 0 tojust
using 2, one
just Adam
one feature –
– historical
optimizer,
feature price
price values
tanh activation
historical –
– and
and predicting
function,
values and 2xLSTM
predicting more
more than
layer one
one time
time period,
thanarchitecture. using
The longer
period, using
the p, q
data parameters
window in
period,the range
the from
better 0
ARIMAto 2, Adam
performs,optimizer,
and the tanh
worse activation
LSTM function,
performs. and
The 2xLSTM
comparison layer
the p, q parameters in the range from 0 to 2, Adam optimizer, tanh activation function, and 2xLSTM layer architecture. The longer of architecture.
the models wasThe longer
made by
the
the data
data window
comparing window period,
the values
period, the
of the better
better ARIMA
the MAPE error. When
ARIMA performs, and
and the
predicting
performs, worse
30 days,
the worseARIMALSTM
LSTM performs. The
is about 3.4
performs. The comparison
times of
of the
better than
comparison models
LSTM.
the was
When
models made
made by
waspredictingby
comparing
an averagedthe
comparing the values
values of
3 months, the
the MAPE
ofARIMA MAPE error.
is about
error.1.8When
times
When predicting
better than
predicting 30 days,
days, ARIMA
30 LSTM. is
is about
about 3.4
When predicting
ARIMA antimes
3.4 better
better9 than
averaged
times LSTM.
months,
than ARIMA
LSTM. When
Whenispredicting
about 2.1
predicting
an averaged
times
an 33 months,
better than
averaged LSTM.
months, ARIMA
ARIMA is is about
about 1.8
1.8 times
times better
better than
than LSTM.
LSTM. When When predicting
predicting anan averaged
averaged 9 9 months,
months, ARIMA
ARIMA is is about
about 2.1
2.1
times
times better
better than
than LSTM.
LSTM.
© 2022
© 2022 TheThe Authors.
Authors. Published
Published by by Elsevier
Elsevier B.V.
B.V.
©
© 2022
This
2022is The
an open
The Authors.
access
Authors. Published
article
Published by
under
by Elsevier
the CC
Elsevier
This is an open access article under the CC BY-NC-ND B.V.
BY-NC-ND
B.V. license
license (http://creativecommons.org/licenses/by-nc-nd/4.0/)
(https://creativecommons.org/licenses/by-nc-nd/4.0)
This
This is an
Peer-review open
is an open
Peer-review access
under
access
under article
responsibilityunder
article under
responsibility the CC
ofofthethe BY-NC-ND
scientific
CCscientificcommittee
BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)
of the
license
committee of KES International.
(http://creativecommons.org/licenses/by-nc-nd/4.0/)
the 26th International Conference on Knowledge-Based and
Peer-review
Intelligent under
under responsibility
Peer-reviewInformation of
of the
& Engineering
responsibility the scientific
Systems committee
scientific (KES 2022)of
committee of the
the KES
KES International.
International.
Keywords: Time Series Analysis; Forecasting; Nasdaq; Autoregressive Integrated Moving Average; ARIMA; Long-Short Term Memory; LSTM.
Keywords:
Keywords: Time Time Series
Series Analysis;
Analysis; Forecasting;
Forecasting; Nasdaq;
Nasdaq; Autoregressive
Autoregressive Integrated
Integrated Moving
Moving Average;
Average; ARIMA;
ARIMA; Long-Short
Long-Short Term
Term Memory;
Memory; LSTM.
LSTM.

1. Introduction
1.
1. Introduction
Introduction
Nowadays, we can observe that almost every field of science and its applications is becoming increasingly com-
Nowadays,
Nowadays,
puterized we
we can
and automated.can observe
observe that
that almost every
every field
almostpandemic
The COVID-19 hasof
field science
sciencea and
ofbecome and its
its applications
applications
significant is
is becoming
accelerator becoming increasingly
increasingly
of this process com-
com-
[9, 16]. There
puterized
puterized and
and automated.
are industries automated.
which, withoutThe
The COVID-19
IT solutions,pandemic
COVID-19 pandemic has
has become
are no longer able toaafunction
become significant
significant accelerator
One of
accelerator
properly. ofthis
of the process
this process [9,
[9, 16].
16]. There
most important There
areas
are
are industries
industries
of this which,
which, without
type is finance, equatedIT
without IT solutions,
solutions,
with are
are no
the standardnooflonger
living able
longer able to
to function
functionand
of households properly.
properly. One
One of
the prosperity the
of of most
most important
thecompanies.
important areas
areas
Regardless
of
of this
this type
type itis
whether is isfinance,
a legalequated
finance, form orwith
equated with the
the standard
standard
an individual, of
of living
living
everyone of
of households
wantshouseholds
to maximize and the
the prosperity
andprofits.
prosperity of
of companies.
The financialcompanies. Regardless
Regardless
market offers many
of
of whether
whether itit isis aa legal
legal form
form or
or an
an individual,
individual, everyone
everyone wants
wants to
to maximize
maximize profits.
profits. The
The financial
financial market
market offers
offers many
many
∗ Corresponding author. Tel.: +48-511-339-571
∗∗ Corresponding
E-mail address:author.
Corresponding author. Tel.:
[email protected]
Tel.: +48-511-339-571
+48-511-339-571
E-mail
E-mail address:
address: [email protected]
[email protected]
1877-0509 © 2022 The Authors. Published by Elsevier B.V.
1877-0509
1877-0509 © 2022
© The Authors. Published by Elsevier B.V.
B.V.
This
1877-0509 © 2022
is an open
2022 The
access Authors.
Thearticle Published
under
Authors. by
by Elsevier
the CC BY-NC-ND
Published license (http://creativecommons.org/licenses/by-nc-nd/4.0/)
Elsevier B.V.
This
This is anopen
open access article under the CC BY-NC-ND oflicense
KES(https://creativecommons.org/licenses/by-nc-nd/4.0)
This is
is an
Peer-review
an open access
under article
article under
responsibility
access CC
CC BY-NC-ND
of the scientific
under license
committee
BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)
the International.
(http://creativecommons.org/licenses/by-nc-nd/4.0/)
Peer-review
Peer-review under
under responsibility
responsibility of of
the the scientific
scientific committee
committee of theofKES
theInternational.
26th International Conference on Knowledge-Based and Intelligent
Peer-review under responsibility of the scientific
Information & Engineering Systems (KES 2022) committee of the KES International.
10.1016/j.procs.2022.09.445
Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839 3831
2 D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000

products to achieve this goal, such as savings accounts, deposits, mutual funds, currencies, bonds and financial instru-
ments such as shares. Each of them is characterized by a specific risk of losing funds. The highest is in the case of
stock trading and its amount is proportional to the possibility of achieving large profits in a short period of time [4].
This factor makes stock trading an important source of income for many investors.
The ability to predict future share prices is important not only for investment decisions, but also when planning a
company’s development strategy, selecting partners for cooperation, and for financial analysis of the company. Each
investor makes the decision to buy or sell based on certain information, knowledge or intuition [26]. With different
indicators at our disposal [15], it is possible to make more rational decisions. There are many tools on the IT market to
support making investment decisions. The most commonly used tools are IT systems implementing technical analysis
indicators [7], which, based on historical data, present the way in which stock prices are shaped on charts. Along
with the development of statistical models and machine learning, they are used increasingly often in predicting stock
prices. In forecasting trends [25], the use of artificial neural networks – a field inspired by biological models – is also
becoming increasingly popular. Time series prediction is a topic that is under constant development and requires a lot
of research. Some of the latest research in this field was performed by Mateńczuk et al. [21] and Khang et al. [13, 14].
The goal of this paper is to compare two very different models – a statistical one (ARIMA) and a deep learning
one (LSTM) – using a very broad and representative range of NASDAQ stock exchange data, to find which model
performs better in the problem of time series forecasting. A forecast refers to a calculation or an estimation that uses
data from previous events, combined with recent trends to come up with a future event outcome. On the other hand,
a prediction is an act of indicating that something will happen in the future with or without prior information [18].
Time series are series of numerical data in which each observation is directly related to a given point in time [6]. In
this article, the daily and monthly average stock prices are time series. The field of time series research is in fact about
drawing conclusions based on observations about the parameters of the process that generates the data. It makes it
possible to predict future values and a forecast error.
To go through the appropriate comparison of the ARIMA and LSTM models, it was decided to conduct a series
of experiments on selected data. Three main goals were taken into consideration. They were to find the best ARIMA
model, to obtain the best LSTM model and finally to compare the selected models and determine which one is most
accurate at predicting stock prices. At the beginning, the focus was on building both models separately, without testing
the parameters. The main goal of this stage was to make the models work properly and not cause errors. The relevant
parameters were then tested separately using the ARIMA model and different LSTM architectures. The final stage
of the work was to create a program to perform of all the experiments and automatically save the results based on
the created convention. An important step was also to select the appropriate accuracy measures, thanks to which
it was possible to correctly compare the results of the built models. Each step was implemented using the Python
programming language.
The rest of the paper is structured as follows. Section 2 outlines the research methodology. Section 3 discusses
the significance and relevance of the results. Section 4 concludes the results and briefly specifies the future work
directions.

2. Methodology

2.1. Input Data

For the purposes of the analysis and modeling, nine of the most popular NASDAQ sectors, namely: IT, automotive,
financial, logistics & transport, clothing, food, energy, healthcare, and entertainment & media, were selected. In the
adopted methodology, inspiration was taken from the approach used by [23]. Each sector includes the share prices of
10 companies. Particular attention was paid to the fact that the training model should cover stock prices from various
sectors to avoid overfitting.
In the technology sector, very large enterprises have been selected that operate globally and have a real impact on
the fluctuations of trends in technology. The list includes both companies related to the production of software and the
production of computer hardware. A social network was also selected for this sector (See Table 1).
In the automotive sector, it was also decided to select companies that represent a cross-section of the situation on the
market. Companies with a long tradition have been added to companies with modern electric technologies. Companies
3832 Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839
D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000 3

Table 1. Stock portfolio selected as the input data. Source: [3].


Sector Stocks Total Cap
[billion $]
IT Microsoft, Google, IBM, Zoom, Intel, Facebook, Amazon, Qualcomm, Workday, Log- 6676
itech
Automotive Ford, Ferrari, Volkswagen, Toyota, Honda, BMW, Li Auto, Paccar, Kandi, Workhorse 659
Financial JP. Morgan, VISA, Bank of America, Morgan Stanley, Accenture, Bank OZK, The Car- 1753
lyle Group, Paypal, Northern Trust Corporation, LPL Financial Holdings
Logistics & UPS, Boeing, Uber, Vroom, Ryanair, United Airlines Holdings, Sky West, Booking 507
Transport Holdings, ArcBest, Lyft
Clothing Poshmark, HM, JOANN, Weyco Group, Cintas Corporation, Crocs, Columbia 86
Sportswear, Steven Madden, Urban Outfitters, Stein Mart
Food PepsiCo, McDonald’s, Unilever, Starbuck, s, Keurig Dr Pepper, The Kraft Heinz, JJ 760
Snack Foods, Sprouts Farmers Market, Pilgrim’s Pride, Beyond Meat
Energy Diamondback Energy, APA, PAA Plains All American Pipeline, BP, PDC Energy, Oasis 163
Petroleum, Plains GP Holdings, Weatherford International, Centennial Resource Devel-
opment, NextDecade Corporation
Healthcare Seagen, BioNTech SE American, IDEXX Laboratories, Sanofi ADR, AstraZeneca, Mod- 553
erna, DexCom, Natera, Masimo Corporation, ABIOMED
Entertainment & Warner Music Group, Fox Corporation, Dish Network, ViacomCBS, Lamar Advertising 136
Media Company, News Corporation, Nextstar Media Group, iHeart Media, Scientific Games
Corporation, Roku

from the financial sector constitute a very large percentage of companies on the US NASDAQ stock exchange. The
list of companies includes banks and corporations. There were also companies closely related to the financial sector
that deals with payment processing. In the logistics and transport sector, both land and air transport were included.
These sectors also include companies offering freight. A company closely related to an industry that affects the entire
logistics and transport sector was also added to the list. The clothing sector includes recognizable brands whose
products are worn by millions of people every day. The food sector includes companies producing food and beverages.
The energy sector includes companies dealing not only with oil and gas extraction, but also companies responsible for
its distribution and elimination of negative effects on the environment. The selected 10 companies from the healthcare
sector include companies producing drugs, vaccines, devices, and technologies necessary in the treatment of patients.
The entertainment sector includes companies that reflect the entire media market. The list of companies includes
television stations, radio stations, publishing houses and a company producing multimedia equipment.
Each company is identified by its ticker. The ticker (ticker symbol), sometimes called the stock symbol, is an
abbreviation used to uniquely identify publicly traded shares of a particular stock company. It can consist of letters,
numbers or combinations of both. Most stock symbols on the NASDAQ are unique 4-letter identifiers. Investors and
traders use the stock symbols to place trade orders [10].
Sample input data after cleaning is shown in Table 2. It consists of two columns: timestamp and price. Timestamp is
the continuous series of the given days, from the period from the year 2008 to 2021. Here, the price is the average price
of the particular stock from the given day and is calculated as the average price from all transactions that occurred on
that day.

Table 2. Sample of the cleaned IBM stock price data. Source: [24].
Id Timestamp Stock Price
1 2008-01-02 105.24647
2 2008-01-03 104.91873
3 2008-01-04 101.84878

After the literature review, it was noticed that in some stock price prediction papers [1, 17], only the closing
price was taken into consideration. An example was taken from [1], in which only the closing price was selected for
prediction, due to the fact that this price reflects all actions of the stock index during one day. After looking at other
Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839 3833
4 D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000

scientific literature about stock prices [32, 34], it was noticed that although the closing price is used in a lot of articles,
the average price is technically acceptable as well. For technical reasons, especially in the neural network model, the
daily average price is better than the daily closing price, because it helps to reduce the noise in the data. It is more
resistant to outliers, which may happen at the end of the day. Thus, the average price was chosen rather than the
closing price. It was also decided to perform experiments with two types of data (daily and monthly).

2.2. Computational Models

2.2.1. ARIMA model


The basic model in the time series analysis is the ARIMA model. It is a combination of two processes – autoregres-
sive (AR) and moving average (MA), which is weighted delayed random components. The letter I in the model name
indicates the level of integration of the analyzed variable. Integrated variables are variables that can become stationary
through differentiation. The structure of ARIMA is based on the phenomenon of autocorrelation. ARIMA can be used
for modeling stationary time series or non-stationary time series that can become stationary through differentiation.
Stationary series are those whose expected value and variance do not change over time, the series values themselves
do not deviate from the initial values, and the value of the covariance for two observations depends on the spacing
between them, not the timing of their origin. The universal notation ARI MA (p, d, q) is used to describe the form
of the ARIMA model. The letter p is the order of the regression, d is the order of differentiation and q is the order
of the moving average. The process of building the ARIMA model can be divided into three phases, which follows
the Box-Jenkins method. In the first phase, identification, the characteristics of the analyzed time series are checked.
A decision is made about the need for data to transform and differentiate the series to stabilize its mean, variance
covariance. This is done by both examining the autocorrelation function (ACF) and partial autocorrelation (PACF),
and by performing statistical Dickey-Fuller and Augmented-Dickey-Fuller tests. In the second phase, estimation and
tests, the parameters of the selected models are estimated. The final model selection is usually based on the analysis of
several criteria – the significance of model parameters, error metric and information criterion (Akaike’s Information
Criterion, Bayesian Information Criterion). The next step is a diagnostic check. The properties of a number of model
residuals are analyzed. If the residuals of the model are a white noise process, and there are no significant ACF or
PACF values of a series of model residuals, the model can be used for forecasting. Otherwise, the estimation and test-
ing phases should be repeated, and a different model should be selected. In some cases, it may be necessary to return
to the identification phase. In the third phase, the model is used to prepare a forecast ([20]). The forecast is performed
using in-sample and out-of-sample periods. The given dataset is split into an in-sample period, used for the initial
parameter estimation and model selection, and an out-of-sample period, used to evaluate the forecasting performance.
Empirical evidence based on the out-of-sample forecast performance is generally considered more trustworthy than
evidence based on the in-sample performance, which can be more sensitive to outliers [8].
To obtain the desired level of stationarity of the series, all of the input data was logarithmized.

2.2.2. LSTM model


A historic scientific paper published in 1943 [22] initiated a new field of research called artificial neural networks
(ANNs). The mathematicians presented an artificial neuron – a model of a nerve cell – and linked its operation to
data processing. Since then, the field has been constantly evolving. Hebb discovered in 1949 [11] that information can
be stored in the structure of connections between neurons and proposed a new method of learning ANN consisting
in changing the connection weights between neurons. The word “Perceptron” was proposed by Rosenblatt [28], who
together with Wightman built a neural-like network. It was part electronic, part electromechanical and was used to rec-
ognize alphanumeric characters. It was the first physical and functional machine of this type. The above achievement
led to the spread of interest in neural networks and research on them all over the world.
Recursive neural networks (RNNs) are a broad class of networks in which, even as the input data changes over
time, the same parameters are used. Recursive networks are among the most successful models that are devouring
applications both in research and industry to problems related to sequential data in natural language processing, time
series prediction and classification. The main differences between unidirectional and recursive networks are that RNNs
see the time data in an ordered form as values in successive steps and have a state that is preserved between successive
time steps. It is this state, as well as its static parameters, that are responsible for updating the network response after
providing it with new information in the next steps. The disadvantage of RNNs is that they suffer from short-term
3834 Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839
D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000 5

memory. One of the solutions to that problem is a model introduced by Hochreiter and Schmidhuber [12] called long
short-term memory (LSTM). It is capable of learning long-term dependencies using a mechanism called gates, which
are different tensor operations that can learn what information to add to or remove from the hidden state. A comparison
of a single unit of a classical RNN with an LSTM is presented in Figure 1.

Fig. 1. RNN and LSTM comparison [30]

To compare the ARIMA and LSTM models, there is a need to choose the best one in each case in relation to the
selected performance metrics. The comparison of predicted values was performed with exactly the same input data
processing. The data was logarithmized and fitted to the models in daily or monthly intervals. In the case of LSTM,
the data was also normalized according to the input set and divided into several input and output windows, moved by
a fixed shift. In the case of ARIMA, every company time series was processed as a whole.

2.3. Output Data

The output data for both models is the time series prediction for a given time window.
In the case of the ARIMA model, it is a table consisting of rows containing: company ticker, real value from out-of-
sample period, prediction value, standard error, and lower and upper value boundaries resulting from the calculation
+/- 2*standard error. To obtain the prediction values in US $, the mathematical exponential operation must be per-
formed (values were previously log-transformed). Exemplary prediction results for the IBM company are shown in
Table 3.

Table 3. IBM exemplary prediction results (ARIMA model)


company real value prediction standard error lower series upper series
IBM 4.897324 4.900446 0.010132 4.880588 4.920305
IBM 4.896517 4.896496 0.010131 4.876639 4.916353

In the case of the LSTM model, the output data is a table consisting of: x test – fragment of the company time
series (whose length is defined as the input window size) used by the model to predict future values; y predict –
time series predicted by the model (length defined as the output window size); y test – real values of the time series
in the predicted period, used to check the model performance; company name – ticker of the predicted company;
x start date, x end date – start and end date for the x test set; y start date, y end date – start and end date for the
y test and y predict sets. Exemplary prediction results for the IBM company are shown in Table 4.
Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839 3835
6 D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000

Table 4. IBM exemplary prediction results (LSTM model)


company name x start date x end date y start date y end date
IBM 2011-04-16 2011-10-12 2011-10-13 2011-11-11

x test y test y predict


165.18612473 186.49382407 186.22127266
164.56847636 189.29697533 186.16533308

3. Results and Findings

It was decided to compare the models using 3 different periods: 30 days, 3 months and 9 months. The main reasons
were to reflect various investment opportunities (short-, medium- and long-term) and that everyone has their own
investment preferences: the goal was to aim the research in the direction that makes business sense and is useful for
various types of investors. A further two basic comparisons were performed: 1 day, and 1 month, to check if LSTM
or ARIMA performs better in the case of a prediction just 1 step ahead.

Table 5. Comparison of MAPE for ARIMA and LSTM for different time windows
time window ARIMA (MAPE) LSTM (MAPE)
1 day 1.64 1.46
30 days 1.64 5.52
1 month 4.28 6.90
3 months 5.93 10.53
9 months 7.55 16.05

Fig. 2. Prediction for IBM company using ARIMA, 30-day period

Two types of errors were selected to compare the performance of each model separately and to compare both
models against each other – Mean Absolute Percentage Error (MAPE) and Mean Square Error (MSE). The results of
3836 Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839
D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000 7

Fig. 3. Prediction for IBM company using ARIMA, 30-day period (zoomed)

Fig. 4. Prediction for IBM company using LSTM, 30-day period (zoomed)

the experiments carried out for the ARIMA model showed that the p and q ranges should be restricted to values of 0,
1 or 2. The results of the LSTM model experiments showed that the best parameters for the neural network model are
Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839 3837
8 D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000

2xLSTM architecture, Adam optimizer and tanh activation function. The next experiments were therefore carried out
using these parameters. A comparison of the GRU and LSTM architectures was also performed, which showed that
in the case of the selected data, the GRU architecture performs worse than the LSTM.
The experiments performed to choose time windows for LSTM showed that the best input window sizes for LSTM
are 180 days in the case of daily intervals and averaged 1800 days in the case of monthly intervals.

Fig. 5. Validation loss values for different input window sizes

The further conducted research showed that in most cases, ARIMA performs better than LSTM (according to the
comparison of the MAPE error values). When predicting 30 days, ARIMA is about 3.4 times better than LSTM. In
the case of predicting averaged 1 month, ARIMA performed about 1.6 times better than LSTM. When predicting
averaged 3 months, ARIMA is about 1.8 times better than LSTM. When predicting averaged 9 months, ARIMA is
about 2.1 times better than LSTM. LSTM only performed better in the case of 1-day prediction (about 1.12 times
better). It can therefore be concluded that the longer the period, the better ARIMA performs and the worse LSTM
performs (the ARIMA results confirm the results obtained by Wang et al. [31]). Based just on the price feature, the
ARIMA model is better at calculating the next predictions. The achieved results confirm the results found by Yi-Tou
et al. [2]. A comparison of the achieved MAPE results for ARIMA and LSTM for different time windows is shown in
Table 5.
Learning plots showed that LSTM is not learning (after the 5th epoch, an example is shown in Figure 5). The
reason of this behavior is that not enough features were taken into account (just one feature was used – price). In
LSTM, all of the desired prediction period values are predicted at once. That is why LSTM produces worse results–
it consists of a more complicated architecture which needs more features for effective training. Otherwise, the LSTM
model is in its basic state and is not using its full potential. The colors used are not important in Figure 5 and only
serve to make it easier to distinguish between different time windows. In the case of predicting the stock prices of
NASDAQ-listed companies using just historical price values (single feature), the statistical model (ARIMA) achieves
better results than the deep learning model (LSTM).
A comparison of the ARIMA and LSTM sample prediction results for the 30-day prediction periods for the IBM
company are shown in Figures 2, 3 and 4. Colors used: blue indicates historical company prices (used by the models
either to learn in the case of LSTM or as the in-sample period in the case of ARIMA); red indicates the forecast
performed by the model; green indicates the company’s real future prices (used to calculate the error between the
forecast and the actual values).
3838 Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839
D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000 9

4. Discussion, Future Research and Limitations

During the comparison of the ARIMA and LSTM models, the logarithmized data were used in both the ARIMA
and LSTM models. This decision is confirmed by the research conducted by Hoque et al. [27] and Dezsi et al. [5].
In the ARIMA model, the logarithm operation was necessary to achieve time series stationarity; however, in the case
of LSTM, it was possible to check if the network can achieve better results using the data without the logarithm
operation. Also, some other methods of sample generation may be tested.
The main value of the presented research is that the model comparison is performed on a very broad and repre-
sentative dataset from the NASDAQ stock exchange. It covers the most important sectors of the US economy. The
comparison of models was done to create a solid background for the usage of ARIMA and LSTM models in time
series prediction. The achieved results can be developed in further research to explore the neural network aspect in
more depth.
It would be valuable to check if the LSTM model with multiple features can outperform the ARIMA model, which
is based just on the price feature. This is very probable according to the research performed by Namin et al. [29],
in which the data consisted of monthly financial time series of five stock indices and monthly economics time series
from the Federal Reserve Bank of St. Louis and the International Monetary Fund Website, so there was a significant
number of features used in LSTM model. The results showed that the deep learning model performs much better than
the statistical model.
When choosing LSTM features, sentiment analysis can be used in addition to economic indicators. Such an ap-
proach, with the usage of sentiment downloaded from news feeds, may help to achieve an interesting model, which
will be able to predict sudden spikes in prices and stock market crashes. Research in this area was performed by
Wojarnik [33]. The overriding feature of recursive LSTM networks is that multiple variables can be used as input.
Unfortunately, this is not possible with the ARIMA model. The research area currently under development [19] is
a hybrid model in which autoregression and deep learning networks are used at once. The use of the benefits of
both types of models while leveling their disadvantages can significantly improve the quality of prediction. This area
requires more detailed research.

Acknowledgements

We would like to thank Mr. Przemysław Koralewski, NASDAQ Associate Vice President and Head of Sales from
the Nasdaq London branch for his help in obtaining and transferring the NASDAQ data which are the basis of our
research.

References

[1] Ariyo, A.A., Adewumi, A.O., Ayo, C.K., 2014. Stock price prediction using the arima model, in: 2014 UKSim-AMSS 16th International
Conference on Computer Modelling and Simulation, IEEE. pp. 106–112.
[2] Choy, Y.T., Hoo, M., Khor, K.C., 2021. Price prediction using time-series algorithms for stocks listed on bursa malaysia , 1–5doi:10.1109/
AiDAS53897.2021.9574445.
[3] CompaniesMarketCap, 2022. Companies market capitalization. URL: https://companiesmarketcap.com/.
[4] Debski, W., 2001. Financial market and its mechanisms: Supplement: stock quotes in the new IT system. PWN.
[5] Dezsi, E., Nistor, I.A., 2016. Can deep machine learning outsmart the market? a comparison between econometric modelling and long-short
term memory. Romanian Economic and Business Review .
[6] Dyk, M., et al., 2013. Forecasting revenues and costs according to box-jenkins. Scientific work of the University of Economics in Wroclaw ,
115–124.
[7] Ebert, S., Hilpert, C., 2019. Skewness preference and the popularity of technical analysis. Journal of Banking & Finance 109, 105675.
[8] Eurostat, 2022. Glossary:in-sample vs. out-of-sample forecasts. URL: https://ec.europa.eu/eurostat/statistics-explained/i
ndex.php?title=Glossary:In-sample vs. out-of-sample forecasts.
[9] Gawin, B., Marcinkowski, B., 2020. Covid-19 lockdown and it-powered reporting: an enabler, irrelevant factor, or something in between?, in:
36th International Business Information Management Association Conference, International Business Information Management Association.
[10] Hayes, A., 2020. Stock symbol (ticker). URL: https://www.investopedia.com/terms/s/stocksymbol.asp.
[11] Hebb, D.O., 1949. The organisation of behaviour: a neuropsychological theory. Science Editions New York.
[12] Hochreiter, S., Schmidhuber, J., 1997. Long short-term memory. Neural computation 9, 1735–1780.
Dariusz Kobiela et al. / Procedia Computer Science 207 (2022) 3830–3839 3839
10 D. Kobiela et al. / Procedia Computer Science 00 (2022) 000–000

[13] Khang, P.Q., Hernes, M., Kuziak, K., Rot, A., Gryncewicz, W., 2020. Liquidity prediction on vietnamese stock market using deep learning.
Procedia Computer Science 176, 2050–2058.
[14] Khang, P.Q., Kaczmarczyk, K., Tutak, P., Golec, P., Kuziak, K., Depczyński, R., Hernes, M., Rot, A., 2021. Machine learning for liquidity
prediction on vietnamese stock market. Procedia Computer Science 192, 3590–3597.
[15] Korczak, J., Bac, M., Drelczuk, K., Fafuła, A., 2012. Multi-agent system for stock trader. Informatyka Ekonomiczna/Uniwersytet Ekonomiczny
we Wrocławiu , 97–108.
[16] Kowal, J., Klebaniuk, J., 2021. Has the pandemic changed moral attitudes and organizational ethics in knowledge workers? Kowal, Jolanta
and Klebaniuk, Jarosław,” Has The Pandemic Changed Moral Attitudes and Organizational Ethics in Knowledge Workers .
[17] Kumar, S., Ningombam, D., 2018. Short-term forecasting of stock prices using long short term memory, in: 2018 International Conference on
Information Technology (ICIT), IEEE. pp. 182–186.
[18] Kungu, E., . Difference between forecast and prediction. URL: http://www.differencebetween.net/science/difference-betwe
en-forecasting-and-prediction/.
[19] Lai, G., Chang, W.C., Yang, Y., Liu, H., 2018. Modeling long-and short-term temporal patterns with deep neural networks, in: The 41st
International ACM SIGIR Conference on Research & Development in Information Retrieval, pp. 95–104.
[20] Malska, W., Wachta, H., 2015. Using the arima model to analyze the time series. Scientific Papers of the Rzeszów University of Technology.
Electrotechnics 34, 3.
[21] Mateńczuk, K., Kozina, A., Markowska, A., Czerniachowska, K., Kaczmarczyk, K., Golec, P., Hernes, M., Lutosławski, K., Kozierkiewicz,
A., Pietranik, M., et al., 2021. Financial time series forecasting: Comparison of traditional and spiking neural networks. Procedia Computer
Science 192, 5023–5029.
[22] McCulloch, W.S., Pitts, W., 1943. A logical calculus of the ideas immanent in nervous activity. The bulletin of mathematical biophysics 5,
115–133.
[23] Mondal, P., Shit, L., Goswami, S., 2014. Study of effectiveness of time series modeling (arima) in forecasting stock prices. International
Journal of Computer Science, Engineering and Applications 4, 13.
[24] Nasdaq, . Nasdaq data on demand. URL: https://dataondemand.nasdaq.com/docs/index.html.
[25] Nielsen, A., 2019. Practical time series analysis: Prediction with statistics and machine learning. O’Reilly Media.
[26] Owoc, M., Weichbroth, P., Żuralski, K., 2017. Towards better understanding of context-aware knowledge transformation, in: 2017 Federated
Conference on Computer Science and Information Systems (FedCSIS), IEEE. pp. 1123–1126.
[27] Paul, J.C., Hoque, M.S., Rahman, M.M., 2013. Selection of best arima model for forecasting average daily share price index of pharmaceutical
companies in bangladesh: A case study on square pharmaceutical ltd. Global Journal of Management and Business Research .
[28] Rosenblatt, F., 1958. The perceptron: a probabilistic model for information storage and organization in the brain. Psychological review 65,
386.
[29] Siami-Namini, S., Namin, A.S., 2018. Forecasting economics and financial time series: Arima vs. lstm. arXiv preprint arXiv:1803.06386 .
[30] Sit, M., Demiray, B.Z., Xiang, Z., Ewing, G.J., Sermet, Y., Demir, I., 2020. A comprehensive review of deep learning applications in hydrology
and water resources. Water Science and Technology 82, 2635–2670.
[31] Wang, M.D., Qiu, Q.R., Cui, B.W., 2012. Short-term wind speed forecasting combined time series method and arch model. volume 3.
doi:10.1109/ICMLC.2012.6359477.
[32] Widodo, A., Kusdarwati, H., Handoyo, S., 2019. Modeling average prices of garlic in indonesia. Journal of Engineering and Applied Sciences
14. doi:10.3923/jeasci.2019.7943.7950.
[33] Wojarnik, G., 2021. Sentiment analysis as a factor included in the forecasts of price changes in the stock exchange. Procedia Computer Science
192, 3176–3183.
[34] Zuo, Y., Kita, E., 2012. Stock price forecast using bayesian network. Expert Systems with Applications 39, 6729–6737. doi:10.1016/j.es
wa.2011.12.035.

You might also like