Hidden Markov Model Package Import

I'm researching using the Hidden Markov Model (HMM) as a regime filter (Use Markov models to detect regime changes). Depending on the results of the backtests I may want to use it in production / live trading. There is a library / package "hmmlearn" that can be installed (hmmlearn β€” hmmlearn 0.3.2 documentation). A couple of questions:

  1. If I use the "hmmlearn" library in which containers would I need to install it to research and then ultimately use for live trading?
  2. Does Quantrocket have a similar ML package or alternative approach I should consider?

Thank you.

  1. For Zipline strategies, you should install packages in the jupyter and zipline containers. More information on installing custom packages can be found in the usage guide.
  2. hmmlearn used to be part of scikit-learn but was moved to a separate package so it is probably the best (only?) choice for HMM.
1 Like

@Brian I'm back to exploring various regime filter techniques. A couple of questions:

  1. Does Quantrocket's documentation have a central place that lists the python libraries it supports without having to install a custom package?
  2. Rather than a Hidden Markov Model I'm starting to explore another variant, the Markov Switching Model. I understand the Markov Switching Model is supported in the Statsmodels library. Would I be required to deploy Statsmodels as a custom package? I seem to remember this already being supported by QR but can't find any evidence of this in the documentation.

Thanks.

The easiest way to see exactly what’s installed is to open a JupyterLab Terminal and type:

conda list

statsmodels is already installed.

1 Like

@Brian Statsmodels is working for me but I'm also interested in hmm.learn which is not currently in the Quantrocket deployment. Is it generally safe to add libraries or is there a risk it will break the standard Quantrocket Docker deployment? As you know, I'm not en Engineer and I'm hesitant to take this on if there is a decent chance I break the normal Docker deployment. Let me know your thoughts. Thanks.

Usually if there's an incompatibility you will know quickly: either the package will not install successfully, or it may install but trigger an error when you try to import something. If that happens, you can restore the container to its original state by recreating the container:

docker compose up -d --force-recreate jupyter

@Brian good to know. A couple more questions:

  1. If you have to recreate the container does it go back to it's original state like it's a new install or is there some kind of time machine like capability that it goes back to it's most recent (or a selected time period) state?
  2. If I have to recreate the container is the data / files that I had in the container lost?

Thank you.

Custom installed packages are lost but your data and code are preserved. More information here.

1 Like

Thanks Brian