3.2.1. ARIMA(p,d,q) Models

The time series analysis requires the stationarity of the data, meaning the statistical properties such as mean, variance, and so on do not change over time. However, most of the real-world data, like stock data, are non-stationary by nature. This non-stationarity can be taken care of by using the Box–Jenkins *ARIMA(p,d,q)* approach (Makridakis and Hibon 1997). A time series {*Yt*} is said to follow an *Autoregessive Integrated Moving Average ARIMA(p,d,q)* if the *d*th difference *Wt* = ∇*dYt* is a stationary *ARMA*(*p*, *q*) process (Cryer and Kellet 1991). A generalised *ARIMA*(*p*, *d*, *q*) model can be written as

$$\mathcal{W}\_t = \phi\_1 \mathbb{W}\_{t-1} + \phi\_2 \mathbb{W}\_{t-2} + \dots + \phi\_p \mathbb{W}\_{t-p} + \varepsilon\_t + \theta\_1 \varepsilon\_{t-1} + \theta\_2 \varepsilon\_{t-2} + \dots + \theta\_q \varepsilon\_{t-q} \varepsilon\_t$$

where *φ*1, *φ*2, ... , *φp* and *θ*1, *θ*2, ... , *θq* are the autoregressive and moving average parameters, respectively, and *es* are the white noise. The autoregression *AR*(*p*), order *p*, and moving average *MA*(*q*), order *q*, are determined from the analysis of the autocorrelation function. The number *d* indicates the number of differences applied to the time series to remove the trend. The autoregressive parameters *φs* and moving average parameters *θs* are estimated from the model based on *p*, *d*, and *q*.

### 3.2.2. ARIMA(p,d,q) Model for S & P 500 Index

The adjusted close price of S & P 500 is a time series process {*Xt*} that has been analysed to build the model. The process {*Xt*} is not a stationary process, if we see the following graphs.

Figure 1 shows an upward trend in the data. Inspecting the sample autocorrelation plot from Figure 2, it is clear that the Auto Correlation Function (ACF) dies down very slowly and the Partial Autocorrelation Function (PACF) cuts off at lag 1 with correlation one.

**Figure 1.** Time plot of the raw data.

**Figure 2.** Sample autocorrelation plot.

The slow dying-down nature of the ACF indicates that the process is non-volatile. That is, the current value is relating with all the past values. These facts ensure the process is non stationary. To make the process stationary, we transform the {*Xt*} series to the {*Yt*} = {log *Xt*} series and then to a new series {*Wt*} = {∇<sup>2</sup>*Yt*}, where *Wt* = *Yt* − 2*Yt*−<sup>1</sup> + *Yt*−2.

Figure 3 is the window plot of the second differenced log transformed stock price. From this plot, the data looks stationary and randomized. Stationarity has been confirmed from the augmented Dickey–Fuller test (Cheung and Lai 1995) with a *p* value of 0.01, where the alternative hypothesis was stationary. Next, the autoregressive and moving average orders *p* and *q* were determined from the PACF and ACF plot from Figure 4.

**Figure 3.** Window plot of the second differenced log transformed stock price.

**Figure 4.** ACF and PACF of the second differenced log transformed stock price.

The ACF cuts of at lag 1 which indicates that the process incorporates an *MA* process of order *q* = 1 whereas the PACF gradually dies down. Therefore, the series *Wt* follows an *MA*(1) process or the series *Yt* follows an *IMA*(2, 1) process i.e. *Yt* ∼ *ARIMA*(0, 2, <sup>1</sup>). Other *ARIMA*(*p*, *d*, *q*) models were also considered in this research, as shown in Table 1. The best model has been chosen based on the *Schwarz Bayesian Information Criterion* (BIC) (Neath and Cavanaugh 2012) criteria, the more negative, the more accurate model. The reason of not choosing *Akaike Information Criterion* (AIC) or *Bias Corrected Akaike Information Criterion* (AICc) is that those models provide over-fitting and non significant parameters.

From Table 1, the *ARIMA*(0, 2, 1) model has the most negative BIC value which fits the data most perfectly. The *Arima* function with order (*p*, *d*, *q*)=(0, 2, 1) was run in RStudio and the summary of the model is displayed in Table 2.


**Table 1.** ARIMA (p,d,q) model comparison.

**Table 2.** ARIMA(0,2,1) model summary.


The model in difference equation is given as

$$\begin{aligned} \mathcal{W}\_t &= \mathfrak{e}\_t + \theta \mathfrak{e}\_{t-1} \\ \nabla^2 \mathcal{Y}\_t &= \mathfrak{e}\_t + \theta \mathfrak{e}\_{t-1} \end{aligned}$$

$$\begin{aligned} \mathcal{Y}\_t - 2\mathcal{Y}\_{t-1} + \mathcal{Y}\_{t-2} &= \mathfrak{e}\_t + \theta \mathfrak{e}\_{t-1} \\ \mathcal{Y}\_t &= 2\mathcal{Y}\_{t-1} - \mathcal{Y}\_{t-2} + \mathfrak{e}\_t + \theta \mathfrak{e}\_{t-1} \end{aligned} \tag{2}$$

Finally, substituting the *MA* parameter *θ* = −1 in Equation (2), the model for *Yt* = log *Xt* is given as

$$
\Upsilon\_t = 2\Upsilon\_{t-1} - \Upsilon\_{t-2} + \varepsilon\_t - \varepsilon\_{t-1}.\tag{3}
$$

A fixed window of 1194 past observed stock prices have been used to predict each of the next-day prices using the model in Equation (3). Hence, the training dataset moved and the end price of the

window was updated with the actual price. The results and diagnostics of this model are discussed in Section 4.1.

### *3.3. Stochastic Model Geometric Brownian Motion*

A process that generates some outcomes which are time-dependent but can not be said ahead of time is known as a *stochastic process*. A stochastic process {*W*(*t*) : 0 ≤ *t* ≤ *T*} is a standard Brownian motion on [0, *T*] if


A stochastic process {*X*(*t*) : 0 < *t* < *T*} is said to be a general Brownian motion with a drift parameter *μ* and diffusion coefficient *σ*<sup>2</sup> if *<sup>X</sup>*(*t*)−*μ<sup>t</sup> σ* is a standard Brownian motion, written as *X*(*t*) ∼ *BM*(*μ*, *<sup>σ</sup>*<sup>2</sup>).

The general Brownian motion still follows first two properties of the standard Brownian motion. However, the third property is modified as *X*(*t*) − *<sup>X</sup>*(*s*) ∼ <sup>N</sup>(*μ*(*<sup>t</sup>* − *s*), *σ*<sup>2</sup>(*<sup>t</sup>* − *s*)) for any 0 ≤ *s* < *t* < *T*.

### 3.3.1. Geometric Brownian Motion (GBM) Model

If *X*(*t*) ∼ *BM*(*μ*, *σ*<sup>2</sup>) then *X*(*t*) satisfies the stochastic differential equation (Yang and Aldous 2015)

$$dX(t) = \mu t + \sigma dW(t),\tag{4}$$

where, *W*(*t*) is the standard Brownian motion or Wiener process. If the stochastic process is defined as *X*(*t*) = log *S*(*t*) then *dS*(*t*) = *μ<sup>S</sup>*(*t*)*dt* + *σ<sup>S</sup>*(*t*)*dW*(*t*) is the stochastic differential equation for the stock price random process.

For a given time *t* > 0, the standard model for stock prediction can be given from the stochastic differential equation by integration

$$\mathcal{S}(t) = \mathcal{S}(0) + \mu \int\_0^t \mathcal{S}(r) dr + \sigma \int\_0^t \mathcal{S}(r) dW(r). \tag{5}$$

A more explicit formula can be derived using Ito's formula (Ševcovic et al. 2011) to the function *F*(log *<sup>S</sup>*(*t*), *t*)

$$dF = \left[\frac{\partial F}{\partial t} + \mu \frac{\partial F}{\partial S(t)} + \frac{1}{2} \sigma^2 \frac{\partial^2 F}{\partial^2 S(t)}\right] dt + \left(\sigma \frac{\partial F}{\partial S(t)}\right) d\mathcal{W}(t),$$

which results

$$\begin{split} d\log S(t) &= \frac{1}{S(t)} dS(t) + \frac{1}{2} \frac{-1}{S^2(t)} (dS(t))^2 \\ &= \mu dt + \sigma dW(t) + \frac{1}{2} \frac{-1}{S^2(t)} (\mu S(t) dt + \sigma S(t) dW(t))^2 \\ &= (\mu - \frac{1}{2}\sigma^2) dt + \sigma dW(t). \end{split}$$

For any time *t* > 0, the differential can be written as

$$\log S(t) = \log S(0) + (\mu - \frac{1}{2}\sigma^2)t + \sigma W(t)$$

$$\text{Or, }\ S(t) = S(0)e^{(\mu - \frac{1}{2}\sigma^2)t + \sigma W(t)}.\tag{6}$$

3.3.2. Geometric Brownian Motion Model for S & P 500 Index: GBM(*μ*, *σ*2) Simulation

For a given time set, *t*0 = 0 < *t*1 < *t*2 < ... < *tn*, the stock price *S*(*t*) at time *t*0, *t*1, ... , *tn* can be generated by

$$S(t\_{i+1}) = S(t\_i)e^{(\mu - \frac{1}{2}\sigma^2)(t\_{i+1} - t\_i) + \sigma\sqrt{(t\_{i+1} - t\_i)}Z\_{i+1}}\tag{7}$$

where *Z*1, *Z*2, ... *Zn* are independent and identically distributed standard normals and *i* = 0,(*n* − <sup>1</sup>). In our case, the time interval *ti*+<sup>1</sup> − *ti* = 1 for all *i* = 0,(*n* − <sup>1</sup>), since we are predicting the next-day price. Hence, the model becomes

$$S(t\_{i+1}) = S(t\_i)e^{(\mu - \frac{1}{2}\sigma^2) + \sigma Z\_{i+1}}.\tag{8}$$

Using the model in Equation (8), we simulate a large number of prices, and from that we take the average to predict the next-day price. For our data, this large number is 100, 000. A total of 63 predictions have been made using this model. A fixed window of 1194 past observed stock prices have been used to predict each of the next-day prices. Hence, the training dataset moved, and the end price of the window was updated with the actual price. The results and diagnostics of this model are discussed in Section 4.2.

### *3.4. Artificial Neural Network*

This section describes how an artificial neural network can be used to predict the stock price and how to build a model based on the stock data for S & P 500 index.
