I am discovering the marvellous world of such called "Hidden Markov Models", also called "regime switching models". I would like to adapt a HMM in R to detect trends and turning points. I would like to build the model as generic as possible so that I can test it on many prices.

Can anyone recommend a paper? I have seen (and read) (more than) a few but I am looking for a simple model that is easy to implement.

Also, what R packages are recommended? I can see there is a lot of them doing HMM.

I have bought the book "Hidden Markov models for time series: an introduction using R", let see what's in it ;)


  • $\begingroup$ There is another StackExchange site for quantitative finance questions. $\endgroup$ Jun 29, 2011 at 2:51
  • 1
    $\begingroup$ As to successfully predicting trends: that's the billion dollar question. $\endgroup$ Jun 29, 2011 at 2:57
  • $\begingroup$ @Lao Tzu: About the stackExchange site for quantitative finance, I doubt that the guys there know something about HMM $\endgroup$ Jun 29, 2011 at 3:18
  • $\begingroup$ I think you'll find they are familiar with hidden markov models, regime switching, boosting, and all that. Machine learning is fashionable in quant-finance. $\endgroup$ Jul 1, 2011 at 6:50
  • $\begingroup$ Word of caution: Hidden Markov models are not the same as Markov (Regime) Switching models. $\endgroup$
    – Zhubarb
    May 29, 2015 at 15:57

1 Answer 1


I think a few methods that can be used, but not designed specifically for you, are as follows:

Modeling approaches:

  1. Topic Models (used to find patters in a set of documents and/or information retrieval)

a. Simplest one is LDA

b. Dynamic topic models (IMHO, most suited for your case, without much domain knowledge)

c. Correlated topic models (IMHO, if 2. is not good, it makes sense to try this)

These approaches are not used in finance (I am not aware, as I don't work in specifically in finance), but they have very general applicability. They use the latent variable formulation, which is very similar to that of HMM. They have shown to be state-of-the-art in topic modeling. You can watch a nice presentation by David Blei (great presenter, apart from his awesome!! research) here. The specific references, the slides for the presentation, and more complicated models can be accessed from his website. He is doing some great work which is very general, so it might not be surprising if he has already done something in finance. Another great reference in the same field is his advisor, Michael Jordan's, website. Its hard to find specific references there as he publishes so much!

  1. Time series and sequential data models (HMM specifically)

Apart from Jordan and Blei, the other prolific research is Zoubin Ghahramani (and his coauthor Beal). You can find here the specific HMM models that you require. A few impressive ones are: The infinite hidden markov models, Time sensitive Dirichlet Process Mixture Models.

  1. Software

There is a R package called lda and topicmodels for most of the "good" models. Blei and Ghahramani maintain C, Matlab codes on their website as well.

Good Luck!

  • $\begingroup$ @Srikant, how did u manage to get 1., 2., 3. numbering working. I, for the life of me, could not figure it out! $\endgroup$
    – suncoolsu
    Oct 26, 2010 at 18:17
  • 1
    $\begingroup$ Magic! The secret is: Type a space at the start of the following paras: "Apart from..." and "There is a R package...". $\endgroup$
    – user28
    Oct 26, 2010 at 18:20
  • $\begingroup$ @RockScience: I have been looking at HMM's in the context of financial time series. But the amount of resources for this application field is very limited ( a few papers and theses and all looking at inter-day data). As you know, HMMs are more used in speech recognition, natural language modelling, biological sequence analysis, etc. Do you know of a reason why HMMs are not used in financial time series? Is it maybe related to the fact that the Markov chains in this context are not homogenous and transition and emission probabilities vary widely by time? $\endgroup$
    – Zhubarb
    Sep 25, 2014 at 8:38
  • $\begingroup$ We know from articles that Baum went to work at Rennaisance technologies so I guess there is some use by a few experienced players. My call. Their use is very good when in experienced good hands and there are very experienced few hands and these may not say they use it. $\endgroup$
    – Barnaby
    Mar 1, 2016 at 22:49

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.