A Markov Regime Switching Approach of Estimating Volatility Using Nigerian Stock Market

Understanding and forecasting the behavior of volatility in stock market has received significant attention among researchers and analysts in the last few decades due to its crucial roles in financial markets. Portfolios managers, option traders, and market makers are all interested in the possibility of forecasting, with a reasonable level of accuracy. This study examined the volatility on the Nigeria stock market by comparing two Markov regime switching Autoregressive (MS-AR) Models estimated at different lagged values using the Nigeria stock exchange monthly All Share Index data from 1988 to 2018 in the Central Bank of Nigeria (CBN) Statistical Bulletin. It was found that factors like financial crisis, information flow, trading volume, economical aspects and investor’s behavior are the causes of volatility in the stock market. The results and forecasts obtained from the statistical analysis in this research showed that the stock market will experience a steady growth in 2020 and beyond. Also, the stock market is experiencing fluctuations in the price indices which show that over the years, investors have been exposed to some certain risks in the time past. We therefore recommended that researchers should focus more attention in developing robust statistical model that will reflect and continue to monitor future trends and realities.


Introduction
The importance of understanding and forecasting the behavior of volatility in stock market has received significant attention among researchers and analysts in the last few decades due to its crucial roles in financial markets. Portfolios managers, option traders, and market makers are all interested in the possibility of forecasting, with a reasonable level of accuracy. Volatility prediction is a critical task in asset valuation and risk management for investors and financial intermediaries. The price of almost every derivative security is affected by swings in volatility.
A financial market often changes patterns over time. It can also exhibit dramatic changes due to unexpected events such as natural hazards and financial crisis. A widely accepted fact is that financial markets behave quite differently in different economic situations. Traders often adjust their portfolios according to market trend, which is defined as the long term tendency of a financial market to move in a certain direction. A financial market is traditionally classified into 3 categories: bearish, bullish and neutral. The first two terms describe overall market gain and loss respectively. The term neutral market is used when no strong upward or downward trend is observed. Several benefits can be derived from generating accurate forecast of volatility. Volatility forecast is a key indicator in assessing the performance of the stock market in order for both indigenous and foreign speculators to make accurate speculations and decisions on investments.
The issue with volatility of stock market price refers to the fluctuations that may be observed in stock market prices over time. The major reason for the ups and downs in the stock market may be traced to macroeconomic instability. Since the stock market operate in a macroeconomic environment, it is therefore necessary that the environment must be an enabling one in order to realize its full potentials. The problem with forecasting the stock market price is that the return distribution can change considerably over time. Volatility is an extremely complex thing to forecast because of the inherent instability of the variable (variability of the random). Volatility forecast sometimes may be uncertain, since it is just a mere projection based on some econometric technique in most cases. Estimating Volatility Using Nigerian Stock Market The Markov regime switching model is a popular approach, much on behalf of the way it takes the shifts in the time series behavior into account and the way it is able to capture more complex dynamic patterns. What separates the Markov regime switching model from other switching models is that the switching mechanism is controlled by an unobservable variable that follows a hidden Markov chain. By Markov properties, the current value of the variable depends only on its immediate past value. This means that a structure in the series may prevail for a random period of time, before being replaced by another structure when a switching takes place. This way, the Markov regime switching model is able to capture more complex dynamic patterns. [1] stated that a way to model non-linear dynamic patterns in time series such as breaks or asymmetry is through the use of Markov switching models. It has been found that financial time series exhibit some formalized facts which can advantageously be reproduced by a hidden Markov model. This has made the Markov regime switching model one of the most popular nonlinear time series models in the literature [2,3,4,5]. Investors are skeptical especially when it comes to investment, as they require that sense of security that they will attain a return on their investment. Hence, the need of a framework where the potential investors has access to relevant information pertaining to the stock market, so that they are able to conduct their personal research and choose the optimal stocks in the market. According to [6], stock market indexes provide guidance concerning the performance of the overall stock market. Therefore, in this study, volatility assessment and forecast are carried out on All Share Index (ASI) of the Nigeria Stock Exchange (NSE) in order to examine the performance of the Nigeria Stock Market. The All Share Index (ASI) on the Nigeria Stock Exchange (NSE) is used as proxy for stock market prices in order to assess volatility by measuring the trends and thereby examining the performance of the Nigeria Stock Market. This research will examine this issue from the perspective of the Markov regime switching model. A number of studies have used such an approach in volatility forecasting and have found that particularly for inherent instability of the variable (variability of the random), the regime switching models do provide a good forecasting ability. The broad objective of this study is to assess the volatility performance of the Nigeria Stock Market in order to determine the basis for examining its forecast.

Data
The data used for this research was sourced from the Central Bank of Nigeria statistical bulletin [7].

Method
This section introduces and explains which statistical tool was deployed in analyzing data and upon what frame work was the conclusion based on. Statistical tools like time series will be deployed in analyzing the data set with the aid of statistical package E-Views also the graphical aspect.

Nonlinear Time Series
Traditional time series analysis is based on assumptions of linearity and stationarity. However, there has been a growing interest in studying nonlinear and non-stationary time series model in many practical problems. The first and the simplest reason for this is that many real world problems do not satisfy the assumptions of linearity and/or stationarity. For example, the financial markets are one of the areas where there is a greater need to explain behaviors that are far from being even approximately linear. Therefore, the need for the further development of the theory and application for nonlinear models is essential. In general time series analysis, it is known that there are a large number of nonlinear features such as cycles, asymmetries, bursts, jumps, chaos, thresholds, heteroscedasticity and mixtures of these have to be taken into account. A problem arises directly from a suitable definition of nonlinear model because not every model is linear. This class clearly encompasses a large number of possible choices. Furthermore, forecasting the future values of an observed time series is an important phenomenon for many real world problems. It provides a good basis for production planning and technical decisions. Forecasting means extrapolating observations available up to time t to predict observations at future times. Forecasting methods are mainly classified into quantitative techniques, which are based on unscientific and mathematical and/or statistical models respectively. The quantitative techniques are more important than qualitative techniques for future planning.

Test of Nonlinearity
Given the wide range of nonlinear time series models available and the inherent flexibility of these models, the possibility of getting a spuriouslygood fit to any time series data set is very high. Therefore it is usually recommendedto perform a test of linearity against nonlinearity before buildinga possibly complex nonlinear model.
A popular test for nonlinearity, the BDS test, which has been found to have power against a wide range of nonlinear time series models, will be used to determine whether a nonlinear model is suitable for the data. There are many other types of nonlinearity tests that are developed to test against specific nonlinear models.
BDS Test for Nonlinearity The BDS test developed by [8] was originally designed to test for the null hypothesis of independent and identical distribution (iid) for the purpose of detecting non-random chaotic dynamics. However, many studies have shown that BDS test has power against a wide range of linear and nonlinear alternatives [9].
Linear vs. nonlinearity choice can be made partly on statistical grounds deciding whether a linear specification is sufficient to describe all of the most important features of the data at hand.
Thus, the null and alternative hypothesis of the BDS test for detecting nonlinearity is as follows; : The series are linearly dependent : The series are not linearly dependent.
The BDS test is based on an integral correlation of the series and is defined as follows; Where M is the surrounded points of the space with m dimension, r denotes the radius of the sphere centered on the , is the constant and . is the standard deviation of √ − .

Selection Criteria
It is not all that possible to identify the parameter p of the Markov Switching Autoregressive (MS-AR) process by visualization. The most common model selection criteria are the AIC, BIC. Using the AIC and BIC criterion, we select the Markov Switching Autoregressive model with the lowest value of the AIC or BIC.

The Akaike Information Criteria (AIC)
The Akaike information criterion (AIC) was the first selection criterion to gain widespread acceptance. AIC was introduced in 1973 by [10] as an extension to the maximum likelihood principle. Akaike's seminal idea was to combine estimation and structural determination into a single procedure. Given a family of candidate models of various structures, each model is fit to the data through maximum likelihood. An AIC is computed based on each model fit. The fitted candidate model corresponding to the minimum value of AIC is then selected; one is hoping to identify the fitted model that is closest to the generating model. The AIC is defined by

Bayesian Information Criterion (BIC)
The Bayesian information criterion (BIC) also known as the Schwarz information criterion (SIC) is related to the Bayes factor and useful for model comparison in its own right.
The BIC of a model is defined as

Markov Regime Switching Model
A basic time series model that will be used in describing the Markov Regime Switching model is the Autoregressive Process (AR) defined below: Definition: Autoregressive Processes AR (p) The idea behind the autoregressive models is to explain the present value of the series, . , by a function of the past values, . , . 0 , . . . , . 1 .
Suppose that at date > there was a significant change in the average level of the series, so that we would instead wish to describe the data according For > = > + 1, > + 2, … This fix of changing the value of the intercept from < >) < 0 might help the model to get back on track with better forecasts, but it is rather unsatisfactory as a probability law that could have generated the data. We surely would not want to maintain that the change from < >) < 0 at date > was a deterministic event that anyone would have been able to predict with certainty looking ahead from date > = 1. Instead there must have been some imperfectly predictable forces that produced the change. Hence, rather than claim that expression (5) governed the data up to date > and (6) after that date, what we must have in mind is that there is some larger model encompassing them both, ; . = < : A + 2; . + 4 . , where B . is a random variable that, as a result of institutional changes, happened in our sample to assume the value B .
Assuming that we do not observe B . directly, but only infer its operation through the observed behavior of ; . , the parameters necessary to fully describe the probability law governing ; . are then the variance of the Gaussian innovation 0 , the autoregressive coefficient 2 , the two intercepts < and < 0 , and the two state transition probabilities, G and G 00 .
The specification in (8) assumes that the probability of a change in regime depends on the past only through the value of the most recent regime, though, as noted below, nothing in the approach described below precludes looking at more general probabilistic specifications. But the simple timeinvariant Markov chain (8) seems the natural starting point and is clearly preferable to acting as if the shift from < to < 0 was a deterministic event. Permanence of the shift would be represented by G 00 = 1 , though the Markov formulation invites the more general possibility that G 00 < 1. Certainly in the case of business cycles or financial crises, we know that the situation, though dramatic, is not permanent. Furthermore, if the regime change reflects a fundamental change in monetary or fiscal policy, the prudent assumption would seem to be to allow the possibility for it to change back again, suggesting that G < 1 is often a more natural formulation for thinking about changes in regime than G 00 = 1.
The probability of switching is captured in the matrix P known as a transition matrix.
Where G + G 0 = 1 and G 0 + G 00 = 1 Suppose that we observe ; . directly but can only make an inference about the value of B . based on what we see happening with ; . . This inference will take the form of two probabilities for E = 1,2, where these two probabilities sum to unity by construction.
Here Ω . = {; . , ; . , ; , ; } denotes the set of observations obtained as of date > , and P is a vector of population parameters, which for the above example would be P = ( , 2, < , < 0 , G , G 00 ) Q , and which for now we presume to be known with certainty. The inference is performed iteratively for > = 1,2, … , R with step > accepting as input the values for % = 1,2 and producing as output (10). The key magnitudes one needs in order to perform this iteration are the densities under the two regimes, for E = 1,2. Specifically, given the input (11) we can calculate the conditional density of the >th observation from T(; . |Ω . ; P) = ∑ ∑ G H M ,. S H. 0 H_ 0 _ (13) and the desired output is then As a result of executing this iteration, we will have succeeded in evaluating the sample conditional log likelihood of the observed data logT(; , ; 0 , … , ; g |; ; P) = ∑ logT(; . |Ω . ; P) g ._ (16) Other alternatives are simply to set M = 1/2 or estimate M itself by maximum likelihood.
The calculations do not increase in complexity if we consider an ( × 1) vector of observations ; . whose density depends on N separate regimes. Let Ω . = {; . , ; . , … , ; } be the observations through date t, P be an (N ×N) matrix whose row j, column i element is the transition probability G H , S . be an (N × 1) vector whose jth element T(; . |B . = E, Ω . ; P) is the density in regime j, and M j .|. an (N × 1) vector whose jth element is Pr (B . = E|Ω . , P). Then (13) and (14) where 1 denotes an (N × 1) vector all of whose elements are unity and ⊙ denotes element-by-element multiplication.
There further is no requirement that the elements of S . be Gaussian densities or even from the same family of densities.
One is also often interested in forming an inference about what regime the economy was in at date t based on observations obtained through a later date T, denoted M j .|g . These are referred to as "smoothed" probabilities. The calculations in (17) and (18)  Nturns out also to be a natural device for handling transition probabilities that are functions of observable variables. It is natural to want to test the null hypothesis that there are N regimes against the alternative of N + 1, for example, when N = 1, to test whether there are any changes in regime at all. Unfortunately, the likelihood ratio test of this hypothesis fails to satisfy the usual regularity conditions, because under the null hypothesis, some of the parameters of the model would be unidentified. For example, if there is really only one regime, the maximum likelihood estimate Ĝ does not converge to a well-defined population magnitude, meaning that the likelihood ratio test does not have the usual r 0 limiting distribution. To interpret a likelihood ratio statistic, one needs to rely on generic tests of the hypothesis that an N-regime model accurately describes the data, though these tests are not designed for optimal power against the specific alternative hypothesis of N + 1 regimes. Other alternatives are to use Bayesian methods to calculate the value of N implying the largest value for the marginal likelihood or to compare models on the basis of their ability to forecast.
Then B . * itself follows a 4-state Markov chain with transition matrix More problematic are cases in which the order of dependence m grows with the date of the observation t. Such a situation often arises in models whose recursive structure causes the density of ; . given Ω . to depend on the entire history ; . , ; . 0 , … , ; as is the case in ARMA, GARCH, or state-space models.
If J H > 0, then state • is said to communicate with state • H such that a two way communication is possible, and if additionally J H > 0, then • ↔ • H . Transition probabilities form an s × s array that can be combined into a transition matrix T. If ∑ G H = 1 H_ , then T is said to be row stochastic. For this study, a two state or regime process was assumed and the probabilities of the Markov process were represented in matrix form as follows: Where G + G 0 = 1, T) % = 1,2 and R = ƒ G G 0 G 0 G 00 " The specification in equation (22) assumes that the probability of a change in regime depends on the past only through the value of the most recent regime.

Expected Duration
We can determine the duration of each regime by using the diagonals elements of equation (9). These diagonal elements denote the transition probabilities of being in the same state both in the current and previous period. Using this information, we can find the average length of which a particular regime lasts on average.
Let H denote the number of periods the system is in state j. The probability to stay k periods in state j is given as follows: This implies the expected duration of state j is given by:

Forecasting
Forecasts for one period or several periods into the future with the parameters for a tentative model have been selected. The principal objective of developing a time series model for a variable is to generate post sample period forecast for the same variable. The ultimate test for any model is whether it is capable of predicting future events accurately or not. There is one problem with RMSE and it is that they may be close to 0 if large positive and negative errors cancel out each other. RMSE gives high weight to the large errors and are generally useful where large errors are not of importance. RMSE are more sensitive than other metrics to the infrequent large errors as the squaring process gives large weight to very large errors [11]. b) Mean Absolute Error (MAE) The problem of RMSE, canceling out of large positive and negative errors can be avoided by using Mean Absolute Errors. In average, MAE weights all the differences equally.
MAE and RMSE can be used together to study the variation in the errors in a set of forecasts. RMSE are always larger or equal than MAE. c) Mean Square Error (MSE) The sum of the squared forecast errors for each of the observations divided by the number of observations. It is an alternative to the mean absolute deviation (MAE), except that more weight is placed on larger errors. While MSE is popular among statisticians, it is unreliable and difficult to interpret. [12] found no empirical support for the use of the MSE or RMSE in forecasting. Fortunately, better measures are available [13].

Statistical Data Analysis and Discussion
This section presents the statistical analysis of our findings.

Time Series Graph of the Raw Data
Time series plots which display observations on the y-axis against equally spaced lag on the x-axis used to evaluate patterns and behaviors in data over time is displayed in Figure 1 below. The data used for this research was sourced from Central Bank of Nigeria Statistical Bulletin. Volatility in the Nigeria stock exchange has been experiencing instability over the years as presented in Figure  1 above. Clearly, Figure 1   Before the estimation of the Markov switching models, a nonlinearity test might still be necessary to describe the important features of the data at hand. Table 1 below, reports the results of the nonlinearity test developed by [8] on the All Share Index (ASI) data from the Nigeria Stock Exchange (NSE). The BDS test results in Table 1 above indicates that there is nonlinearity effect in the All Share Index of the Nigeria Stock Exchange. Table 1 shows that the probabilities are less than 5%, thus implying a rejection of the null hypothesis that the series is linearly dependent. The results in Table1 suggest that All Share Index of the Nigeria Stock Exchange are nonlinear and unstable which is an indication of the dynamic behavior of financial time series data hence the data can be estimated using a nonlinear model.

BDS Test for Nonlinearity
Next, this study proceeds with the estimation of the Markov switching model (MS-AR). However, before obtaining the final form of the model used in this research, two models were estimated at different lagged values of the All Share Index on the Nigeria Stock Exchange.
At the first regime, the estimated mean of the model is 2594.267 with a sigma of 20.7992 which are both significant with P-value of (0.0000) each, while at the second regime, the estimated mean of the model switched to 2734.858 with a sigma of 10.8209 which are also both significant at the 5% level of significance.
In common is the Autoregressive AR (1) parameter, 2 o = 0.988384 with p-value (0.000) which is also significant at the 5% level of significance.
At the first regime, the estimated mean of the model is 5500.129 with a sigma of 21.0079 which are both significant with P-value of (0.0000) each, while at the second regime, the estimated mean of the model switched to an insignificant mean of 165.6161 with a sigma of 14.9457 which is significant at the 5% level of significance.
In common is the Autoregressive AR (1) and AR (2) parameter, 2 o = 1.306792, and 2 o 0 = -0.299854 for both regime 1 and regime 2 respectively with p-value (0.000) each, and this implies they are both significant at the 5% level of significance.  Table 4 contained the summary results and the parameters estimate of the possible two state Markov switching Autoregressive models. Comparing the Akaike Information Criteria (AIC) of the models, clearly we prefer the MS (2)-AR (1) model as the best since it has the smallest AIC (16.09972) and the largest log likelihood (-2987.548).

Inferences on the selected Markov Regime Switching Model
MS (2)-AR (1) ; . = ‹ < : A + 2 ; . + 4 . B . = 1 < : A + 2 ; . + 4 . B . = 2 Where B . denotes the regime/state From the estimated Markov switching model above, it is evident that all the model's parameters are significant at the 5% level since their P-value (0.0000) < (0.05). Table 6 below contains the forecasts obtained for (January-December, 2018) using the MS (2)-AR (1) model in order to examine the forecasting performance of the model.    The probability transition matrix which is a tool for describing the behavior of Markov chains represents the probability of moving from state i to state j in a Markov process and is denoted as G H .

Transition Probabilities and Expected Durations
From the matrix above, given that we are in regime/state 1 (bull market), G = 0.93 represents the probability similar to a 93% chance of remaining in state/regime 1 and G 0 0.07 represents the probability similar to a 7% chance of switching to regime/state 2. Also, given that we are in regime/state 2 (bear market) G 00 0.97 represents the probability similar to a 97% chance of remaining in state/regime 2 (bear market) and G 0 0.03 represents the probability similar to a 3% chance of switching to regime/state 1. Furthermore, the estimated transition probabilities indicated that none of the regime is permanent since all the estimated transition probabilities are less than one.
We can also determine the duration of each regime by using the diagonal elements of the probability transition matrix as described in equation (25).
From the table of constant expected duration above, the expected duration of being in regime 1 (bull market) in the stock market is approximately 15 months, while the expected duration of being in regime 2 (bear market) is approximately 34 months. This is because we are dealing with monthly All Share Index data from the Nigeria Stock Exchange.  The filtered and smoothed probabilities respectively, shows that the model accurately captures the two different regimes, because the probability of regime/state 1 is high when B . = 1, and low when B . 2.

Diagnostic Tests for MS (2)-AR (1) Model
Heteroskedasticity Test From the heteroskedasticity test carried out on the residuals of the estimated MS-AR model, we accept the null hypothesis at the 5% level of significance and conclude that the ARCH test reported homogeneity of variance across error term series. From the Q-Statistics tests above, it can be concluded that the error terms are not serially correlated since the P-values across the 12 lags are greater than 0.05, we therefore accept the null hypothesis and conclude that the residuals of the MS-AR models are independent. Therefore, the residuals of the MS (2)-AR (1) model has been diagnosed and examined to be white noise since they are not serially correlated, and have a constant variance.

Conclusion
This study examined the volatility on the Nigeria stock market by comparing two Markov regime switching Autoregressive (MS-AR) Models estimated at different lagged values using the Nigeria stock exchange monthly All Share Index data from 1988 to 2018. The preliminary analysis of the data obtained shows the presence of volatility in the stock market. The parameters of the MS-AR Models were estimated with most of the parameters significant at 5% level of significance. AIC and log-likelihood was used to select the best model that was used. From the AIC and log-likelihood, MS (2)-AR (1) was selected to be the best model since it has the smallest AIC and largest log-likelihood. The nonlinear time series model known as the Markov Regime Switching Autoregressive (MS-AR) model was then used to generate post sample forecasts for 2019 and 2020. The forecasts value indicates clearly that All Share Index prices will have a steady growth between 2019-2020. From the trend analysis of the Nigerian All Share Index, the result shows that there is an unstable trend which indicates that Nigeria stock market is experiencing fluctuations in the price indices which shows that over the years, investors have been exposed to some certain risks in the stock market in the time past.