hurstexponent


Namehurstexponent JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/anabugaenko/hurstexponent
SummaryHurst exponent estimator
upload_time2023-07-26 11:20:01
maintainer
docs_urlNone
authorAnastasia Bugeenko
requires_python
licenseMIT
keywords hurst autocorrelation time-series fractals
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Hurst Estimator
A simple statistical package for estimating the long-term memory of time series.  

#
This repository contains a Python class for estimating the Hurst exponent of a time series. The Hurst exponent is used as a measure of long-term memory of time series and relates to both the scaling of the standard deviation of sums of N successive events and the autocorrelations of the time series given the rate at which these decrease as the lag between pairs of values increases.

Feel free to raise an issue if you find a problem; this repository is actively being developed and any tickets will be addressed in order of importance.

# Table of Contents
[Installation](#Installation)</b>

[Basic Usage](#Usage)</b>

[Example](#Example)</b>

## Installation 

We recommend conda for managing Python packages; pip for everything else. To get started, `pip install hurstexponent` ensuring the following dependencies:

  `pip install scipy numpy pandas statsmodels hurst typing matplotlib`

## Usage 

This tells you everything you need to know for the simplest, typical use cases:
  
	import hurstexponent 

  	# Initialize the HurstEstimator with a time series
	np.random.seed(42)
	random_changes = 1. + np.random.randn(99999) / 1000.
	series = np.cumprod(random_changes)
	
	hurst_estimator = HurstEstimator(series)

	# Estimate the Hurst exponent via generalised hurst (default methods)
 	H, D, data, interpretation = hurst_estimator.estimate()

  	# Estimate the Hurst exponent via Rescaled Range
 	H, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')

 	# Estimate the Hurst exponent via alpha found from fitting autocorrelation function (ACF)
  	H, _, _, interpretation = hurst_returns_acf.estimate('hurst_from_alpha', alpha=alpha)
  	
## Example 

	np.random.seed(42)
	random_changes = 1. + np.random.randn(99999) / 1000.
	series = np.cumprod(random_changes)
	
	# Create an instance of HurstEstimator
	hurst_estimator = HurstEstimator(series)
	
	# Generalized Hurst
	H, D, data, interpretation = hurst_estimator.estimate('generalized_hurst')
	print(f"Hurst Estimate via Generalised Hurst: {H}, D constant: {D if D is not None else 'N/A'} ({interpretation})")
	
	# Rescaled Range
	H, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')
	print(f"Hurst Estimate via R/S: {H}, c constant: {c if c is not None else 'N/A'} ({interpretation})")
	
	# Plotting
	fig, axs = plt.subplots(1, 2, figsize=(10, 4))
	
	# Generalized Hurst
	H, D, data, interpretation = hurst_estimator.estimate('generalized_hurst')
	chunk_sizes, y_values = data
	axs[0].plot(chunk_sizes, D*np.array(chunk_sizes)**H, "g--", label=f'Generalized Hurst (H={H:.2f})')
	axs[0].plot(chunk_sizes, y_values, 'b.',  label='Observed Values')
	axs[0].loglog()
	axs[0].set_xlabel('Lag')
	axs[0].set_ylabel('Standard deviation of sums')
	axs[0].legend(frameon=False)
	axs[0].grid(False)
	
	# Rescaled Range
	H, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')
	axs[1].plot(data[0], c*data[0]**H, 'g--', label=f'Hurst (H={H:.2f})')
	axs[1].plot(data[0], data[1],  'b.', label='(Lag, R/S value)')
	axs[1].loglog()
	axs[1].set_xlabel('Lag')
	axs[1].set_ylabel('R/S ratio')
	axs[1].legend(frameon=False)
	axs[1].grid(False)
	
	plt.show()


![Hurst, generalised and r/s hurst](/plots/hurst.png)
	

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/anabugaenko/hurstexponent",
    "name": "hurstexponent",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "hurst autocorrelation time-series fractals",
    "author": "Anastasia Bugeenko",
    "author_email": "anabugaenko@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3a/1e/da8ced8256c98c20b26e84798d63fc0eb49d58656d03191cf0b02cc3850b/hurstexponent-0.1.1.tar.gz",
    "platform": null,
    "description": "# Hurst Estimator\nA simple statistical package for estimating the long-term memory of time series.  \n\n#\nThis repository contains a Python class for estimating the Hurst exponent of a time series. The Hurst exponent is used as a measure of long-term memory of time series and relates to both the scaling of the standard deviation of sums of N successive events and the autocorrelations of the time series given the rate at which these decrease as the lag between pairs of values increases.\n\nFeel free to raise an issue if you find a problem; this repository is actively being developed and any tickets will be addressed in order of importance.\n\n# Table of Contents\n[Installation](#Installation)</b>\n\n[Basic Usage](#Usage)</b>\n\n[Example](#Example)</b>\n\n## Installation \n\nWe recommend conda for managing Python packages; pip for everything else. To get started, `pip install hurstexponent` ensuring the following dependencies:\n\n  `pip install scipy numpy pandas statsmodels hurst typing matplotlib`\n\n## Usage \n\nThis tells you everything you need to know for the simplest, typical use cases:\n  \n\timport hurstexponent \n\n  \t# Initialize the HurstEstimator with a time series\n\tnp.random.seed(42)\n\trandom_changes = 1. + np.random.randn(99999) / 1000.\n\tseries = np.cumprod(random_changes)\n\t\n\thurst_estimator = HurstEstimator(series)\n\n\t# Estimate the Hurst exponent via generalised hurst (default methods)\n \tH, D, data, interpretation = hurst_estimator.estimate()\n\n  \t# Estimate the Hurst exponent via Rescaled Range\n \tH, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')\n\n \t# Estimate the Hurst exponent via alpha found from fitting autocorrelation function (ACF)\n  \tH, _, _, interpretation = hurst_returns_acf.estimate('hurst_from_alpha', alpha=alpha)\n  \t\n## Example \n\n\tnp.random.seed(42)\n\trandom_changes = 1. + np.random.randn(99999) / 1000.\n\tseries = np.cumprod(random_changes)\n\t\n\t# Create an instance of HurstEstimator\n\thurst_estimator = HurstEstimator(series)\n\t\n\t# Generalized Hurst\n\tH, D, data, interpretation = hurst_estimator.estimate('generalized_hurst')\n\tprint(f\"Hurst Estimate via Generalised Hurst: {H}, D constant: {D if D is not None else 'N/A'} ({interpretation})\")\n\t\n\t# Rescaled Range\n\tH, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')\n\tprint(f\"Hurst Estimate via R/S: {H}, c constant: {c if c is not None else 'N/A'} ({interpretation})\")\n\t\n\t# Plotting\n\tfig, axs = plt.subplots(1, 2, figsize=(10, 4))\n\t\n\t# Generalized Hurst\n\tH, D, data, interpretation = hurst_estimator.estimate('generalized_hurst')\n\tchunk_sizes, y_values = data\n\taxs[0].plot(chunk_sizes, D*np.array(chunk_sizes)**H, \"g--\", label=f'Generalized Hurst (H={H:.2f})')\n\taxs[0].plot(chunk_sizes, y_values, 'b.',  label='Observed Values')\n\taxs[0].loglog()\n\taxs[0].set_xlabel('Lag')\n\taxs[0].set_ylabel('Standard deviation of sums')\n\taxs[0].legend(frameon=False)\n\taxs[0].grid(False)\n\t\n\t# Rescaled Range\n\tH, c, data, interpretation = hurst_estimator.estimate('rescaled_range', kind='random_walk')\n\taxs[1].plot(data[0], c*data[0]**H, 'g--', label=f'Hurst (H={H:.2f})')\n\taxs[1].plot(data[0], data[1],  'b.', label='(Lag, R/S value)')\n\taxs[1].loglog()\n\taxs[1].set_xlabel('Lag')\n\taxs[1].set_ylabel('R/S ratio')\n\taxs[1].legend(frameon=False)\n\taxs[1].grid(False)\n\t\n\tplt.show()\n\n\n![Hurst, generalised and r/s hurst](/plots/hurst.png)\n\t\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Hurst exponent estimator",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/anabugaenko/hurstexponent"
    },
    "split_keywords": [
        "hurst",
        "autocorrelation",
        "time-series",
        "fractals"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eedc1caedcbc23795520c2b9db6cadd78d6c573eb39837660a435724a08d967b",
                "md5": "0940ae5d0ca6df73b50108906d8cab50",
                "sha256": "9b4ff7f4bb592e8e06dcf353c64a7fbeaa39d90c55c9d3d3cff595e88ca078fc"
            },
            "downloads": -1,
            "filename": "hurstexponent-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0940ae5d0ca6df73b50108906d8cab50",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6197,
            "upload_time": "2023-07-26T11:19:59",
            "upload_time_iso_8601": "2023-07-26T11:19:59.615759Z",
            "url": "https://files.pythonhosted.org/packages/ee/dc/1caedcbc23795520c2b9db6cadd78d6c573eb39837660a435724a08d967b/hurstexponent-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a1eda8ced8256c98c20b26e84798d63fc0eb49d58656d03191cf0b02cc3850b",
                "md5": "bf96d7831ab19ac7d1eb4b0f20a1d84a",
                "sha256": "0cafc4609a9e7857d5a2401d6dc781102db81b365f79c721f0208bd87bfa3df0"
            },
            "downloads": -1,
            "filename": "hurstexponent-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bf96d7831ab19ac7d1eb4b0f20a1d84a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5511,
            "upload_time": "2023-07-26T11:20:01",
            "upload_time_iso_8601": "2023-07-26T11:20:01.428297Z",
            "url": "https://files.pythonhosted.org/packages/3a/1e/da8ced8256c98c20b26e84798d63fc0eb49d58656d03191cf0b02cc3850b/hurstexponent-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-26 11:20:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anabugaenko",
    "github_project": "hurstexponent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "hurstexponent"
}
        
Elapsed time: 0.10615s