# predict next day's close price using hmm

I am reading this paper(Stock market forecasting using hidden Markov model: a new approach) and get confused about how they predict the next day's close price. Below is what the authors say about how to implement the hmm:

Using the trained HMM, likelihood value for
current day’s dataset is calculated. For example, say the
likelihood value for the day is ‘ , then from the past
dataset using the HMM we locate those instances that
would produce the same ‘  or nearest to the ‘ likelihood
value. That is we locate the past day(s) where the stock
behaviour is similar to that of the current day. Assuming
that the next day’s stock price should follow about the
same past data pattern, from the located past day(s) we
simply calculate the difference of that day’s closing price
and next to that day’s closing price. Thus the next day’s
stock closing price forecast is established by adding the
above difference to the current day’s closing price.


I just begin learning the hmm and know that in a hidden markov model, we have hidden states and observation states. So in order to train a hmm model, one needs to specify what is the hidden states and what is the observation state.But in their paper, I did not quite get what they use as the hidden states and observation to train the model. Besides, they mention a likelihood value which I do not understand. So my questions are: in this paper

1.what are the hidden states and what are the observation states.

2.what is the likelihood value and how to calculate it.

Thanks.

I cannot seem to find that article for free, so here is a more generalized answer.

1.what are the hidden states and what are the observation states.

The hidden states are said to be that of an unobserved parameter process following the Markov property. The observation states are generated by the hidden parameter process. The parameter process changes or switches to different sets of parameters depending only on the previous state.

In other words, there is a hidden parameter process that you cannot observe. It is a random process governing which of the m different sets of parameters is generating the observed data.

2.what is the likelihood value and how to calculate it.

After making assumptions about the number, m, and types of underlying distributions, we have to multiply the initial distribution of the hidden states, $\delta$, by the probability of each observation, $P(x_T)$, and the transition probability matrix, $\Gamma$, (whose rows sum to 1 and tell us the probability of transitioning from one state to another).

Note that $P(x_T)$ is an m x m diagonal matrix where the elements are the probability of observing x from each of m underlying distributions.

The likelihood is given by:

$L_T = \delta P(x_1) \Gamma P(x_2) ... \Gamma P(x_T) 1^T$

The goal is to find the values for $\delta$, $\Gamma$, and the parameters of the m distributions which maximize $L_T$. This is non trivial. As an alternative to numerically maximizing the likelihood, you can also estimate these parameters using Bayesian inference. See the following for more details and computational considerations:

Zucchini, Walter. Hidden Markov Models for Time Series: An Introduction Using R, 1st Edition. CRC Press, 04/2009. VitalSource Bookshelf Online.

See the R package HiddenMarkov for discrete time, continuous space models and the package HMM for discrete time, discrete space models. In other words, use HiddenMarkov if you believe the distributions generating the parameters are continuous (probability density functions), and use HMM if you believe the distributions are discrete (probability mass functions).

I might add that another calculation of great interest form these models is one which estimates the most likely sequence of states given the parameters above, this is know as the Viterbi algorithm and is implemented in both of the R packages mentioned above.

• Hi ian mcdavid, welcome to Quant.SE! Thank you for your contribution. – Bob Jansen Oct 19 '15 at 12:57