Application of Markov Chain To Model and Forecast Stock Market Trend: A Study of Safaricom Shares in Nairobi Securities Exchange, Kenya
Application of Markov Chain To Model and Forecast Stock Market Trend: A Study of Safaricom Shares in Nairobi Securities Exchange, Kenya
net/publication/281974470
CITATIONS READS
3 3,358
3 authors:
Robert Nyabwanga
Maseno University
12 PUBLICATIONS 74 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Robert Nyabwanga on 21 September 2015.
1Department of Finance and Accounting, School of Business and Economics, Jaramogi Oginga Odinga University
of Science and Technology, P.O Box 210 Bondo, Kenya
2Department of Statistics and Actuarial Science, School of Mathematics & actuarial Sciences,
Article History: Wealth creation is the goal for every investor. The stock market is one attractive area for investment.
th
Received 27 January, 2015
Nairobi Securities Exchange being an emerging market in the region, it is considered that both
Received in revised form foreign and local investors will seize the opportunity and
and invest in the stock market. However, this
20th February, 2015 has not been the case for many potential investors due to inability to make informed investment
Accepted 14th March, 2015 decisions based on future expectations of the stock market. An understanding of the stock market
Published online 28th April, 2015 trend in terms of predicting
predicting price movements is important for investment decisions. Markov Chain
model has been widely applied in predicting stock market trend. In many applications, it has been
Key words: applied in predicting stock index for a group of stock but little has been done for a single stock.
Markov Chain,
Moreover, the model has had limited application in emerging stock markets. The overall objective of
Forecast,
Safaricom Shares this study therefore, was to apply Markov Chain to model and forecast trend of Safaricom shares
trading in Nairobi Securities Exchange, Kenya. The study was conducted through a longitudinal case
study design. Secondary quantitative data on the daily closing share prices of Safaricom was
obtained from NSE website over a period covering 1st April 2008 to 30th April 2012 forming a 784
days trading
rading data panel. A markov chain model was determined based on probability transition matrix
and initial state vector. In the long run, irrespective of the current state of share price, the model
predicted that the Safaricom share prices would depreciate, maintain value or appreciate with a
probability of 0.3, 0.1 and 0.5 respectively.
Copyright © 2015 Simeyo Otieno et al. This is an open access article distributed under the Creative Commons Attribution
Attribution License, which permits unrestricted use,
distribution, and reproduction in any medium, provided the original work is properly cited.
INTRODUCTION
With globalization of the capital markets, we see that investors
A stock market is an established legal framework surrounding are not restricting their investments to a single market.
the trading of shares of many companies or organizations. Investments are made in different markets, enabling investors
When a stock market is on the rise, it is considered to be an up to enjoy
joy the benefit of diversification of markets ((Vasanthi
and coming economy. It is often considered as the primary et al., 2011).
). Investors base their investments and make a
indicator of a country’s economic strength and development. A choice of their investment destinations based on the
rise in share index and share prices are usually associated with movements of the stock markets. Investors worldwide try to
increased business investment and vice visa, and this also watch the movements ents of market indices and have always
affects the wealth of households and their consumption shown keen interest in trying to predict the share market trend.
(Obodos, 2007). Typically, stock
ock market indices and prices are Stock market forecasts focus on developing a successful
the performance indicators for the entire market. They act as approach for predicting index values or stock prices. The
barometer, which enable us to get an idea about the ultimate aim is to earn high profit us using well defined trading
performance of the entire market in general. Interested strategies. However, forecasting stock indices and stock prices
investors all around the globe keep track of the movement
mov of is very difficult because of the market volatility that needs
various stock market indices and prices to get an idea about accurate forecast model. The stock market indices and prices
how the global markets are moving. are highly fluctuating, that is rising and ffalling randomly. Such
*Corresponding author: Simeyo Otieno, fluctuations affect the investor’s belief. Therefore determining
Department of Finance and Accounting, School of Business and more effective ways of stock market index and stock price
Economics, Jaramogi Oginga Odinga University of Science and prediction is important for stock market investor in order to
Technology, P.O Box 210 Bondo, Kenya. make more informed and accurate investment decisi decisions
14713 Simeyo Otieno et al. Application of Markov chain to model and forecast stock market trend: A study of Safaricom shares in
Nairobi securities exchange, Kenya
(Preethi and Santhi, 2005). Several different approaches have A stochastic process may be continuous or discrete. A
been used to predict the trend of stock markets. These stochastic process is said to be a discrete time process if set T
approaches range from neural network, Data mining, moving is finite or countable. That is, if T= (0,1,2,3,4…….. , n)
averages, Regression analysis, Autoregressive Integrated resulting in the time process X(0), X(1), X(2), X(3), X(4),
Moving Average (ARIMA) A) models to Markov Chain analysis. ……….. ,X(n) , recorded at time 0,1,2,3,4……,n respectively.
Studies indicate that the operational status of the stock market On the other hand stochastic processes X (t): t Є T is
is subject to the influence of various factors from the market considered a continuous time process if T is not finite or
such as multiple market forces from both sides, the countable. That is, if T= [0, ∞) or T= [0, k] for some value k.
fundamentals state of the stock itself, macroeconomic policy,
trade and economic degrees and psychological factors of A state space S is thehe set of states that a stochastic process can
investors. Therefore no single method can accurately predict be in. The states can be finite or countable hence the state
changes in the stock market every day. Markov Chain analysis space S is discrete, that is S=1, 2, 3…, N. Otherwise the space
which this study aims at exploring, is a prediction method
meth S is continuous (Doubleday,
Doubleday, Kevin and Julius Esunge, 2013).
based on probability forecasting approach that has no after-
after A stochastic process is said to be a stationary process (or
effect and may be effectively used to analyze and predict the strict(ly) or strong(ly) stationary process
process) if its joint probability
stock market index and closing stock price under the above distribution does not change when shifted in time.
market mechanisms (Deju Zhang and Xiaomin Zhang, 2009). Consequently, parameters such as the mean and variance, if
they are present, also do not change over time and do not
A number of studies have been conducted to predict the stock follow any trends. If is a stochastic process and let
market trend of financial markets. Majority of these studies represent the cumulative distribution
have tried to forecast financial time series of developed function of the joint distribution of at times .
markets like the US, Chaina and UK, not many empirical Then, is said to be stationary if, for all , for all , and
studies have been done one to forecast stock market trend of for all ,
emerging markets such as Nairobi Securities Exchange market
in Kenya. There seems to be a lot of potential in the emerging
markets and both local and overseas investors are looking
forward to investing heavily in the stocktock markets. This is Since does not affect , is not a function of time.
evidenced in the oversubscribed safaricom shares that were (Honarkhah,
Honarkhah, M.; Caers, J. 2010
2010)
floated to investors in an Initial Public Offer (IPO) at a share
price of Ksh.5 in March 2008 and started trading in Nairobi The opening and closing prices and indices of Stock trading in
Securities Exchange market subsequent month. However,
Howe a Nairobi Securities exchange varies or fluctuates in a random
few months later the Safaricom share price came down manner due to influence of various factors from the market
drastically to as low as Ksh.2 that saw the many investors pull such as multiple market forces from both sides, the
out, Safaricom Kenya Ltd. being the most profitable company fundamentals state of the stock itself, macroeconomic policy,
in East Africa notwithstanding. Given this unique trend for trade and economic degrees to psychological factors of
Safaricom, unlike
nlike the other 65 listed companies trading in investors.
NSE, this study therefore sought to predict the stock market
trend of Safaricom shares trading in NSE in Kenya as an Markov Chains
emerging market, using Markov chain analysis.The specific
objectives were: (1) to study the trend of safaricom share Markov chains are a type of Stochastic Process with special
prices in Nairobi Securities exchang; (2) to determine the property that probabilities involving how the process will
Markov model for forecasting safaricom share price in Nairobi evolve in the future depend only on the present state of the
Securities exchange and (3) to forecast safaricom share price process, and so are independent of events in the past. A
trend in Nairobi Securities Exchange. stochastic process {Xt} is said to have the Markovian property
if P{X t+1 = j/X0 = k0, X1 = k1 ……X t-1= kt-1, Xt = i } = P{ X
Basic Concepts t+1 = j/Xi = i, for t= 0,1,……and every sequence i, j, ko,
kj,…….k t-1.
This section presents the concepts and theories underpinning
the study. This study was anchored on the theory of Markov
In other words this Markovian property says that the
Chains. A Markov chain is a special type of stochastic process.
conditional probability of any future “event”, given any past
The concepts of stochastic process, Markov Chain, Transition
“event” and the present state Xt = i, is independent of the past
matrix, Properties of Markov Chains and Classification of
“event” and depends only upon the present state. The
States are presented in sub sections as outlined below. conditional probabilities P (X t+1 = j/ X t =i}= pij are called
transition probabilities. (Doubleday et al., 2013).
Stochastic Process
A stochastic process is a random process, that is, a change in Transition Probability Matrix
the state of some system over time whose course depends on
The conditional probabilities P (X t+1 = j/ X t =i}= pij are
chance and for which the probability of a particular course is
called transition probabilities and can be arranged in the form
defined. It is basically a family of random variables, X (t): t Є
of a n x n matrix known as the Tran
Transition Probability Matrix. It
T defined on a given probability space, indexed by the time
is given
variable t, where t varies over an index set T. ( Ryan, T,1973).
147144 International Journal of Current Research, Vol. 7, Issue, 04, pp.14712-14721, April, 2015
11 12 − 1
by: P= 21 22 − 2 which can be denoted as P= Pij .
1 2 − (where "gcd" is the greatest common divisor). Note that even
though a state has period k,, it may not be possible to reach the
The matrix has the following properties, state in k steps. For example, suppose it is possible to return to
the state in {6, 8, 10, 12, ...} time steps; k would be 2, even
Pij > 0 for all i and j. though 2 does not appear in this list.
Properties of Markov
kov Chains and Classification of States
The number
Reducibility
This integer is allowed to be different for each pair of states, State i is recurrent (or persistent
persistent) if it is not transient.
hence the subscripts in nij. Allowing n to be zero means that Recurrent states are guaranteed to have a finite hitting time.
every state is defined to be accessible from itself. A state i is
said to communicate with state j (written i ↔ j) if both i → j Ergodicity
and j → i. A set of states C is a communicating class if every
pair of states in C communicates with each other, and no state A state i is said to be ergodic if it is a periodic and positive
in C communicates with any state not in C. C It can be shown recurrent. In other words, a state i is ergodic if it is recurrent,
that communication in this sense is an equivalence relation and has a period of 1 and it has finite mean recurrence time. If all
thus that communicating classes are the equivalence classes of states in an irreducible Markov chain are ergo ergodic, then the
this relation. A communicating class is closed if the probability chain is said to be ergodic. It can be shown that a finite state
of leaving the class is zero, namely that if i is in C but j is not, irreducible Markov chain is ergodic if it has an a periodic state.
then j is not accessible from i. A model has the ergodic property if there's a finite number N
such that any state can be reached from any othe other state in
A state i is said to be essential or final if for all j such that exactly N steps. In case of a fully connected transition matrix
i → j it is also true that j → i. A state i is inessential if it is not where all transitions have a non
non-zero probability, this condition
essential (Asher Levin, David, 2009). is fulfilled with N=1.
=1. That is i.e. a Markov chain is ergodic if
there exists some finite k such that;
A Markov chain is said to be irreducible if its state space is a
single communicating class; in other words, if it is possible to P{X (t+k) = j/X(t) = i} > 0 for all i and j (Tommi Jaakkola,
get to any state from any state. 2006).
Periodicity
A model with more than one state and just one outout-going
transition per state cannot be ergodic (Meyn and Tweedie,
A state i has period k if any return to state i must occur in
2005).
multiples of k time steps. Formally, the period of a state is
defined as
14715 Simeyo Otieno et al. Application of Markov chain
chain to model and forecast stock market trend: A study of Safaricom shares in
Nairobi securities exchange, Kenya
Based on the classifications of the states, the transition matrix Vasanthi S, Subha V. and Nambi T(2011) did an empirical
P can be partitioned into its canonical form. Let an absorbing study on stock index trend prediction using Markov chain
Markov chain with transition matrix P have t transient states analysis. The study used first order Markov chain model to
and r absorbing states. Then predict the daily trend of various global stock indices and
compared the results with that of traditional forecasting
methods. The results showed that the Markov model
outperformed the traditional models used iin the study. The
markov model exhibited high levels of accuracy with the one
Where, Q is a t-by-t matrix, year data used to predict the trend. The study concluded that
the model could help researchers in identifying the future
R is a nonzero t-by-r matrix, trends in the stock markets, and serve as a useful indicat
indicator for
0 is an r-by-t zero matrix, and investors to make better investment decisions. In terms of
Ir is the r-by-r identity matrix. further studies, the study suggested that future research could
be conducted using higher order Markov chains to gain better
Thus, Q describes the probability of transitioning from some insight into the behavior of the market.
transient state to another while R describes the probability of
transitioning from some transient state to some absorbing state.
Rafiul Hassan and Baikunthu nthu Nath (2005) used Hidden
Fundamental matrix Markov Models (HMM) approach to forecasting stock price
for interrelated markets. HMM was used for pattern
A basic property about an absorbing Markov chain is the recognition and classification problems because of its proven
expected number of visits to a transient state j starting from a suitability for modeling dynamic system. The author
transient state i (before being absorbed). The probability of summarized
ized the advantage of the HMM was strong statistical
transitioning from i to j in exactly k steps is the (i,j)-entry
( of foundation. It’s able to handle new data robustly and
Qk. Summing this for all k (from 0 to ∞) yields the desireddesire computationally efficient to develop and evaluate similar
matrix, called the fundamental matrix and denoted by N. It is patterns. The author decides to develop hybrid system using AI
easy to prove that paradigms with HMM improve tthe accuracy and efficiency of
forecast the stock market.
From the above literature review, it comes out that Markov p1= x1/768, p2= x2/768 and p3= x3/768,
Chain model has been widely applied in predicting stock giving:
market trend. In many applications, it has been applied in n (0)=( x1/768, x2/768 , x3/768 ) as the initial state vector.
predicting stock index for a group of stock but little has been
done for a single stock. Moreover, the model has had limited Establishment of the Three State Transition Matrix
application in emerging stock markets. This study therefore,
sought to apply Markov Chain model to study the trend of The transition matrix for this study would involve three states
Safaricom shares trading in Nairobi Securities Exchange, only as the Safaricom stock assumes basically three states. The
Kenya as an emerging market. states are the chances that a stock decreases, that it remains the
same (unchanged) and that it increases. The three states are
MATERIALS AND METHODS stated as follows:
This study used a case study design. The Safaricom shares D = Safaricom share price decreases
were floated for initial public offers in March 2008 and U = Safaricom share price remains the same (Unchanged)
subsequently started trading in the NSE market in April 2008. I = Safaricom share price increases.
The case study design was therefore longitudinal in nature
covering four years period of share prices from 2008 to 2012. Transition Probability Matrix provides a precise description of
This study was carried out in Nairobi Securities Exchange the behavior of a Markov chain. Each element in the matrix
Market. This market is located in Nairobi which is the capital represents the probability of the transition from a particular
city of Kenya. It is situated within the Central Business District state to the next state. The transition probabilities are usually
at Nation Centre. Nairobi Securities Exchange is a capital determined empirically, that is based solely on experiment and
market that engages in trading, clearing and settlement of observation rather than theory. In other words, relying or based
equities, debt, derivatives and other associated instruments. on practical experience without reference to scientific
The operations of this market is automated and comprises eight principles.
segments ranging from Agricultural sector, Commercial and
Services, Telecommunications and Technology (Where This research was based on historical daily closing prices of
Safaricom Kenya ltd belongs), Automobiles and Accessories, Safaricom shares quoted on the Nairobi Securities Exchange.
Banking, Insurance, Investment to Manufacturing and Allied. The data on share price of the Safaricom, was collected from
Secondary quantitative data on the daily closing stock prices of the daily list published by the Nairobi Securities Exchange
Safaricom Kenya limited was obtained over a period of four (also the daily Nation newspaper) from 2008 to 2012. The
years covering 1st April 2008 to 30th April 2012 through transitions from one state to another (that is the share price
document analysis to form a 768 trading days data panel. This movement pattern, which could be that a decrease in price can
data was gathered from the official website of the Nairobi be followed by another decrease or a decrease is followed by
Securities Exchange. Additionally, the Daily newspapers that unchanged or a decrease followed by an increase etc) was
capture daily trading of NSE market were used as data source. observed from the data collected and the result for the period
(4 years) under study was compiled in Table 3.1 as follows;
14717 Simeyo Otieno et al. Application of Markov chain to model and forecast stock market trend: A study of Safaricom shares in
Nairobi securities exchange, Kenya
Each entry Pij in the table refers to the number of times a RESULTS AND DISCUSSION
transition has occurred from state i to state j. Consequently,
from the share price movement compiled, the transition
Trend of Safaricom Share Prices
probabilities was computed to obtain transition matrix for
Safaricom Shares as shown in Table 3.2. The states 1, 2 and 3
The first research question sought to determine the trend of
represent the Price Decreases, Unchanged and Increases
safaricom share prices in Nairobi Securities exchange. To
respectively. The probability transition matrix Pij is formed by
address this, the 768 days trading data panel for daily closing
dividing each element in every row by the sum of each row.
prices of safaricom shares trading in Nairobi Securities
exchange was gathered as illustrated in appendix I. A Four
Table 3.1 The Share Price Movement of Safaricom Kenya Ltd
days weekly moving average of daily closing prices of
Decrease in Unchanged in Increase in safaricom shares was then computed and the results presented
Share Price Share Price Share Price in Figure 4.1 below.
(D) (U) (I)
Decrease in PDD PDU PDI 4 Days Weekly Moving Average Plot
Share Price (D) 8 Variable
Unchanged in PUD PUU PUI Actual
Smoothed
3
State 1 2 3 Sum of Row
2
1 P11 P12 P13 T1 1 79 158 237 316 395 474 553 632 711 790
2 P21 P22 P23 T2 4 days weekly Moving Average
The absolute probabilities at any stage where n is greater than Moving Average (MA) is a tool commonly used by market
unity is determined by the used of n-step transition analysts, as popular as the use of trend lines and chart patterns
probabilities. This is a higher order transition probability Pij(n) to understand the price behaviour of stocks. The price of a
of the transition matrix Pij. The n-step matrix shows the stock can fluctuate wildly over time due to the frequent change
behavior of share prices n-steps later. The elements of this in market sentiment, sector or industries in play and profit
matrix represent the probabilities that an object in a given state taking. This makes interpretation of the underlying price
will be in the next state n-steps later. These repeated transitions movement of the stock difficult. Therefore a Moving Average
are used to evaluate whether the transition probabilities is usually taken by averaging the prices over a period of time
converge over repeated iterations ie, producing a smoother line (Ng Ee Hwa, ChartNexus, 2007).
Lim Pij(n) The results in Figure 1 above show the Safaricom stock
t ∞ prevailing trend. There are 3 types of trends namely
“Uptrend”, “Downtrend” and “Sideway”. Each represents a
This results in steady state probabilities which shows the different collective sentiment of the stock market participants,
probabilities of the shares prices increasing, remaining bullishness in an Uptrend, bearishness in a Downtrend and
unchanged or decreasing regardless of the share’s most recent indecision in a Sideway market. Knowing the trend, a trader
changes in daily closing price. can more easily identify the tops and bottoms of the price
movement for buying or shorting opportunities.
Calculating the State Probabilities of the subsequent
closing days (forecasting) The 4 days weekly moving average starts with a sideway trend
at a share price of Ksh. 5. This is followed by a bullish trend
Since the state probability in different periods are denoted by up to a peak of Share price of Ksh 8 and then engages a
n(i), then n(i+1) = n(i) * p(ij) Thus n (i+n) = n(i) * p(ij)(n). bearish trend to a low of less than Ksh. 3 share price. The trend
then again takes a bullish pattern to a high of Ksh. 6 before
So, depending on the state of the closing share price on the last experiencing a bearish trend and eventually a bullish trend
day of trading period under study ( ie the 768th day), with no from a low of below Ksh.3. The most common way to
follow –up information, it will be regarded as the initial vector. interpreting the price moving average is to compare its
Suppose it is in U state, then, n(0)= (1,0,0). By virtue of the dynamics to the price action. When the instrument price rises
vector and transition matrix, we can predict or forecast state above its moving average, a buy signal appears, if the price
probabilities of various closing date in future. Hence, we can falls below its moving average, what we have is a sell signal.
obtain the state probability of closing price on the769th day as; This trading system, which is based on the moving average, is
n(1)= n(0) * p(ij). State probability vector of closing price on not designed to provide entrance into the market right in its
770th day will be: n(2)= n(1) * p(ij), and so on. lowest point, and its exit right on the peak.
14718 International Journal of Current Research, Vol. 7, Issue, 04, pp.14712-14721, April, 2015
It allows acting according to the following trend: to buy soon Consequently, from the share price movement compiled, the
after the prices reach the bottom, and to sell soon after the transition probabilities were computed to obtain transition
prices have reached their peak. (Neo Ease, 2009) matrix for Safaricom Shares as shown below.
Each closing day was taken as a discrete time unit and the This implies that 0.4513 Safaricom share price that decreases
closing share prices of Safaricom were divided into three states will still decrease; 0.2876 Safaricom share price that decrease
namely Decreases (D), Unchanged (U) and Increases (I). Let x1 will remain the same while 0.2610 Safaricom share price that
= D, x2= U and x3= I, where xi are the number of observations decreases will increase.
for the share prices in the named states gathered over the
period of study, then the state space is E(x1, x2, x3). State D =0.2176
probability is the possibility size of emergence of a variety of U U= 0.5714
states. State vector is denoted by n(i)=( p1, p2,……., pn ) where i= I = 0.2108
1,2,….n, pj is the probability of xj, j=1,2,…,n. The 784 trading
day’s data panel on daily closing prices of Safaricom shares This means that 0.2176 Safaricom share price that remains the
obtained from NSE for the four year period were as shown in same will decrease; 0.5714 Safaricom share price that remains
appendix I. the same will still remain the same whereas 0.2108 Safaricom
The proportions (probabilities) for share prices that Decreases share price that remain the same will increase.
(D), Unchanged (U) and Increased (I) were (246/784)=0.3137;
(315/784)=0.4017 and (223/784)=0.2844 respectively. This D = 0.3076
gives rise to initial state vector as: n (0) = (0.3137 0.4017 I U = 0.2262
0.2844) I = 0.4660
Establishment of the Three State Transition Matrix This also means that 0.3076 Safaricom share price that
increases will decrease; 0.2262 Safaricom share price that
The transition matrix for this study involved three states only increases will remain unchanged while 0.4660 Safaricom share
as the Safaricom stock assumes basically three states. The price that increase will still increase.
states are the chances that a stock decreases (D), that it remains
the same /unchanged (U) and that it increases (I). The The above share price transition movements can be illustrated
transitions from one state to another (that is the share price clearly by a transition diagraph as shown in Figure 4.2.2
movement pattern, which could be that a decrease in price can below.
be followed by another decrease or a decrease is followed by
unchanged or a decrease followed by an increase etc)
observed from the data panel in appendix I were compiled in
Table 4.2 as follows;
The n-step Transition Matrix probabilities contained in their row vectors, reflecting the fact
that each of the states can be reached from any of the states in
The absolute probabilities at any stage where n is greater than a finite number of steps.
unity was determined by the use of n-step transition
probabilities. This is a higher order transition probability Pij(n) The following comments can be made from the above steady
of the transition matrix Pij. The n-step matrix shows the state transition matrix;
behavior of share prices n-steps later. The elements of this
matrix represent the probabilities that an object in a given state The probability that a share price will depreciate (D) given that
will be in the next state n-steps later. These repeated transitions it initially either depreciated (D), unchanged (U) or appreciated
were used to evaluate whether the transition probabilities (I) is 0.3435
converge over repeated iterations ie,
The probability that a share price will remain unchanged (U)
Lim Pij(n) given that it initially either depreciated (D), unchanged (U) or
t ∞ appreciated (I) is 0.1339
This results in steady state probabilities which shows the The probability that a share price will appreciate (I) given that
probabilities of the shares prices increasing, remaining it initially either depreciated (D), unchanged (U) or appreciated
unchanged or decreasing regardless of the share’s most recent (I) is 0.5226
changes in daily closing price. The higher order transition
probability Pij(n) of the transition probability matrix Pij was This shows that regardless of the stocks’ most recent changes
calculated to observe the behavior of the share price and the in closing price, approximately 34.35% of the time they will
results obtained using MATLAB Statistical Software are as drop in value tomorrow, 13.39 % will maintain the value and
shown below. 52.26% will have increases in price. This means that for
investors who held a portfolio made up of Safaricom shares
0.4513 0.2876 0.2610 during the period of study, averaged gains 433 out of 784
Pij = 0.2176 0.5714 0.2108 trading days.
0.3076 0.2262 0.4660
0.4497 0.2214 0.3289 Calculating the State Probabilities of the subsequent
P52 = 0.3082 0.2055 0.4863 closing days (forecasting)
0.4481 0.1244 0.4275
0.3440 0.1329 0.5231 The third research question sought to determine the extent to
P104 = 0.3406 0.1398 0.5196 which the Markov model can be used to forecast Safaricom
0.3439 0.1331 0.5230 share price trend in Nairobi Securities exchange.
0.3435 0.1338 0.5227
P208 = 0.3432 To address this, we apply an initial state vector to the transition
0.1344 0.5224
matrix and predict what state that initial vector will transition
0.3435 0.1339 0.5226
0.3435 0.1339 0.5226 to after n iterations, or trading days.
P416 = 0.3434 0.1340 0.5226
0.3435 0.1339 0.5226 Since the state probability in different periods are denoted by
0.3435 0.1339 0.5226 n(i), then n(i+1) = n(i) * p(ij) Thus n (i+n) = n(i) * p(ij)(n).
P832 = 0.3435 0.1338 0.5227
0.3435 0.1339 0.5226 So, By virtue of the initial satate vector and transition matrix,
0.3434 0.1339 0.5226 we can predict or forecast state probabilities of various closing
P1664 = 0.3435 0.1339 0.5226 date in future after the 784th trading day. Hence, we can obtain
0.3435 0.1339 0.5226 the state probability of closing price on the785th day as; n(1)=
0.3434 0.1339 0.5226 n(0) * p(ij).
P2080 = 0.3435 0.1339 0.5226
0.3435 0.1339 0.5226
By using the n-step probability transition matrix and state Hence, this model will help both researchers and investors in
vectors, we forecast the probabilities of Safaricom share identifying the future trends in Safaricom shares and stock
prices appreciating for some selected period of trading days in markets in general thereby being able to make informed
the future based on the formula: Thus n (i+n) = n(i) * p(ij)(n). The decisions regarding investment in the stock market. However,
results are posted in Table 4.3 as shown below. the operational status of the stock market is subject to the
Table 4.3. Forecasts of Safaricom daily closing share price
Period (some selected Trading days from Probabilities of Safaricom Share Probabilities of Safaricom Share Probabilities of
May 2012 price depreciating remaining unchanged Safaricom Share Appreciating
104 (1/2 a year) 0.3425 0.1874 0.4606
208 (1 year) 0.3433 0.1340 0.5224
832 (4 year) 0.3434 0.1339 0.5225
1664 (8 years) 0.3434 0.1339 0.5225
2080(10 years) 0.3434 0.1339 0.5225
From the forecasts in Table 4.3 above, we notice that influence of various factors from the market ranging from
irrespective of current price today, the probability of the daily multiple market forces to psychological factors of investors.
closing share price of Safaricom either depreciating, remaining Therefore, no single method can accurately predict changes in
unchanged or appreciating continue to increase until the stock market. Markov Chain prediction method is no
equilibrium was reached (after 832 trading days or 4 years) exception and therefore, a combination of results from using
and then became constant. markov Chain to predict with other factors can be more useful
as a basis for decision making. The current study was a case
Regardless of the Safaricom share price today, the probability study on only one company trading in the Nairobi security
of its share price appreciating in 4 years time (by 2016) is Exchange. Furthermore, the study was conducted based on
approximately 0.5. Compared to approximate probability of First order Markov Chains assuming only three possible states
o.3 and 0.1 of Shares depreciating or not gaining value (Increased, unchanged and Decreased). This study therefore
respectively, investors or future investors would be informed suggest that further studies could be conducted on several
that those who bought Safaricom shares or buy safaricom companies listed in the Nairobi Securities Exchange, using
shares today have more chances of appreciating resulting into higher order Markov chains to gain better insight into the
capital gains and hence better returns on investment. behavior of the stock market.
Halbert White, 2009. “Economic prediction using neural Niederhoffer, V. and Osborne, M. F. M. 1966. "Market
networks: the case of IBM daily stock returns” Department Making and Reversal on the Stock Exchange" Journal of
of Economics University of California, San Diego. American Statistical Association, Vol. 61,897-916.
Honarkhah, M. and Caers, J. 2010. "Stochastic Simulation of Obodos, E. 2007. "Predicting Stock Market Prices in Nigeria:
Patterns Using Distance-Based Pattern Modeling". A Preliminary Investigation". University of Benin, Benin
Mathematical Geosciences,42 (5): 487–517. City, Nigeria.
Hsieh Y.L., Don-Lin Yang and Jungpin Wu, 2003. “Using Preethi G. and Santhi B. 2012. Stock Market Forecasting
Data Mining to study Upstream and Downstream causal Techniques: A Survey. Journal of Theoretical and Applied
relationship in stock Market” Information Technology, December 2012. Vol. 46 No.1
JingTao YAO and Chew Lim TAN. 2009. “Guidelines for Rafiul Hassan and Baikunth Nath, 2005. ‘’Stock market
Financial Prediction with Artificial neural networks“. forecasting using hidden Markov model; A new
Kuang Yu Huang, Chuen-Jiuan Jane, 2009. “A hybrid model approach’’. Proceedings of 5th international conference on
stock market forecasting and portfolio selection based on intelligence systems design and applications. 7695-2286-
ARX, grey system and RS theories”, Expert systems with 06/05, IEEE 2005.
Applications, pp.5387-5392 . Tommi Jaakkola, (2006). course materials for 6.867 Machine
Mcqueen, G. and Thorley, S. 1991. "Are Stocks Returns Learning, MIT OpenCourseWare (http://ocw.mit.edu/),
Predictable? A Test Using Markov Chains". The Journal of Massachusetts Institute of Technology
Finance, Vol. 56, No. 1, 49-60. Turner, C. M., Startz, R. and Nelson, C. R. 1989. "A Markov
Meyn S. P. and R.L. Tweedie, 2005. Markov Chains and Model of Heteroskadasticity, Risk & Learning in the Stock
Stochastic Stability. Market"Journal of Financial Economics, Vol. 25, 3-22.
Neo Ease, 2009. Indicator forex : how to interpret Moving Vasanthi S, Subha V. and Nambi T. 2011. An empirical
Average indicator; world press analysis on stock index trend prediction using Markov
Ng Ee Hwa, Chart Nexus 2007. Different uses of Moving chain analysis; Sri Krisha International research and
Average downloaded at http://www.chartnexus.com/ Education consortium, Vol. 1 issue 1. 2231-4288.
learning/static/pulses_apr2007
*******