Application of Markov Chain Techniques for Selecting Efficient Financial Stocks for Investment Portfolio Construction

In this paper, we apply Markov chain techniques to select the best ﬁ nancial stocks listed on the Ghana Stock Exchange based on the mean recurrent times and steady-state distribution for investment and portfolio construction. Weekly stock prices from Ghana Stock Exchange spanning January 2017 to December 2020 was used for the study. A three-state Markov chain was used to estimate the transition matrix, long-run probabilities, and mean recurrent times for stock price movements from one state to another. Generally, the results revealed that the long-run distribution of the stock prices showed that the constant state recorded the highest probabilities as compared to the point loss and point gain states. However, the results showed that the mean recurrent time to the point gain state ranges from three weeks to thirty- ﬁ ve weeks approximately. Finally, Standard Chartered Bank, GCB, Ecobank, and Cal Bank emerged as the top best performing stocks with respect to the mean recurrent times and steady-state distribution, and therefore, these equities should be considered when constructing asset portfolios for higher returns.


Introduction
Investing in the stock market is not gambling but requires an investor to determine whether stock prices will rise or fall over the investment horizon. Stock price forecasting has always been a challenging task in corporate finance research and academia. In most cases, investors sought to gain a deeper understanding and the historical performance of equities to make better investment decisions [1]. Many fund managers and investors are faced with the challenge of selecting efficient stocks for constructing investment portfolios. For instance, in portfolio construction and management, the initial step involves stock or fund selection based on their performance and grouping them into a stock fund known as a portfolio [2].
Kaya and Karsligil's study asserted that determining the stock price of any business goes beyond the financial position of the company and requires the flow of information about the company and the economic performance of the sector, as well as the country in which the company is located. As a result, stock price forecasting has become more challenging than it was before [3]. There is no straightforward equation that can locate the correct resource allocation for each person. In any case, the agreement among most financial managers is that the allocation of resources is efficient and yields good returns. Therefore, predicting stock prices or stock market returns remains a critical and complex issue in financial and investment analysis. In addition, the agreement among most financial managers is that the allocation of resources is efficient and yields a good return [4].
Usually, the portfolio manager typically uses two types of strategies to pick securities or funds. These are quantitative and qualitative appraisals of an asset before its selection. The quantitative method of stock or asset picking for portfolio construction uses quantitative metrics to assess the performance of an asset before its approval into the portfolio.
However, the qualitative approach on the one hand requires investigation of the management of the company/funds, which is important to understand a significant part of the results. Unfortunately, this technique takes time to investigate all the mechanisms of asset management, and they often remain elusive.
Several researchers over the years [1,[5][6][7] have developed various methodologies for predicting future share market prices using either deterministic statistical approach or stochastic approach. However, there are little studies on the use of stochastic approach in stock selection under the Ghana stock market/exchange. The inherent goal of this paper is to apply Markov chain techniques to select stocks based on their mean recurrent times and steady states for investment consideration.
To analyse and predict the stock market behaviour, the Markov chain model has been employed by several researchers in different times. The following studies indicate the pertinence of the Markov chain model in predicting the movement stocks. Choji et al. [8] applied the Markov chain model to predict the possible states in demonstrating the performance of the two best banks, namely, Guarantee Trust Bank of Nigeria and First bank of Nigeria. Their study employed six-year data spanning 2005 to 2010. They used transition probability matrix and probability vector to obtain the long-run prediction of the share price of these banks whether appreciate, depreciate, or remain unchanged irrespective of current share price of the banks. D. Zhang and X. Zhang [9] applied a Markov chain model to forecast the stock market trend in China. Their study discovered that the Markov chain has no after-effect, and the model is more suitable to analyse and predict the stock market index, and closing stock prices are more effective under the market mechanism. The study recommended that the result obtain from the Markov chain model for prediction should be combined with other factors having significant influence in stock market variations and the method should be used as a basis for decision making.
Otieno et al. [10] used the Markov chain model to forecast stock market trends of Safaricom share in Nairobi Securities Exchange in Kenya. Their study estimated the probability transition matrix and initial state vector to predict the Safaricom share prices using the dataset spanning April 1, 2008, to April 30, 2012. Their study revealed that the memory less property and random walk capability of the Markov chain model facilitated the best fit to the data and predicted good trends of the share prices. Mettle et al. [1] used the Markov chain model with finite states to analyse the share price changes for five different randomly selected equities on the Ghana Stock Exchange. Their study concluded that the application of the Markov chain model as a stochastic analysis method in equity price studies improves the portfolio decisions. They have suggested that the Markov chain model can be applied as a tool for improving the stock trading decisions. Application of this method in stock analysis improves both the investor knowledge and chances of higher returns.
Bhusal [11] applied a Markov chain model to forecast the behaviour of Nepal Stock Exchange (NEPSE) index.
The study explored the long-run behaviour of the NEPSE index and the expected number of visits to a particular state and determined the expected first return time of various states. The NEPSE index of 2741 trading days ranging from August 15, 2007, to June 18, 2017, was used. The study showed that regardless of the present status of the NEPSE index, in the long run, the index will increase with a probability of 0.3855, remain in the same state with probability 0.1707, and decrease with a probability of 0.4436. It revealed that the index will remain in increasing state after three days when it starts to move from the increasing state. The study concluded that the movement of stock index to the various states in a particular trading day is independent with the index of initial trading days but depends only on the index of the most recent day.

Materials and Methods
The data used for this paper consists of time series data of weekly price changes of the equities listed on the Ghana Stock Exchange (GSE). The daily price changes of these equities are transformed into weekly price changes. The data spanned January 2017 to December 2020. It is assumed that the number of working days in a week was used to compute the average price change. The remaining part of the section discusses the Markov Chain techniques for modelling the dynamics of stock prices.
Stochastic processes can be characterized into several types depending upon the state space, index parameter, and the dependence relations among the random variables through the specification of the joint distribution function. Among these processes, Markov chain is a special type of random process that has the property that the occurrence of any event in the future depends only in the present state. The set of values taken by the Markov process is known as state space. A Markov process having discrete state space is termed as Markov chain. The fundamental difference between the Markov chain model and other statistical methods of projection such as regression model and time series analysis is that the Markov model does not need any mutual laws among the factors from complex predictor; it only requires the characteristic of the development on the history of event (i.e., initial probability) to estimate the transition probability for different possible states at various times to come.
Using the Markov chain model makes it is easier to predict the possibility of state value in a certain period after knowing the initial probability distribution and transition probability matrix. The Markov chain model has been extensively applied in predicting stock prices or index for a group of stock as well as for a single stock [9,11].
2.1. The Markov Chain Model. Markov chains represent the probabilistic movements of certain variables over time. They are widely applicable across a wide range of disciplines. A Markov chain is a stochastic process that satisfies the Markov property or has the memoryless rule that argues that once the present is known, the past and future are unrelated. This means that if one knows the process's current state, no additional information about its previous states is required 2 Journal of Applied Mathematics to make the best possible prediction for its future. This simplicity allows for a significant reduction in the number of parameters to be estimated in such a process. Mathematically, a Markov Chain model can be expressed as follows.
Let "S" be a discrete set; a Markov Chain is a sequence of random variables: X 0 , X 1 , X 2 , ⋯, X n taking values in the set S with the property (Markov property) such that where x 0 , x 1 , ⋯, x n−1 , i, j ∈ S and ∀n ≥ 0. The set S represents the Markov Chain's state space.
There are two representations of Markov chains: discretetime Markov chain and continuous-time Markov chain, and this paper employed discrete-time Markov chains. The price change of an asset, where the change is registered as the difference between the previous end of week price and the current end of week price, is a good example of a discrete-time Markov chain. In discrete time, the value of the Markov chain is known as the state, and in this case, the state corresponds to the price change. A continuous-time Markov chain can change at any point in time. This can be explained using events occurring with continuous time lag "steps" in their appearance. Markov chains are techniques used to compute the probabilities of events occurring in states transitioning into other states or back into the same state. Individual probabilities, known as transition probabilities, can be organized into states and studied using transition matrices. These special matrices with their transition diagrams are used to demonstrate the movement between or among states.

Transition Matrices.
A transition matrix or stochastic matrix is a square matrix P with probabilities given by which satisfies the following axioms: Based on the transition matrix in Equation (2), a threestate transition matrix diagram can be represented as follows in Figure 1.

Long-Run Distribution for a Markov Chain.
If P is the stochastic matrix which is aperiodic, irreducible, and finite state Markov chain (ergodic Markov chain), then where a = ða 1 , a 2 ,⋯,a n Þ, with 0 ≤ a i ≤ 1 and ∑ n i=1 a i = 1.

Recurrent Property.
Consider a state that is arbitrary but fixed, i, and define an integer n ≥ 1; then, It implies that f n ii is the likelihood that the first return to state i, from state i, happens at the n th transition. However, given that f 1 ii = p ii , then the mean recurrent time ðP n ii Þ may be computed as 2.3. Model Specification. Let Y t represent the equity price at time t, where t = 0, 1, 2, ⋯, n (where t is measured in weekly time intervals). Furthermore, we define R t = Y t 1 −t 0 , as the change in equity price at time t. Taking each closing week's price as a discrete time unit and letting the random variable X t represent the state of equity closing price at time t, a vector spanned by 0, 1, and 2, where 2, if dt > 0, increase in equity price from time t − 1 to t: Here, the values 0, 1, and 2 denote the states of the transition matrix. Now, let us define an indicator random variable I i,t as

Journal of Applied Mathematics
Then, the result of X t will be given as where n = ∑ 2 i=0 n i and n i is the number of equity prices for state i.
The estimates of the initial probabilities for that the equity prices for decrease, unchanged/constant, and increase states are obtained as follows: where n 0 is the number of times the equity remains decreased over the period, n 1 is the number of times the equity remains unchanged, and n 2 is the number of times the equity increased over the study period. Now, for the stochastic process X t obtained in Equation (6) for t = 1, 2, ⋯, n, the estimated probabilities can be obtained as follows:p ij = PðX t = j | X t−1 = iÞ, for i, j = 0, 1, 2 (in this paper) and defining the indicator function, δ ði,jÞ t , as where t = 1, 2, ⋯, n − 1 and i, j = 0, 1, 2 are the number of states in the Markov chain, and the number of times ðn ij Þ, when X t = i and X t+1 = j, is given as The estimated transition matrixP of Equation (2), with respect to this paper is of the form wherep ij = n ij /n i , for i, j = 0, 1, 2, is the probability of an equity price at state i at time, t, will move to state j at time t + 1: This paper employed a Markov chain technique to analyse the average price fluctuation behaviour of the stocks which are grouped into the three states: S = fpoint loss, constant, point gaing. The selecting of stocks of the financial sector on the GSE would be based on the limiting distribution or the long-run transitional probabilities and the recurrent times from point loss to point gain state.

Results and Discussions
The results and discussions of using the Markov chain techniques to select stocks based on their mean recurrent times and steady-state distribution for investment considerations are presented. The transition probabilities from one state to the other were obtained using 209 transitions of the dataset. The paper considered twelve stocks from the financial  Table 1.
It is observed that Standard Chartered Bank (SCB) stock recorded the maximum weekly return over the period, and it was followed by Access, EGH, EGL ADB, GCB, RBG, SG-GH, CAL Bank, TBG, and ETI in a descending order of magnitude of returns. In terms of the minimum values, SCB has the least minimum value followed by GCB, EGH, ADB, EGL, Access, SG-GH, Cal, RBG, TBG, SIC, and ETI. In terms of the variability (i.e., standard deviation), SCB recorded the greatest variability as compared to the other equities, making it a riskier stock. Table 2 presents the statistics for the initial market condition, steady-state distribution, and the mean recurrent times of the twelve equities considered. The three states employed in this study are loss, constant, and gain. The initial market condition represents the probabilities of equities in each state at the beginning, and for each equity, the three-state probabilities sum up to one. However, the steady-state distribution of the states described the long-run probabilities for the equities at the three states. It is generally observed that both the probabilities of the initial market condition and the steady-state distribution presented the same pattern with the constant state recording the highest probabilities for almost all the stocks. The mean recurrent times present the movement of the weekly equity prices from one state to another. It is observed that moving from state 0 to state 1 records the highest mean recurrent times and was followed by state 1 back to state 1.

The Behaviour of Equities. This subsection presents three-state Markov chain transition matrices illustrating the behaviours of the equities listed on the Ghana Stock
Exchange. The states are loss (represents number of times a decrease is observed from the current price), constant (represents number of times no change is observed from the current price), and gain (represents number of times an increase is observed from the current price). The transition matrices were estimated based on 209 transitions obtained from weekly price averages spanning four years (January 2017 to December 2020). Figure 2 depicts the transition matrix and diagram for Access Bank Plc equity. The transition matrix showed that 4 Journal of Applied Mathematics the Access stock has an average of 18.2% chance of staying in a point loss state, 45.5% chance of switching from point loss state to a constant state, and 36.4% chance of switching from point loss state to point gain state. However, market trends at a constant state showed no change in prices. The Access stock recorded an average of 14% chance of moving from a constant state to point loss state, 76.9% likelihood of remaining at the constant, and 9.1% chance of switching from constant state to point gain state. It is observed that the movement from the point gain state to the other states is not different. Furthermore, there is 18.2% chance of switching from point gain state to point loss state, 57.6% chance of switching to constant state, and 24.2% chance of maintaining the point gain state in the preceding cycle are recorded. It is observed that Access stock showed a high probability of remaining at a constant state or switch to a constant state from loss and gain states with a greater probability as confirmed by the steady-state distribution ( Table 2).
The mean recurrent times of Access stock displayed in Table 2 showed that on average, the weekly time for the share price to revisit point gain state while in point gain (U 11 ) is 6.212 and average weekly time for the stock price to revisit point gain state while in point loss or constant state (U 01 ) is 6.88. This means that the prices of Access stock have an average of six weeks approximately to revisit point gain    Figure 3 presents the behaviour of ADB stock prices using the transition matrix and diagram. It is observed from the ADB transition matrix that there is zero probability of staying in the point loss state or losing further points but had almost sure chance of switching from point loss state to a constant state. Furthermore, the ADB stock recorded    This implies that stock prices on the increase have 50 percent chances of increasing in the following cycle or week and 50 percent chance of being constant in the next cycle but zero probability of decreasing to a lower price than the current stock in the next cycle.
The steady-state distribution for the ADB stock displayed in Table 2 shows that in the long run, ADB share prices have 0.5% of decreasing in price, 96.6% of the price remaining constant, and 2.9% of the price increasing. In addition, the mean recurrent times of ADB (Table 2) showed that the stock prices have an average of 35 weeks to revisit point gain state while in point gain, whereas it takes the price of the equity approximately 68 weeks to revisit point gain state while in point loss or constant state. The movements of the weekly prices of the Cal Bank stock on the GSE are not different from those of the Access bank stock presented in Figure 2. The transition matrix and diagram for the Cal Bank equity are presented in Figure 4. It is observed that on average, Cal stock price has 46.8 percent chance of returning to point loss state or continual decreasing in stock price. However, Cal stock price has 24.7 percent chance of switching from point loss state to a constant state and 28.6 percent chance of switching from point loss state to point gain state.
Furthermore, there was 0.507 probability of returning to the constant state and 0.261 and 0.232 probabilities for Cal Bank stock price switching from constant state to loss state or gain state, respectively. It is interesting to note that the Cal Bank stock has 0.381 likelihood of returning to the point gain state and lesser chances of switching from point gain state to constant state or point loss state.
The long-run distribution of Cal Bank stock prices affirmed that weekly prices of equity are more likely to decrease than been constant or increasing (Table 2). Furthermore, the mean recurrent times of Cal Bank stock weekly prices have an average of approximately three weeks to revisit point gain state while on the increase, whereas it would take approximately four weeks to revisit point gain state when in loss or constant states (Table 2). Furthermore, the behaviour and movements of the remaining nine stocks (EGH, ETI, EGL, GCB, RBG, SIC, SG-GH, SCB, and TGB) are not completely different from the movements of Access bank and Cal Bank stocks. However, the differences observed are the magnitude of the transition probabilities for their movements from one state to another (Figures 5-13). Furthermore, there are similar long-run distribution of their stock prices and similar mean recurrent times as displayed in Table 2 for the remaining nine stocks. For instance, Ecobank weekly stock prices have an average of three weeks to revisit point gain state while increasing and approximately 4 weeks to revisit point gain state while been on the decreasing or constant prices.
The statistical analysis of the Markov chain model for fitting equities is displayed in Table 3. The chi-square test for goodness of fit was used to test the null hypothesis that the steady-state probabilities are stable and consistent. It is observed from Table 3 that all the 12 equities' chi-square tests recorded p values greater than 5 percent level of significance. This implies that the steady-state probabilities of the three states for all the equities are stable and consistent. It can therefore be concluded that the Markov chain model employed produces a good fit to the data. Table 4 depicts the overall average rating of assets under the financial sector based on the following metrics on mean recurrent times. It is observed that Standard Chartered Bank (SCB) emerged as the best stock or equity in terms of U 11 since SCB stock has the lowest mean recurrent time to state of point gain while in point gain state. This means it takes SCB the shortest number of weeks among its peers for its share prices to increase. In addition, the next stocks with the minimum number of weeks in ascending order are as  (Table 3).
Additionally, considering the steady-state time with respect to the point gain state, it was observed that SCB stock recorded the highest chance of gaining points or increasing in stock price weekly and adjudging it as the best performing

Discussion and Conclusion
This paper sought to apply Markov chain techniques to select financial stocks listed on the Ghana Stock Exchange based on the mean recurrent times and steady-state distribution for investment consideration. The success of an investor particularly in a stock market centers on the choice of decision made which in turn hang on to the large extent on how well knowledgeable one is in stock analysis. According to Choji et al., Markov chain models have been used to analyse and predict the movement of stock prices in a stock market [8]. The paper has shown systematically the applications of Markov chain techniques in analysing the transition probabilities and movement of the stock prices among the three states: point loss, constant, and point gain. Generally, the long-run distribution of the stocks showed that the constant state recorded the highest probabilities as compared to the other two states: point loss and point gain states. The stock prices showed similar long-run distribution and similar mean recurrent times except in the cases of ADB stock. However, the results showed that the mean recurrent time to the point gain state ranges from three weeks to thirtyfive weeks approximately. Finally, Standard Chartered Bank, GCB, Ecobank, and Cal Bank were considered the top best performing stocks with respect to the mean recurrent times of their stock prices increasing and attaining the highest probabilities in the long run. However, ADB, Trust Bank of Gambia, Access Bank Plc, and Republic Bank stock prices were observed to have produced the highest probabilities for their stock prices to remain constant.
According to studies by Choji et al. and D. Zhang and X. Zhang, the Markov chain model was successfully used to predict and forecast the stock price movements and stock market trends in China and Nigeria, respectively [8,9]. In Kenya, Otieno et al. employed the Markov chain model to forecast stock market trend of Safaricom share in Nairobi Securities Exchange [10]. Bhusal used the Markov chain model to forecast the behaviour of Nepal Stock Exchange (NEPSE) index [11]. Based on the empirical evidence for the use of the Markov chain model to analyse and forecast the movements of stock market trends, the application for Markov chain techniques to select financial stocks based on the mean recurrent times and steady-state distribution for investment consideration is appropriate. Hence, centred on the findings of the study, the paper recommends that investors should consider Standard Chartered Bank (SCB), GCB, and Ecobank equities when constructing asset portfolios for higher returns.

Data Availability
The weekly stock prices data used to support the findings of this study are available from the corresponding author(s) upon request. They were extracted from Ghana Stock Exchange website: https://gse.com.gh.