Empirical Analysis for Stock Price Prediction Using NARX Model with Exogenous Technical Indicators

Stock price prediction is one of the major challenges for investors who participate in the stock markets. Therefore, different methods have been explored by practitioners and academicians to predict stock price movement. Artificial intelligence models are one of the methods that attracted many researchers in the field of financial prediction in the stock market. This study investigates the prediction of the daily stock prices for Commerce International Merchant Bankers (CIMB) using technical indicators in a NARX neural network model. The methodology employs comprehensive parameter trails for different combinations of input variables and different neural network designs. The study seeks to investigate the optimal artificial neural networks (ANN) parameters and settings that enhance the performance of the NARX model. Therefore, extensive parameter trails were studied for various combinations of input variables and NARX neural network configurations. The proposed model is further enhanced by preprocessing and optimising the NARX model's input and output parameers. The prediction performance is assessed based on the mean squared error (MSE), R-squared, and hit rate. The performance of the proposed model is compared with other models, and it is shown that the utilisation of technical indicators with the NARX neural network improves the accuracy of one-step-ahead prediction for CIMB stock in Malaysia. The performance of the proposed model is further improved by optimising the input data and neural network parameters. The improved prediction of stock prices could help investors increase their returns from investment in stock markets.


Introduction
e importance of the stock market to the international economy is undeniable [1]. Stock markets play a critical role in accelerating the growth of various sectors of the economy by facilitating the transfer of money from those with funds to those with the ability to invest it [2].
Wang et al. stated that different arguments had been made between participants in the market about the stock price predictability [3], with two arguments constituting the main ones. e first argument advocates that predictability is not possible because stock markets are efficient and future price movements are independent of past price action. e second argument argues that the market can be predicted or that its predictability can fluctuate between high and low levels.
Two hypotheses are closely related to the first argument regarding the unlikelihood of correct prediction, namely the Random Walk Hypothesis (RWH) and the Efficient Market Hypothesis (EMH). e RWH was introduced by [4], who stated who stated that future stock price values or directions could not be predicted based on past performance since stock price fluctuations are unrelated to one another. e EMH [5] implies that in an efficient market, all readily available information is incorporated, and stock prices respond to new information rapidly. Consequently, this rapid adjustment of stock prices in response to new information is frequently unanticipated, making the shift random [6]. Similarly, in [7], the study explains that the stock price follows a random walk behaviour because the market is efficient, and therefore, the movements of stock prices are unpredictable. Based on the multiple information levels (historical prices, public information, and private information) incorporated into the stock price, [5] categorised market efficiency into three types: weak-form EMH, semistrong form EMH, and strong-form EMH. On the other hand, the Adaptive Market Hypothesis (AMH) introduced by [8] suggests that market efficiency is not fixed and can fluctuate between different efficiency levels. Market change is commonly driven by predictable investor behaviour, such as overconfidence, loss aversion, and overreaction. ese investors' behaviours are consistent with human behavioural principles such as adaptation, competition, and natural selection [8,9]. erefore, AMH proposes that market efficiency and inefficiencies coexist in an intellectually consistent manner [10]. AMH can describe the predictability of major global stock indices where stock price predictability fluctuates with the time between periods of high predictability and other periods of low predictability, indicating that market efficiency is not an all-or-none situation [11].
Previous studies have attempted to predict the stock price or return movement with varying degrees of success (for example, [12][13][14]). Surveys conducted by [15] showed promising forecast results using conventional or digital computing models.
Accurate prediction of the stock market is still a big challenge because of the complexity and stochastic nature of the market data [16][17][18][19][20][21]. Specifically, the Malaysian stock market is a growing emerging market characterised by asymmetrical dynamic behaviour and weak market efficiency [22,23]. Several studies were carried out to improve the prediction accuracy of different stock prices in Malaysia using various computational intelligence techniques [24,25]. is paper's main objective is to analyse and compare the performance of the NARX neural network model to the performances of two other models [26,27]. ese models used the Feedforward Neural Network (FFNN) and Ensembled Feedforward Neural Network (ENN) models with macroeconomic variables in forecasting the CIMB stock market closing price. e CIMB stock is chosen as it was used in the [26,27] models, and such selection was based on the fluctuation in the CIMB price data [26,27].
is study explores the potential improvement in prediction performance by utilising technical variables in NARX models with optimised input data, preprocessing, and model parameter configuration. A comprehensive set of parameter trails for different combinations of input variables and different NARX neural network settings are investigated. e remaining sections of the paper are organised as follows: Section 2 provides background on prediction techniques as well as an overview of notable studies on the subject. NARX's approach, experimental setup, and settings are all explained in Section 3. Section 4 discusses and compares the experimental results, and finally, Section 5 draws the main conclusions of this study.

Literature Review
Forecasting the stock market is made by utilising a variety of prediction models. ese forecasting models take technical and fundamental factors into account and as such, fundamental and technical analyses are two methods for forecasting a stock's future direction. e fundamental analysis utilises economic and financial data about the company (e.g., revenue, workforce, infrastructure, and profitability) to determine the company's intrinsic value [28]. Fundamental analysis assumes that the market is logical, and the stock price depends on the company's real value and so, the price will eventually move towards the real (intrinsic) value.
On the other hand, forecasting stock prices can be accomplished by examining previous price and volume trends [29].
us, in technical analysis, characteristics such as peaks, bottoms, trends, and patterns all contribute to determining the stock's future value [28]. e main advantages of fundamental analysis are its structured evaluation and it offers superior long-term performance [30]. However, technical analysis might better predict the stock prices in the short-term [31][32][33], which is why traders frequently employ technical analysis [28]. Nevertheless, technical analysis is still criticised for its very subjective interpretation [34].
Researchers employed various conventional and digital computing prediction models. ese models may incorporate different explanatory input variables from the fundamental and technical analysis [35]. e CAPM (Capital Asset Pricing Model) [36] is a well-known example of a conventional structural model [37]. CAPM describes the relationship between stock return including its risk and market return. e Arbitrage Pricing eory (APT) expanded the relationship and described the relationship between a stock return and some macroeconomic variables [38,39].
Other structural models can be classified as linear or nonlinear. Linear models include the linear-trend prediction model [40] and the exponential smoothing model, which assigns exponentially decreasing weights for time series prediction [41]. Additionally, the Autoregressive Integrated Moving Average (ARIMA) model gained momentum and is still widely regarded as a significant contribution to time series prediction. A key shortcoming of linear models is their inability to capture nonlinear trends in the data. Nonlinear models, such as GARCH (Generalized Autoregressive Conditional Heteroscedasticity), address this issue.
Some research suggests that nonlinear models might outperform linear models [42]. However, these studies are not conclusive and do not exclude the possibility that the opposite might occur [43].

Computational Intelligence and Neuroscience
Several studies have utilised the recent advancements in soft computing techniques and artificial intelligence to improve prediction model performance in forecasting the stock market [20,24]. Soft computing methods for stock price prediction can capture and better handle the stock market's uncertain, noisy, and nonlinear patterns. Recently, these techniques have become more popular as they give a more accurate stock market prediction [44]. Artificial neural networks (ANNs) are soft computing models that mimic basic human brain processes in the central nervous system [44,45]. e architecture of neural networks can be divided into different categories depending on the neuron's network layers and positions [46].
Various ANN training algorithms are available, each with its own benefits and drawbacks. Levenberg-Marquardt (LM), Bayesian Regularization (BR), and Scaled Conjugate Gradient (SCG) are three training algorithms that have been utilised successfully for stock market data prediction in prior studies [47][48][49].
e characteristics of the problem to be solved influence the choice of an ANN model. e feedforward neural network, for example, may not perform well if the input data pattern changes over time. A viable solution is to utilise a recurrent neural network (RNN), in which neurons have additional connections to the prior layer [50,51].
is study employs a nonlinear autoregressive network with exogenous inputs (NARX), a type of recurrent neural network with high prediction capabilities for time series data. Given that the stock price prediction problem incorporates historical data as well as external variables, the NARX could be a compelling choice for modelling such a problem [49,[52][53][54][55][56][57].
A comparison of the prediction performance of the NARX model with other neural network models for the Indonesian stock index was carried out by [58] over a five-day forecasting period. e NARX model outperforms other neural network models' mean square error (MSE) performance. Similarly, in [53] research, predicting the NASDAQ closing price using a NARX prediction model outperforms other models such as VAR (vector autoregressive), ARIMA, and LSTM models.
In another recent study, Gandhmal

Methodology
e main objective of this study is to compare and analyse the performance of an adaptive nonlinear autoregressive exogenous (NARX) neural network model that incorporates lagged pricing and technical indicators with two previously published models [26,27]. e design of a neural network model for forecasting is a challenging endeavour due to the large number of parameters that may be altered to affect the performance of the ANN. Some of these parameters are associated with the selection and preprocessing of input data. Additional parameters related to neural network architecture include the number of hidden layers, the number of neurons, and the training algorithm. Furthermore, evaluation of the neural network requires selecting some performance measures.
is section discusses the experimental setup, including the model parameters used to perform the experiments. e first step is to collect data on CIMB stock and then compute the technical factors. After that, the data is filtered and normalised during the preprocessing stage. e data is then partitioned into input and test sets, which are then fed into the NARX neural network model.
Following that, the prediction model is constructed, and its parameters are adjusted, after which the model is put through a series of trials to determine its performance. Finally, all experiments' output results are saved for further evaluation and comparison. e overall methodology is depicted in Figure 1, and the subsequent sections describe each stage in further detail.

Data Collection and Preprocessing.
e NARX model input data includes the CIMB stock adjusted closing prices and three-day lagged data, as well as six calculated technical variables: momentum, MACD, RSI, oscillator, WPCTR, and CHVOL. For technical factors (refer to Table 1), an arbitrary combination is used in the experiments because no prior knowledge exists regarding which combination will perform better.
CIMB stock data was obtained from the Yahoo Finance website for a ten-year period (2 nd Jan., 2008 to 29 th Dec., 2017). Two thousand three hundred thirty-three observations were included in the CIMB stock information dataset (trading days). Each observation included daily data on the lowest and highest prices, the opening and closing prices, and trading volume. Based on this, three subsets of the ten-year dataset were constructed (five years, three years, and one year).
After collecting the data, it was analysed to identify and eliminate any missing or erroneous values. Observations with missing, zero, or null closing prices correspond to days when no trading happens due to weekends, holidays, or other events, and these were all excluded from the datasets. Technical indicators are calculated during the preprocessing stage, and the data is subsequently normalised and smoothed, as described below.

Calculating Technical Variables.
Six technical indicators for the CIMB stock were calculated using the collected data. e following are the technical indicators that were chosen and their formulas: is indicator recognises price movement in terms of strength and speed by measuring the price (P) change rate. It is calculated by determining the difference between the current and past prices over an n-period.
Computational Intelligence and Neuroscience (1) In the calculation, the frequently adopted value of n � 12 [50] is used. In MATLAB, MOM is calculated using the built-in function tsmom.
(2) Moving Average Convergence Divergence (MACD). Another momentum indicator for trending stock price data is MACD. It depicts the relationship between two stock price moving averages (the 26th and 12 day exponential moving averages) [60]. e macd MATLAB function is used to calculate MACD.
(3) Relative Strength Index (RSI). e relative strength index (RSI) measures the magnitude and velocity of stock price changes [60]. RSI is computed in MATLAB using the rsindex function.
(4) On-Balance-Volume (OBV). OBV measures stock momentum by relating volume and stock price changes [60]. e onbalvol function in MATLAB is used to calculate OBV.

(5) Williams' Percent Range (Williams' %R) or (WPCTR).
is technical indicator is used to determine whether or not a stock is oversold or overbought in the market [60]. e calculations in this study were based on a 14 day period. WPCTR % R is calculated in MATLAB using the willpctr function.
(6) Chaikin Volatility (CHVOL). CHVOL is used to compare the spread between a stock's high and low prices by quantifying the volatility based on the changes of the moving average over a specific period. In this study, MATLAB's chaikvolat function was used to calculate CHVOL.

Normalization and Smoothing.
After calculating the technical indicators, the data is preprocessed using the smoothing and normalisation transformation techniques to improve the prediction outcomes [46]. e CIMB adjusted closing price data was smoothed using a five-day Exponential Moving Average (EMA) to minimise daily data's noisy and erratic effects. en the input data that includes the smoothed CIMB stock's adjusted closing price and the calculated technical indicators are normalised to zero mean and unit variance [50].

Building the Prediction Model.
is study employed a single-layered neural network structure of a nonlinear autoregressive exogenous (NARX) model. e NARX model uses a single hidden layer because single-layer models often give better prediction results and are more practical due to their ability to reduce computation time and reduce the risk of overfitting, which can degrade prediction performance [50,61]. e following steps describe how the NARX model's parameters were set and optimised in MATLAB.

Selecting Initial Model Parameters.
e absence of a systematic method for determining the appropriate quantity of inputs that can affect the learning performance of neural networks is unfortunate [42]. Consequently, numerous parameters were investigated and tested in this study to optimise model performance, including the following: (1) Data size. CIMB closed price data for (one, three, five, and ten) years.
(2) Inputs. e model's inputs are CIMB closing price data and exogenous variables (technical factors), which were combined in arbitrary combinations by adding one variable at a time. No    the experiments. Additionally, the model was supplied with lagged data of the CIMB closing price and the exogenous variables. e number of lags varied; both the closing price and exogenous input lags ranged between 0 and 3.
(3) Data split. Two datasets were created from the input data. e first 90% of data was utilised as the neural network's input dataset, while the remaining 10% was unknown to the model and was used as a testing dataset and not for training. e 90% input dataset was then split into three segments, 70% training data, 15% testing data, and the remaining 15% was validation data (see Figure 2). e data split used in this arrangement was chosen based on the author's work [50].

Determining the Best Number of Neurons.
In the neural network design process, the number of input and output neurons is chosen based on the data used to solve the problem (i.e., the input features and outputs). ere is no consensus on the optimal number of hidden neurons although some literature gives rules of thumb that can be utilised as a jumping-off point for experiments. e use of a fixed technique, in which the number of hidden neurons is changed while keeping all other parameters constant, can be used to identify the optimal number of neurons, resulting in the minimization of errors, the prevention of overtraining, and the avoidance of local minima. During the training phase, this study optimised by using a variety of different numbers of neurons. e range of neurons employed in the search for the optimal number of neurons was based on [50,62], in which the maximum number of neurons is determined by the number of inputs and outputs as stated in equations (2) or (3).
No.of neurons � 2 × no.of inputs + 1, where n i � number of inputs, n o � number of outputs.

Determining the Best Neural
Network. Different parameter combinations were tested in order to identify the optimal neural network for the study model in terms of prediction accuracy as measured by mean square error (MSE). ree different training algorithms were used with both the training and testing sets, including the Levenberg-Marquardt algorithm (trainlm), Bayesian Regularization (trainbr), and Scaled Conjugate Gradient (trainscg). e Leveneberg Marquardt algorithm (LM) is a more powerful optimization than the gradient descent [61,62]. It outperforms both conjugate gradient and variable learning rate algorithms in neural networks of moderate size [63]. Bayesian Regularization is a training technique that updates the weight and bias values using Levenberg-Marquardt optimization. It minimises a combination of square errors and weights and determines the ideal combination for constructing a well-generalized network [64]. e scaled conjugate gradient algorithm (SCG) was introduced by [65] as a rapid training algorithm that removes the time spent online searches and combines the conjugate gradient and model-trust region approaches. ese three training algorithms were identified to be dominant training algorithms in the stock market prediction field, with exceptional performance [48,49,66]. e random initialization of biases and weights is another issue to consider when designing neural networks, as two networks with identical designs and parameters might generate different results (Fang et al., 2014). is issue was addressed in this study by training many networks and picking the one with the lowest mean square error.
Moreover, to avoid overfitting, the neural network is first trained on a large part of the data sample and then tested on the remaining, smaller part to see if it can generalise what it learned during training when met with unknown data. Figure 3 compares the model's performance on both insample and out-of-sample forecasts in terms of adjusted R 2 .

Setting UP the Model.
After setting the initial model parameters and selecting the optimal number of neurons and neural network, the final model is constructed and prepared for testing with various combinations of exogenous factors and input dataset durations.

Running the Model.
ree cascading loops were utilised to run the model and test all potential combinations efficiently. e first loop modifies the amount (duration) of data inputs (one year, three years, five years, and ten years). e second loop is responsible for selecting the training algorithms (trainlm, trainbr, and trainscg). Finally, the third loop selects various exogenous variable combinations (technical factors). In each iteration of these loops, the model is run on the training dataset then the test dataset.

Performance Evaluation.
e test data was used to evaluate the model's performance using three widely used performance metrics: mean square error (MSE), hit rate (HR), and R-squared coefficient of determination (R 2 ) [27,67] (Gan et al., 2019). ese three metrics were computed for the training and testing datasets, respectively. MSE is dependent on the data type and order of magnitude and is calculated as follows: where x i denotes the actual data for the i th observation (out of N observations), and x i denotes the model forecasted data.
Hit rate (HR) measures the prediction accuracy by calculating the percentage of correct movement of the predictions either up or down. e R 2 (R-squared coefficient of determination) is also used to indicate the prediction accuracy as it measures the percentage of the response variable variation explained by the model [68]. R 2 is calculated using the following equation: Computational Intelligence and Neuroscience where n denotes the total number of data points, y denotes the predicted value and y denotes the average value of actual output, and y i denotes the actual output [69].

Results and Discussion
A total of 72 experiments were conducted to evaluate the developed ANN-NARX model's performance in predicting the CIMB stock closing price, with each experiment incorporating a different combination of data size (duration), exogenous variables (technical indicators), training functions (algorithms), and the optimal number of neurons. As stated in Table 1 Figure 4 shows that the one-year duration performed lower than the other durations in terms of average MSE and average hit rate, which could be attributed to the model being trained on an inadequate amount of historical data to provide accurate predictions. e model's performance significantly improved as the amount of data used as input was raised to three years. However, there was no evidence of a significant improvement in the model's performance when the data set was increased to five and ten years.
As for the training algorithms illustrated in Figure 5, the Levenberg Marquardt algorithm (trainlm) and Bayesian Regularization (trainbr) both displayed slightly higher performance (in terms of average MSE) when compared to the Scaled Conjugate Gradient (trainscg) algorithm. On the other hand, the (trainlm) algorithm achieved the best overall averages in both MSE and Hit Ratio.
Regarding the number of neurons in the neural network, as indicated in Figure 6, the highly fluctuating results indicate that the number of neurons has no definitive effect on the model performance.
Additionally, Figure 7 shows that the combination of exogenous factors (MOM, MACD, and RSI) achieved the lowest MSE result. Increasing the number of technical factors in the prediction model had little effect on the R 2 while degrading the average MSE and hit rate.

Experiment Number
In-sample Adj R2 Out-of-sample Adj R2         Computational Intelligence and Neuroscience paired with more technical indicators, as illustrated by combining Figures 5 and 6, the performance was generally degraded in terms of the average MSE.

Model Performance Compared to Prior Studies.
As shown in Table 6, the proposed NARX-model significantly increased forecast accuracy in terms of mean square error (MSE) when compared to the model proposed by [26,27]. e proposed model's best and mean MSE values are lowered to (0.0003955) and (0.000618044), respectively, compared to (0.02198) for the best and (0.03149) for the mean MSE in [26,27].
is improvement could be attributed to incorporating technical factors and preprocessing, which includes data smoothing using moving averages and optimization of the proposed model's parameters.

Conclusion and Future Work
In this study, the problem of stock market prediction is examined for a selected stock on the Malaysian stock exchange. e prediction of the CIMB stock closing price one step ahead was investigated using technical variables in a NARX neural network. e prediction performance was improved by including technical variables as exogenous inputs to the model, preprocessing the input data, and optimising the neural network's input variables and parameters. e model proposed in this study outperformed two other models previously published in the literature in terms of hit rate and MSE. e results suggest that including technical indicators into the NARX neural network model has a high potential for improving prediction performance and is demonstrated by examining performance indicators such as MSE, Hit rate, and R 2 .
In this study, only three training algorithms (trainlm, trainbr, and trainscg) were examined. To further improve prediction performance, it may be useful to investigate other widely used training algorithms such as, gradient descent and gradient descent with momentum in future studies.
Additionally, this study only considered the use of technical indicators as exogenous variables in the NARX model arbitrarily for only one stock in the Malaysian stock market. In future works, it might be beneficial to optimise the selection of the exogenous variables by using advanced features selection methods such as, deep mining and exploring the use of integrating fundamental factors to improve the prediction for different stocks in the market.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.