• Tidak ada hasil yang ditemukan

Predicting The Stock Closing Price of ISX-Listed Companies Using LSTM

N/A
N/A
Protected

Academic year: 2024

Membagikan "Predicting The Stock Closing Price of ISX-Listed Companies Using LSTM"

Copied!
10
0
0

Teks penuh

(1)

Volume 8, No. 3, November 2022, 391-400 E-ISSN 2655-7274

391

Predicting The Stock Closing Price of ISX-Listed Companies Using LSTM

Salim Sallal Al-Hassnawi, Laith Haleem Al-Hchemi*

University of Al-Qadisiyah, Diwaniyah, Iraq Email: [email protected]

Abstract

Financial markets are highly reactive to events and situations, as seen by the very volatile movement of stock values. As a result, investors are having difficulties guessing prices and making investment decisions, especially when statistical techniques have failed to model historical prices. This paper aims to propose an RNNs-based predictive model using the LSTM model for predicting the closing price of four stocks listed on the Iraq Stock Exchange (ISX). The data used are historical closing prices provided by ISX for the period from 2/1/2019 to 24/12/2020. Several attempts were conducted to improve models training and minimize the prediction error, as models were evaluated using MSE, RMSE, and R2. The models performed high accuracy in predicting closing price movement, despite the Intense volatility of time series. The empirical study concluded the possibility of relying on the RNN-LSTM model in predicting close prices at the ISX as well as decisions making upon.

Keywords: Stock, Closing price ISX, Prediction, LSTM, RNN

How to Cite: Al-Hassnawi, S.S. & Al-Hchemi, L.H., (2022).

Predicting the stock closing price of ISX-Listed companies using LSTM. Journal Ilmiah Manajemen dan Bisnis, 8 (3), 391-400.

INTRODUCTION

In recent years, financial markets have seen significant volatility, particularly with the emergence of the Covid-19 pandemic and the massive damage it caused to various economic sectors, which was reflected in stock prices both negatively and positively. That is what made the risk factor raise, especially since it relates to an uncertain future. The situation of ISX is not extremely different from other stock markets, despite the lack of international investments and the prevailing nature of local trading of the market. However, ISX did not immune it to global dangers, as shares had some oscillations especially observed when coincided Covid-19 pandemic with dropping oil prices, which Iraq's economy is heavily reliant on. These rapid fluctuations make investment decisions excessively difficult, prompting investors and financial analysts to hunt for techniques to predict the future. Stock prediction is regarded as a difficult task, with researchers proposing various techniques for predicting stock prices. Statistical models such as Linear Regression (Cakra & Distiawan Trisedya, 2016), Autoregressive and Moving Average (ARIMA) (Ariyo et al., 2014), and (GARCH) models (Franses &

Van Dijk, 1996) are among the proposed techniques mentioned. However, previous techniques have been criticized for being inaccurate and having difficulty processing non-linear data. Therefore, modern

Article info Article history:

Received :11 October 2022

Received in revised form 23 Nov 2022 Accepted : 28 Nov 2022

Available online : 30 Nov 2022

(2)

Artificial Intelligence-based techniques known as "Machine Learning" have recently been proposed, such as Support Vector Regression (SVR) (MS, 2011), Deep Learning Algorithm (Nikou et al., 2019), and Neural Networks. Machine Learning refers to all algorithms that use computers to detect patterns based on provided data (Moghar & Hamiche, 2020), which varies depending on the learning mechanism used to model data. Long-Short-term Memory (LSTM) network, which is part of Recurrent Neural Networks (RNN), was used in this work. We attempted to train predictive models to estimate the closing price trend and predict the next day's price. The sample included four stocks of industrial and banking sectors, both of them listed on Iraq Stock Exchange, for a period from (2/1/2019) to (24/12/2020).

Python packages, such as Keras, Sklearn, were used to build the LSTM model. Some Python dependency packages, such as Pandas and Numpy, have also been used to deal with and prepare data provided by Iraq Stock Exchange (ISX). The goal of this work is to experiment with a stock prediction LSTM-based model to obtain more accurate results. This work is a contribution to helping investors in the Iraqi Stock Exchange in making stock investment decisions. The following is the structure of the paper reminder; the literature review was covered in Section (2). Section 1 provides an overview of artificial neural networks (3). Section (4) discussed the paper's methodology and data. The empirical results and discussion were covered in Section (5). The paper was finally concluded in Section (6).

Several similar works of this paper, have been examined in the literature, Tasi & Wang (2009) (Tsai & Wang, 2009) examined a hybrid model combines Decision trees and Neural networks to forecast the electronic industry stocks price of Taiwan. The findings show that neural network models outperform decision tree models. Abhishek et al (2012) (Abhishek et al., 2012) used ANN with Back- Propagation algorithm to predict Microsoft stock price. The findings showed high performance though it was not able to predict stock price precisely, it was able to predict the stock trend. Moghaddam et al (2016) (Moghaddam et al., 2016) examined the ability of Neural networks to predict the daily NASDAQ exchange rate using several Feed-forward ANNs, which have been trained by Back-propagation algorithm. The study found that ANN is able to predict the trend of NASDAQ exchange rate. Liu et al (2017) (Y. Liu et al., 2017) developed an analytical model based on merging sentiments of online stock forums and stock market information to predict stock volatility using RNN. They found that the model performs significantly better by merging compared to using RNN only. Jin et al (2019) (Jin et al., 2020) proposed a predictive model based on deep learning using LSTM considering investors' emotional tendency. They conducted Stock time sequence analysis using empirical mode decomposition (EMD) to reduce the complexity. The empirical study showed that LSTM model improves the prediction accuracy and reduces the time delay. Vijh et al (2020) (Vijh et al., 2020) conducted a comparative study between ANNs and Random forest for predicting the next day closing price of five companies in the operation sector. The findings showed the superiority of ANN comparing RF when tested by MSE, MAPE, and RMSE. Liu et al (2021) (K. Liu et al., 2021) studied the impact of Social network information on the accuracy of LSTM model in predicting the close price of the SSE 50 constituent

(3)

stocks. The empirical findings indicate that the social network variable can significantly improve prediction accuracy.

Artificial Neural Network

Artificial Neural Networks are brain-inspired computational models. They've been used in a variety of fields, including computing, medicine, engineering, economics, and more. Optimization theory was used to construct the artificial neural networks. Artificial Neural Networks, like the human nervous system, are made up of a group of neurons called (processing units) that are linked together by synapses (known as Weights) (Zakaria et al., 2014). In general, artificial neural networks have three layers: input, hidden, and output. The number of neurons in the Input and Output layers is determined by the entered data dimension and target output, respectively. Concerning the hidden layer, the number of neurons depends on the complexity of the entered data. The hidden layers have transformation functions known as (Activation function), which may include Sigmoid, Tanh, Relu, and others. These functions improve training by processing nonlinear data coming from the input layer (Tharsanee et al., 2021). ANNs learn by computing the error in output values using a specific algorithm that adjusts the weights. Artificial neural networks come in a variety of types. We used recurrent neural networks (RNNs) in this study, specifically the Long short-term memory (LSTM) as mentioned previously.

Recurrent Neural Network

The recurrent neural network (RNN) is a type of artificial neural network that considers the sequence in which the units are connected (Mathur et al., 2019). RNN receives prior output as input into next neurons, allowing it to remember past values (Rather, 2021). According to this context, RNN can be used to predict time series. However, as feedback loops continue, there are some limitations in terms of memory. The inability of RNNs to store memory for a long time due to gradient descent has vanished. (Chen & He, 2018). Given the foregoing, the node at (time t) will receives the output of previous node at (time t-1) in addition to data itself to generate the output at (time t) (Nabipour, Mojtaba and Nayyeri, Pooyan and Jabani, Hamed and Mosavi, Amir and Salwana, 2020). RNN formulas can be described as follow (Lin et al., 1996)

𝑡 = tanh⁡(𝑊𝑡𝑡+ ⁡⁡ 𝑊𝑥𝑋𝑡) (1) 𝑦𝑡 = 𝑊𝑦𝑡 (2) Where, xt, ht, yt, and Wh are input, hidden, output vectors and weighting matrix respectively.

(4)

Figure 1. Recurrent Neural Networks (RNNs) Chart Long Short-Term Memory

Due to the limitations of RNNs previously mentioned, Hochreiter & Schmidhuber (Hochreiter, 1997) proposed a modified type of RNN called Long short-term memory (LSTM), which can learn long-term dependencies. LSTM has a large memory and can learn from separate inputs with long time lags (Yadav et al., 2020). Each LSTM node is mostly made up of cells that are in charge of storing passed data streams. The LSTM model consists of three gateways: an input gate that determines whether new input is permitted, a forget gate that discards irrelevant data, and an output gate that determines what data to output. These three gates operate in the (0, 1) range and employ the sigmoid function. The mathematical formulas for these gates are represented by the following equations.

3( 𝑓(𝑡)= ⁡𝜎(𝑊𝑓ℎ⁡.⁡⁡ℎ(𝑡−1)+ ⁡ 𝑊𝑓𝑋⁡⁡.⁡⁡𝑥(𝑡)+ ⁡ 𝑏𝑓) )

f is forget gate, Wfh is weight matrix associated with the hidden states, h is hidden state of previous timestamp, Wfx is weight matrix associated with the input, x(t) is input of current timestamp, b is bias value.

( )4 𝑖(𝑡)= ⁡𝜎(𝑊𝑖ℎ⁡.⁡⁡ℎ(𝑡−1)+ ⁡ 𝑊𝑖𝑋⁡.⁡⁡𝑥(𝑡)+ ⁡ 𝑏𝑖)

i is input gate, Wih is weight matrix associated with the hidden states, h is hidden state of previous timestamp, Wix is weight matrix associated with the input, x(t) is input of current timestamp, b is bias value.

( )5 𝑔(𝑡)= ⁡𝑡𝑎𝑛ℎ(𝑊𝑔ℎ⁡.⁡⁡ℎ(𝑡−1)+ ⁡ 𝑊𝑔𝑋⁡.⁡⁡𝑥(𝑡)+ ⁡ 𝑏𝑖)

g(t) is tanh activation function.

( )6 𝐶(𝑡) = ⁡ 𝑖(𝑡)⁡. 𝑔(𝑡)+ ⁡ 𝑓(𝑡). 𝐶(𝑡−1)

C(t) is cell state of current time stamp, C(t-1) is cell state of previous timestamp.

(5)

( )7 𝑜(𝑡)= ⁡𝜎(𝑊𝑜ℎ⁡.⁡⁡ℎ(𝑡−1)+ ⁡ 𝑊𝑜𝑋⁡.⁡⁡𝑥(𝑡)+ ⁡ 𝑏𝑜)

i is input gate, Woh is weight matrix associated with the hidden states, h is hidden state of previous timestamp, Wox is weight matrix associated with the input, x(t) is input of current timestamp, b is bias value.

( )8 ℎ(𝑡)= ⁡𝑡𝑎𝑛ℎ(𝐶(𝑡−1))⁡. 𝑜(𝑡)

h(t) is tanh activation of current timestamp.

Figure (2) described LSTM model architecture.

Figure 2: Long short term memory architecture METHODOLOGY

Description of Data

The four stocks raw data were acquired from Iraq Stock Exchange (ISX). The data were gathered for a two-year (02/01/2019) to (24/12/2019) as daily indices. Several stock indices are included in the data set, such as Open, Close, High, Low, Volume, Last Close, Average, and Change Rate. Only the closing price is considered in this study. Table (1) displays some statistics of the dataset

Table 1: Closing price statistics

Stock Observations Max value Min value Average

Baghdad Bank 390 0.50 0.23 0.33

Investment Bank 298 0.30 0.19 0.25

Baghdad Soft Drink Co. 402 4.15 1.91 3.13

Mansour Drugs Co. 362 1.50 0.60 1.00

Proposed work

In this section, we will discuss the methodology of proposed work for predicting stock closing price of the concerned stock in several stages.

Data Preparation

This phase involves sub-stages to pre-process the raw data:

• Extracting only the closing price from other features.

(6)

• Missing data have been replaced by the previous day value.

• Normalizing the dataset in range (0,1) using MinMaxScalar library, to improve the training.

• Dividing dataset into Training and Testing sets, to evaluate the model later, where the training set was 80%, and testing is the 20% remainder. Table (2) shows dividing dataset based on dates.

Table 2: Dividing dataset into train and test sets

Company Training Set Testing Set

From To From To

Baghdad Bank 2/1/2019 19/8/2020 20/8/2020 24/12/2020

Investment Bank 2/1/2019 12/8/2020 13/8/2020 24/12/2020

Baghdad Soft Drink Co. 2/1/2019 27/8/2020 31/8/2020 24/12/2020

Mansour Drugs Co. 3/1/2019 6/9/2020 7/9/2020 24/12/2020

LSTM Model Building

In this stage, we use the Sequential class from the Keras library to structure the LSTM model.

The model was built from a sequential input layer, two LSTM layers with (50) neurons with Relu activation function, and a Dense output layer. The models were built using stochastic gradient descent (SGD) and Adamax optimizers.

Training The Model

Several training attempts are made, during which the RNN generates random outputs that are compared to the target values. By adjusting the weights, the back-propagation algorithm reduces errors.

The regression loss function was mean squared error (MSE).

Evaluating The Model

At this stage, the model is evaluated by comparing predicted values to test set values. As a result, mean squared error (MSE) and root mean squared error (RMSE) are employed. The lowest score of these measures indicates the model's accuracy.

RESULTS AND DISCUSSION

In this paper, we used two LSTM models to predict the closing price of four ISX-listed stocks from the industrial and banking sectors. Two error metrics, MSE and RMSE, as well as the Coefficient of determination (R2), were used to assess model accuracy. These three measures are widely used to assess the efficacy of Regression models. Below are equations for the performance measures used.

𝑴𝑺𝑬 = ⁡𝑁𝑖=1𝑁𝑒2 (3) 𝑹𝑴𝑺𝑬 = ⁡ √𝑁𝑖=1𝑁𝑒2 (4) 𝑹𝟐= ⁡∑(𝐲(𝐢)⁡−⁡µ(𝐲))𝟐

∑(ȳ⁡(𝐢)⁡−⁡µ(ȳ))𝟐 (5) To compare the performance of optimization algorithms used in long-term memory to minimise the error function. The Adamax optimizer was used to optimise the industrial sector models, and

(7)

Stochastic gradient descent (SGD) was used to optimise the banking sector models. The performance of four models is shown in Table (3).

Table 3: The performance of the four models.

Stock’ model Optimizer Epochs MSE RMSE R2

Baghdad Bank SGD 5000 0.00001 0.003 0.90

Investment Bank SGD 5000 0.000001 0.001 0.94

Baghdad Soft Drink Co.

Adamax 1000 0.0001 0.01 0.99

Mansour Drugs Co. Adamax 1000 0.0000001 0.0003 0.99

As it is shown in Table (3), four models have high accuracy, as the performance measures were minimal and high R2 score. Furthermore, Table (3) shows that Adamax algorithm learned faster, reaching the best performance after 1000 epochs, whereas SGD algorithm required 5,000 epochs to achieve the best performance.

Baghdad Bank Investment Bank

Baghdad Soft Drink Co. Mansour Drugs

Figure 3: Model performance minimizing errors.

(8)

Figure (3) illustrates that the model's error dropped as the number of epochs increased. The experiment demonstrated that increasing batch size improves the training process, despite increasing time.

Baghdad Bank Investment Bank

Baghdad Soft Drink Mansour Durgs

Figure 4: Stock price prediction for the four models.

Figure (4) shows the high accuracy of the four models used, despite the time series' instability in the presence of trend and seasonality components.

CONCLUSION

Stock prices fluctuate significantly, as forecasting future price movements is a challenging task, especially given the inability of statistical techniques to model the stock price movement. This paper proposed an RNN-based predictive model using LSTM to predict the closing price of four stocks listed on the Iraq Stock Exchange's industrial and banking sectors (ISX). Python packages such as Keras and Sklearn are used to build the LSTM models because of their high flexibility and controllability. The empirical results show that the proposed models are accurate, as measured by MSE, RMSE, and R2. The LSTM models have proven to be reliable in making investment decisions based on them. In future

(9)

work, we will attempt using multivariate to construct a more accurate predictive model, as well as other types of ANNs such as CNN, GRNN, and others.

REFERENCES

Abhishek, K., Khairwa, A., Pratap, T., & Prakash, S. (2012). A stock market prediction model using Artificial Neural Network. 2012 Third International Conference on Computing, Communication and Networking Technologies (ICCCNT’12), 1–5.

Ariyo, A. A., Adewumi, A. O., & Ayo, C. K. (2014). Stock price prediction using the ARIMA model.

2014 UKSim-AMSS 16th International Conference on Computer Modelling and Simulation, 106–112.

Cakra, Y. E., & Distiawan Trisedya, B. (2016). Stock price prediction using linear regression based on sentiment analysis. ICACSIS 2015 - 2015 International Conference on Advanced Computer Science and Information Systems, Proceedings, 147–154.

https://doi.org/10.1109/ICACSIS.2015.7415179

Chen, S., & He, H. (2018). Stock Prediction Using Convolutional Neural Network. IOP Conference Series: Materials Science and Engineering, 435(1). https://doi.org/10.1088/1757-

899X/435/1/012026

Franses, P. H., & Van Dijk, D. %J J. of forecasting. (1996). Forecasting stock market volatility using (nonlinear) Garch models. 15(3), 229–235.

Hochreiter, S. and S. (1997). Long short-term memory. Neural Computation, 9(8), 1735–1780.

Jin, Z., Yang, Y., Liu, Y. %J N. C., & Applications. (2020). Stock closing price prediction based on sentiment analysis and LSTM. 32(13), 9713–9729.

Lin, T., Horne, B. G., Tiiio, P., & Giles, C. L. (1996). Learning Long-Term Dependencies in NARX Recurrent Neural Network. IEEE Transactions on Neural Networks, 7(6), 1329–1338.

https://pdfs.semanticscholar.org/f62c/3868ebabb5d84bfcf1c5eae6d72d5fb33125.pdf

Liu, K., Zhou, J., Dong, D. %J J. of B., & Finance, E. (2021). Improving stock price prediction using the long short-term memory model combined with online social networks. 30, 100507.

Liu, Y., Qin, Z., Li, P., & Wan, T. (2017). Stock volatility prediction using recurrent neural networks with sentiment analysis. International Conference on Industrial, Engineering and Other

Applications of Applied Intelligent Systems, 192–201.

Mathur, R., Pathak, V., & Bandil, D. (2019). Emerging Trends in Expert Applications and Security. In Emerging Trends in Expert Applications and Security (Vol. 841). Springer Singapore.

https://doi.org/10.1007/978-981-13-2285-3

Moghaddam, A. H., Moghaddam, M. H., Esfandyari Finance, M. %J J. of E., & Science, A. (2016).

Stock market index prediction using artificial neural network. 21(41), 89–93.

Moghar, A., & Hamiche, M. %J P. C. S. (2020). Stock market prediction using LSTM recurrent neural network. 170, 1168–1173.

MS, V. (2011). Stock price prediction using support vector regression. International Conference on Computing and Communication Systems, 588–597.

Nabipour, Mojtaba and Nayyeri, Pooyan and Jabani, Hamed and Mosavi, Amir and Salwana, E. and others. (2020). Deep learning for stock market prediction. Entropy, 22(8), 840.

Nikou, M., Mansourfar, G., Bagherzadeh Finance, J. %J I. S. in A., & Management. (2019). Stock price prediction using DEEP learning algorithm and its comparison with machine learning algorithms. 26(4), 164–174.

Rather, A. M. (2021). LSTM-based Deep Learning Model for Stock Prediction and Predictive Optimization Model. EURO Journal on Decision Processes, 9(September), 100001.

https://doi.org/10.1016/j.ejdp.2021.100001

Tharsanee, R. M., Soundariya, R. S., Kumar, A. S., Karthiga, M., & Sountharrajan, S. (2021). Deep convolutional neural network–based image classification for COVID-19 diagnosis. Data Science for COVID-19, 117–145. https://doi.org/10.1016/b978-0-12-824536-1.00012-5

Tsai, C. F., & Wang, S. P. (2009). Stock price forecasting by hybrid machine learning techniques.

Proceedings of the International Multiconference of Engineers and Computer Scientists, 1(755), 60.

(10)

Vijh, M., Chandola, D., Tikkiwal, V. A., & Kumar, A. (2020). Stock Closing Price Prediction using Machine Learning Techniques. Procedia Computer Science, 167, 599–606.

https://doi.org/10.1016/j.procs.2020.03.326

Yadav, A., Jha, C. K., & Sharan, A. (2020). Optimizing LSTM for time series prediction in Indian stock market. Procedia Computer Science, 167(2019), 2091–2100.

https://doi.org/10.1016/j.procs.2020.03.257

Zakaria, M., Al-Shebany, M., & Sarhan, S. (2014). Artificial neural network: a brief overview.

International Journal of Engineering Research and Applications, 4(2), 7–12.

Referensi

Dokumen terkait

distress amongst public listed companies in Indonesia Stock Exchange. (IDX) using the logistic regression

This research has an objective to prove earnings manipulation detection using Beneish M-score model has an impact to stock return in Indonesia listed companies on LQ45 at

PERFORMANCE EVALUATION OF PROPERTY AND REAL ESTATE COMPANIES LISTED ON INDONESIA STOCK EXCHANGE USING DATA ENVELOPMENT ANALYSIS1.

This study aims to determine the financial health level of manufacturing and metal companies listed on the Indonesia Stock Exchange and also to find out if there is a

In this paper, we evaluate and analyze the optimal hyperparameter search in the long short-term memory (LSTM) model developed to forecast stock prices using the Optuna

DETERMINANTS OF FACTORS THAT AFFECT THE STOCK PRICE OF MANUFACTURING COMPANIES LISTED IN THE INDONESIAN STOCK. EXCHANGE IN THE YEARS 2011

The effect of intellectual capital on stock price and company value in manufacturing companies listed in Indonesia Stock Exchange 2008-2012 with size and leverage as moderating

Therefore, the study aimed to look on FINANCIAL PERFORMANCE BASED ON PROFITABILITY, LIQUIDITY, SOLVENCY AND ITS IMPACT ON THE STOCK PRICE OF COMPANIES LISTED IN MINING SECTOR AT