Skip to main content

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

Project description

HMMpy

Build Status Build status

The HMMpy documentation is at insert link when website is ready.

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 TestPyPI, and can be installed with (only for windows)

pip install -i https://test.pypi.org/pypi/ --extra-index-url https://pypi.org/simple cstolborg==0.0.5

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)

Apart from the JumpHMM class

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.0.tar.gz (140.1 kB view hashes)

Uploaded Source

Built Distribution

hmm_py-0.0.0-cp39-cp39-win_amd64.whl (115.9 kB view hashes)

Uploaded CPython 3.9 Windows 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