hurst
Hurst exponent evaluation and R/S-analysis
hurst is a small Python module for analysing random walks and evaluating the Hurst exponent (H).
H = 0.5 — Brownian motion,
0.5 < H < 1.0 — persistent behavior,
0 < H < 0.5 — anti-persistent behavior.
Installation
Install hurst module with
pip install hurst
or
pip install -e git+https://github.com/Mottl/hurst#egg=hurst
Usage
import numpy as np
import matplotlib.pyplot as plt
from hurst import compute_Hc, random_walk
# Use random_walk() function or generate a random walk series manually:
# series = random_walk(99999, cumprod=True)
np.random.seed(42)
random_changes = 1. + np.random.randn(99999) / 1000.
series = np.cumprod(random_changes) # create a random walk from random changes
# Evaluate Hurst equation
H, c, data = compute_Hc(series, kind='price', simplified=True)
# Plot
f, ax = plt.subplots()
ax.plot(data[0], c*data[0]**H, color="deepskyblue")
ax.scatter(data[0], data[1], color="purple")
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel('Time interval')
ax.set_ylabel('R/S ratio')
ax.grid(True)
plt.show()
print("H={:.4f}, c={:.4f}".format(H,c))
H=0.4964, c=1.4877
Kinds of series
The kind parameter of the compute_Hc function can have the following values:
'change': a series is just random values (i.e. np.random.randn(...))
'random_walk': a series is a cumulative sum of changes (i.e. np.cumsum(np.random.randn(...)))
'price': a series is a cumulative product of changes (i.e. np.cumprod(1+epsilon*np.random.randn(...))
Brownian motion, persistent and antipersistent random walks
You can generate random walks with random_walk() function as following:
Brownian
brownian = random_walk(99999, proba=0.5)
Persistent
persistent = random_walk(99999, proba=0.7)
Antipersistent
antipersistent = random_walk(99999, proba=0.3)
Metadata
Release files for hurst 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hurst-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for hurst-0.0.5-py3-none-any.whl |
Release files / hurst-0.0.5-py3-none-any.whl
| Download URL | hurst-0.0.5-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d163f11fe2318aa8979c921d6667b8dfd6205c629924fefbed68505357cf995e
|
|
BLAKE2b-256 checksum How to use checksums |
024fd3471ce0dca03a21d4c6640da07a6040c9cc800a937233086b6cea6a7dc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.8
|
Security for hurst 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.