hurst


Namehurst JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/Mottl/hurst
SummaryHurst exponent evaluation and R/S-analysis
upload_time2019-02-07 14:07:07
maintainer
docs_urlNone
authorDmitry Mottl
requires_python
licenseMIT
keywords hurst fractal econometrics time-series
VCS
bugtrack_url
requirements pandas numpy
Travis-CI
coveralls test coverage No coveralls.
            # hurst
## Hurst exponent evaluation and R/S-analysis

![Python 2.7](https://img.shields.io/badge/python-2.7-blue.svg)
![Python 3x](https://img.shields.io/badge/python-3.x-blue.svg)
[![Build Status](https://travis-ci.org/Mottl/hurst.svg?branch=master)](https://travis-ci.org/Mottl/hurst)
[![pypi](https://img.shields.io/pypi/v/hurst.svg)](https://pypi.org/project/hurst/)
[![Downloads](https://pepy.tech/badge/hurst)](https://pepy.tech/project/hurst)

**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
```python
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))
```

![R/S analysis](https://github.com/Mottl/hurst/raw/master/examples/regression.png?raw=true "R/S analysis")

```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)```


![Brownian motion](https://github.com/Mottl/hurst/raw/master/examples/Brownian_motion.png?raw=true "Brownian motion")

### Persistent
```persistent = random_walk(99999, proba=0.7)```


![Persistent random walk](https://github.com/Mottl/hurst/raw/master/examples/Persistent.png?raw=true "Persistent random walk")

### Antipersistent
```antipersistent = random_walk(99999, proba=0.3)```


![Antipersistent random walk](https://github.com/Mottl/hurst/raw/master/examples/Antipersistent.png?raw=true "Antipersistent random walk")



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Mottl/hurst",
    "name": "hurst",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "hurst fractal econometrics time-series",
    "author": "Dmitry Mottl",
    "author_email": "dmitry.mottl@gmail.com",
    "download_url": "",
    "platform": "",
    "description": "# hurst\n## Hurst exponent evaluation and R/S-analysis\n\n![Python 2.7](https://img.shields.io/badge/python-2.7-blue.svg)\n![Python 3x](https://img.shields.io/badge/python-3.x-blue.svg)\n[![Build Status](https://travis-ci.org/Mottl/hurst.svg?branch=master)](https://travis-ci.org/Mottl/hurst)\n[![pypi](https://img.shields.io/pypi/v/hurst.svg)](https://pypi.org/project/hurst/)\n[![Downloads](https://pepy.tech/badge/hurst)](https://pepy.tech/project/hurst)\n\n**hurst** is a small Python module for analysing __random walks__ and evaluating the __Hurst exponent (H)__.\n\nH = 0.5 \u2014 Brownian motion,  \n0.5 < H < 1.0 \u2014 persistent behavior,  \n0 < H < 0.5 \u2014 anti-persistent behavior.  \n\n## Installation\nInstall **hurst** module with  \n`pip install hurst`  \nor    \n`pip install -e git+https://github.com/Mottl/hurst#egg=hurst`\n\n## Usage\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom hurst import compute_Hc, random_walk\n\n# Use random_walk() function or generate a random walk series manually:\n# series = random_walk(99999, cumprod=True)\nnp.random.seed(42)\nrandom_changes = 1. + np.random.randn(99999) / 1000.\nseries = np.cumprod(random_changes)  # create a random walk from random changes\n\n# Evaluate Hurst equation\nH, c, data = compute_Hc(series, kind='price', simplified=True)\n\n# Plot\nf, ax = plt.subplots()\nax.plot(data[0], c*data[0]**H, color=\"deepskyblue\")\nax.scatter(data[0], data[1], color=\"purple\")\nax.set_xscale('log')\nax.set_yscale('log')\nax.set_xlabel('Time interval')\nax.set_ylabel('R/S ratio')\nax.grid(True)\nplt.show()\n\nprint(\"H={:.4f}, c={:.4f}\".format(H,c))\n```\n\n![R/S analysis](https://github.com/Mottl/hurst/raw/master/examples/regression.png?raw=true \"R/S analysis\")\n\n```H=0.4964, c=1.4877```\n\n### Kinds of series\nThe `kind` parameter of the `compute_Hc` function can have the following values:  \n`'change'`: a series is just random values (i.e. `np.random.randn(...)`)  \n`'random_walk'`: a series is a cumulative sum of changes (i.e. `np.cumsum(np.random.randn(...))`)  \n`'price'`: a series is a cumulative product of changes (i.e. `np.cumprod(1+epsilon*np.random.randn(...)`)\n\n## Brownian motion, persistent and antipersistent random walks\nYou can generate random walks with `random_walk()` function as following:\n\n### Brownian\n```brownian = random_walk(99999, proba=0.5)```\n\n\n![Brownian motion](https://github.com/Mottl/hurst/raw/master/examples/Brownian_motion.png?raw=true \"Brownian motion\")\n\n### Persistent\n```persistent = random_walk(99999, proba=0.7)```\n\n\n![Persistent random walk](https://github.com/Mottl/hurst/raw/master/examples/Persistent.png?raw=true \"Persistent random walk\")\n\n### Antipersistent\n```antipersistent = random_walk(99999, proba=0.3)```\n\n\n![Antipersistent random walk](https://github.com/Mottl/hurst/raw/master/examples/Antipersistent.png?raw=true \"Antipersistent random walk\")\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Hurst exponent evaluation and R/S-analysis",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/Mottl/hurst"
    },
    "split_keywords": [
        "hurst",
        "fractal",
        "econometrics",
        "time-series"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "024fd3471ce0dca03a21d4c6640da07a6040c9cc800a937233086b6cea6a7dc2",
                "md5": "42b4c739a49ead3a6ea9eb450a7161e2",
                "sha256": "d163f11fe2318aa8979c921d6667b8dfd6205c629924fefbed68505357cf995e"
            },
            "downloads": -1,
            "filename": "hurst-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "42b4c739a49ead3a6ea9eb450a7161e2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5856,
            "upload_time": "2019-02-07T14:07:07",
            "upload_time_iso_8601": "2019-02-07T14:07:07.841216Z",
            "url": "https://files.pythonhosted.org/packages/02/4f/d3471ce0dca03a21d4c6640da07a6040c9cc800a937233086b6cea6a7dc2/hurst-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-02-07 14:07:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Mottl",
    "github_project": "hurst",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "0.18"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.10"
                ]
            ]
        }
    ],
    "lcname": "hurst"
}
        
Elapsed time: 1.25957s