Skip to main content

A python module to implement Hidden Markov hidden_markov for financial times series.

Project description

HMMpy

Build Status Documentation Status

The HMMpy documentation is at https://hmmpy.readthedocs.io/en/latest/.

HMMpy is a Python-embedded modeling language for hidden markov models. It currently supports training of 2-state models using either maximum-likelihood or jump estimation, and uses and API that is very similar to scikit-learn.

HMMpy began as a University project at Copenhagen Business School, where it was used for financial times series forecasting in an asset allocation project.

Installation

HMMpy is available on PyPI, and can be installed with (only for windows)

pip install hmm-py

HMMpy has the following dependencies:

  • Python >= 3.8
  • Cython >= 0.29
  • NumPy >= 1.20.1
  • Pandas >= 1.2.0
  • SciPy >= 1.5.4
  • tqdm

Getting started

The following code samples some data, and then trains a hidden markov model using the JumpHMM class:

from hmmpy.jump import JumpHMM
from hmmpy.sampler import SampleHMM

# Instantiate the HMM model
hmm = JumpHMM(random_state=42)

# Instantiate the sampler with user defined HMM model parameters
hmm_params = {'mu': [0.1, -0.05],
              'std': [0.1, 0.2],
              'tpm': [[1-0.0021, 0.0021],
                      [0.0120, 1-0.0120]]
             }
sampler = SampleHMM(hmm_params=hmm_params, random_state=42)

# Simulate data
observations, state_sequence = sampler.sample(n_samples=2000, n_sequences=1)  # Outputs 2000 observations and the underlying states

# Fit the model
hmm.fit(observations)

# Inspect model parameters
print(hmm.mu)
print(hmm.std)
print(hmm.tpm)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hmm-py-0.0.2.tar.gz (140.3 kB view hashes)

Uploaded Source

Built Distributions

hmm_py-0.0.2-cp39-cp39-win_amd64.whl (116.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

hmm_py-0.0.2-cp39-cp39-win32.whl (102.2 kB view hashes)

Uploaded CPython 3.9 Windows x86

hmm_py-0.0.2-cp39-cp39-manylinux2010_x86_64.whl (426.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

hmm_py-0.0.2-cp39-cp39-manylinux2010_i686.whl (405.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

hmm_py-0.0.2-cp39-cp39-manylinux1_x86_64.whl (426.5 kB view hashes)

Uploaded CPython 3.9

hmm_py-0.0.2-cp39-cp39-manylinux1_i686.whl (405.6 kB view hashes)

Uploaded CPython 3.9

hmm_py-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl (118.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

hmm_py-0.0.2-cp38-cp38-win_amd64.whl (116.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

hmm_py-0.0.2-cp38-cp38-win32.whl (102.1 kB view hashes)

Uploaded CPython 3.8 Windows x86

hmm_py-0.0.2-cp38-cp38-manylinux2010_x86_64.whl (441.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

hmm_py-0.0.2-cp38-cp38-manylinux2010_i686.whl (419.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

hmm_py-0.0.2-cp38-cp38-manylinux1_x86_64.whl (441.9 kB view hashes)

Uploaded CPython 3.8

hmm_py-0.0.2-cp38-cp38-manylinux1_i686.whl (419.4 kB view hashes)

Uploaded CPython 3.8

hmm_py-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl (116.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page