Skip to content
All library documents

How Hidden Markov Models Use Likelihood to Forecast Stock Prices

Article Quant Q&A · Author: epx

Summary

The document explains a proposed forecasting procedure from a paper on stock prediction with hidden Markov models. For a current observation, the trained model calculates its likelihood, then historical observations with matching or nearby likelihoods are used to identify similar market conditions. The forecast adds the historical next-day change in closing price to the current close. The questioner asks what the model treats as hidden states and observations, and how likelihood is calculated.

The response describes hidden states as unobserved regimes or parameter sets that generate observable data, with transitions governed by a Markov process. It gives the likelihood as a product of the initial state distribution, state-specific observation probabilities, and transition probabilities across the observation sequence. Model parameters can be estimated by maximizing that likelihood; Bayesian estimation is mentioned as an alternative, and the Viterbi algorithm as a way to infer a likely state sequence. The original paper is unavailable in the discussion, so its precise state and observation definitions are not established. The answer is general HMM background, not evidence that the forecasting procedure works or a full specification for reproducing it.

Key ideas

  • Hidden states can represent unobserved regimes whose parameters generate observed market data.
  • The likelihood measures how probable an observation sequence is under specified state and emission distributions.
  • Likelihood calculation combines initial state probabilities, observation probabilities, and transition probabilities.
  • Model fitting seeks parameters that make the observed sequence more likely, while Bayesian inference offers another estimation approach.
  • The discussion does not identify the specific states or observations used in the referenced stock forecasting paper.

Tags

Full text
# predict next day's close price using hmm


# 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.

## Answer by bad question asker (score 2)

https://quant.stackexchange.com/a/21295

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.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.