A python module to implement Hidden Markov hidden_markov for financial times series.
Project description
HMMpy
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for hmm_py-0.0.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 028fd2c16332590e03a36b048c3e5be7e6ac0cebaaa410a238d498f38fa00e4f |
|
MD5 | 70521190451dd2a2d77c609dc42e4bd6 |
|
BLAKE2b-256 | 1d74624ffc760c61c432d8850ca3097b3f86f5e358dfe14ef5850881161df905 |
Hashes for hmm_py-0.0.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56b85ab66cc23da04515ff181c4e8239cf8d7c014af5a8878bcb7847857b1956 |
|
MD5 | af058d76926aa97d448d01a4f83f0910 |
|
BLAKE2b-256 | 89df4d284eca49d67bc9574a516d18e8bbbbcf7d7a4a175d42332ff29c848320 |
Hashes for hmm_py-0.0.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 698968c0117bd307beb13170d9bc57d88a608f242640b200936b390dec343df4 |
|
MD5 | 4ff2390842d16cb8d6cc8c73e22ebb5c |
|
BLAKE2b-256 | f7a5bd79e1d634e6bcb9ffbb2d46cfc4d3f493c7f33bcb8e4f27ed450f90ff95 |
Hashes for hmm_py-0.0.2-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24f7dc3fd28a59702b0e15504a0a4f174986090a27e21dfb597ad59f4ee73f1a |
|
MD5 | 1c557e34cdf9356491d6178c78741368 |
|
BLAKE2b-256 | bc81c9f5a32955744ffeaf4a2ef39ab3add2aada30e9ddf87d2454ce8fe1b6d1 |
Hashes for hmm_py-0.0.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a220d5a564a7e1370406a29ba1bd83638f9bdb21cce4a3d397336e6e2f9e4137 |
|
MD5 | 19f7ebb22f6da69190b29f43442aa0c8 |
|
BLAKE2b-256 | 8ac43dcc7ab8d73d8189bcec185bd1293f97b4b43cdb4a2bb9b89beb2752062a |
Hashes for hmm_py-0.0.2-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17241e51b0786ba7651e4fd45579c21cac2c3dc83250eb58395d505a578fe6b |
|
MD5 | 2d4a181cb0790cb228d0fe00ec0df9aa |
|
BLAKE2b-256 | 1623921e1745328e377cea99785598cac433ce6e07fef9c247c141a591b65b4b |
Hashes for hmm_py-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecc70647966abd128165138fe14f85ec1b9b0699ca2ad74c46fa5e87f43aa35c |
|
MD5 | 1662a4130966514d81e03e9cb3714a57 |
|
BLAKE2b-256 | 357721ccf39cfcb21e1e13aaf4730c8df9972a4418c8dd2f80b42955eaafc330 |
Hashes for hmm_py-0.0.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de55789aae2d16e22827c55844b562e1258ef42603e97d00455759b92da3b277 |
|
MD5 | 4e0c4db0df9773a1f44672434112cdf5 |
|
BLAKE2b-256 | 49ac888f9db35cbf15049a3e261d1dc45c8b2752ea1989638e60cbdcfb0a9fd5 |
Hashes for hmm_py-0.0.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9dca3f5023c766c2aeb700eb9eeed552a09fd8d338d05aa3e339f1d9bf683b0 |
|
MD5 | 1060755b7147109064866696aaa4e35f |
|
BLAKE2b-256 | 710ae8ce35a6bebe71d4f1f8c895acf3d692f5ae91e4abeff009c7a15ad5b11d |
Hashes for hmm_py-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427cd89f0de95001c33a6915562e10a2e2c5b98e55065b6b30e07a9da2b194cc |
|
MD5 | f602ec2b5d88b3fb286439ebf12e2ee0 |
|
BLAKE2b-256 | b7f2567aa0047ff21ba4d5a7a21c8439d87151c7f0f9b5f29853637f2fd07281 |
Hashes for hmm_py-0.0.2-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e4e6ba5b254c7c2602686d28eb7b3a8c1b3b5f71dd64b86e3c4b40f9d72fff |
|
MD5 | a179aa27a5f8b2ab2c474e417eb51e44 |
|
BLAKE2b-256 | 8258f1963e5dd87500244dbf5f64901f49ba9b1700d2561f647bbfc938e22e93 |
Hashes for hmm_py-0.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fc62ea19a576530f9de1e854f99ab3111ca297d9bba56996fb2d1d2258e256d |
|
MD5 | 91ffa6f81fbf48ad8f2e13b36ec8b03a |
|
BLAKE2b-256 | 5d43f27a709543bdd1fee3594221b764c473236bcadc2a59dfa24e0d9b5b1116 |
Hashes for hmm_py-0.0.2-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805b56e54b480c23f827630b0f08b32215552c62672c0c16553ef94473e80ae5 |
|
MD5 | d82adac3e92b7fad190956e0e94e6fda |
|
BLAKE2b-256 | 6ca4a5fb85ff330aab3c288da3941578ea8ba96ec59f8aa0ae99003032bb9d74 |
Hashes for hmm_py-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91e929be3abe4d7904a4fb5b83cfb4a0b2a0782ac313d3a9f86c2e1d8ae8ed72 |
|
MD5 | 8ef923648403893d19fff2ea6a7a87e5 |
|
BLAKE2b-256 | 46ad295a24f1a6e8c3b8fe9771e33c85b6ee7a14964239206e0008eec65791e4 |