1
$\begingroup$

I have a the following time series

  Price      BrokerID 632 Behaviour  BrokerID 680 Behaviour ...BrokerID XYZ Behaviour

  5.6          IP                       SP                   
  5.7          BP                       IP
  5.8          SP                       BP
  5.83         IP                       SP

where IP is idle position, BP is buying position, and SP is selling position. I want to use Broker behaviour as the known variable and price as the hidden variable and predict it using HMM. But my question is how to find the emission matrix between a character vector (broker behaviour) and price numeric vector?

$\endgroup$
3
  • $\begingroup$ R for statistical computing $\endgroup$
    – Rup Mitra
    Commented Apr 29, 2013 at 17:46
  • $\begingroup$ This won't work in real life $\endgroup$
    – Jase
    Commented Nov 28, 2013 at 9:47
  • $\begingroup$ What is HMM? Please explain acronyms in the text for better understanding. $\endgroup$
    – mpiktas
    Commented Jan 28, 2014 at 20:07

3 Answers 3

4
$\begingroup$

I'm not familiar with the financial time series data, but with my understanding of HMMs / graphical models, they are not models in which you get to choose the hidden variables. The hidden variables are interpreted as a "state", or some latent data-generation scheme, such that several states, each state with a different emission distribution, are responsible for the generation of the observed data. If it is a general mixture model without the HMM chain structure, then there's no temporal dependence of the model. HMM is proposed to incorporate temporal dependence of the data. In which case, the next "state" of the stock market depend on the current "state" of the stock market.

In your case, you have observed broker behavior (variable $B$, possibly from multiple brokers), and price (variable $P$), and you want to predict $P$ from $B$.

If we do not consider temporal dependence of the stock market, we can just use any regression methods, or conditional graphical models (e.g. conditional random field) to predict $P$.

Given we want to consider temporal dependence as well, in the HMM setting, you can treat $B$ as a set of covariates for your emission distribution. That is, $B$ is a set of conditional variables which $P$ is conditioned upon. So, for each hidden state in the HMM, we want to learn a distribution of $P$ conditioned upon $B$.

Therefore, back to your question, probably what you wanted is an HMM, with:

  • $M$, a fixed hidden number of states (decided by you).
  • $T$, a transition matrix between the states (result of learning procedure of HMM).
  • $A$ the initial distribution of hidden states (result of learning procedure of HMM).
  • $E$, the emission distribution, one for each hidden state, where each distribution is a conditional distribution $p(P|B)$.

Here, the conditional distribution $p$ can be as complicated as a conditional random field, or, a simple one such as a Gaussian mixture model, where the number of mixtures are the number of possible broker behaviors, the mixture coefficients are the portion of each broker behavior observed in that time, and the $\mu_i$ and $\sigma_i$ for each mixture is estimated using MLE for Gaussian distribution (in the M-step of the EM algorithm, for example.)

However, given the fact that research of modeling spatial-temporal dependent time-series data using HMM is still an open field, starting with a simple regression model (e.g. linear regression) is more practical.

EDIT: Thanks for the comment by @while, I somehow misinterpreted the intention of @rup-mitra by saying that he wants to "predict" the price. I agree with @while that there are a variety of continuous state-space hidden Markov models. Broadly speaking, Kalman filters, observable operator models, reduced-rank hidden Markov models, etc. Theoretically, there could be an HMM that uses the "price" as the hidden state and generate multiple "broker behaviors", but I doubt that a single real number "price" contains enough information. Thus I proposed the above models as alternatives.

$\endgroup$
2
  • 1
    $\begingroup$ I don't agree with you at all. What you describe is a simplification of what is contained within HMMs. You can choose your states in a HMM much more freely than you describe and it is very well possible to have a continuous state space for the hidden states. I have for example used continuous x and y position in a plane as the hidden states with great results. Another good example widely used in HMM research papers is the stochastic volatility model which also has a continuous hidden state space. $\endgroup$
    – while
    Commented Apr 30, 2013 at 8:44
  • $\begingroup$ You are right, I misinterpreted the question. However, my alternative models might be more practical than using a single variable "price" as the hidden state. $\endgroup$
    – nil
    Commented Apr 30, 2013 at 17:44
1
$\begingroup$

You need to use the Baum-Welch algorithm to learn the transition, emission and prior probabilities from your data.

If you are using the HiddenMarkov CRAN package, you can achieve this by using the BaumWelch() function.

$\endgroup$
0
$\begingroup$

A simple way to compute a transition matrix from a sequence:

 l = 100
 seq = sample(letters[1:5],l,replace=T)
 tab = table(seq[1:(l-1)],seq[2:l])
 print(tab)

  a b c d e
a 4 6 5 4 2
b 2 2 6 6 6
c 8 4 2 1 3
d 3 4 3 0 4
e 4 6 3 2 9

 print(t(t(tab)/colSums(tab)))

         a          b          c          d          e
a 0.19047619 0.27272727 0.26315789 0.30769231 0.08333333
b 0.09523810 0.09090909 0.31578947 0.46153846 0.25000000
c 0.38095238 0.18181818 0.10526316 0.07692308 0.12500000
d 0.14285714 0.18181818 0.15789474 0.00000000 0.16666667
e 0.19047619 0.27272727 0.15789474 0.15384615 0.37500000
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.