mottl / hurst Goto Github PK
View Code? Open in Web Editor NEWHurst exponent evaluation and R/S-analysis in Python
License: MIT License
Hurst exponent evaluation and R/S-analysis in Python
License: MIT License
Why do you require series length to be above 100 and not 50? Is this an arbitrary or universal condition? thttps://github.com/Mottl/hurst/blob/5ca5005485a679e6ce11a2769c948915ae27b2da/hurst/init.py#L146
When I look at the code for the compute_Hc
function, there is an initial finite differencing step. Everything else after that agrees with Wikipedia's description of the Hurst exponent except it works with the derivative of the series, instead of the original series.
The random_walk
function, which is supposed to use Fractional Brownian Motion, seems to be in agreement with their compute_Hc
function. If you remove the differencing step, then there ends up being disagreement. But then is the random_walk
function correctly implemented? Because if it is correctly implemented, then the Wikipedia article needs to be corrected.
I have a cycle data, how I choose the "random_walk","change" and "price"? My data looks like Sin function.
I noticed that the compute_Hc
result for some time series is less than 0 or greater than 1. Is this behavior intended?
MWE to reproduce this bug:
import hurst
import numpy as np
print("numpy", np.__version__)
print("hurst", hurst.__version__)
print()
np.random.seed(988)
H, _, _ = hurst.compute_Hc(np.random.uniform(size=100), kind="random_walk", simplified=True)
print(H) # -0.017687382184009826
np.random.seed(916)
H, _, _ = hurst.compute_Hc(np.random.uniform(size=100), kind="random_walk", simplified=False)
print(H) # -0.011722357538317393
np.random.seed(164)
H, _, _ = hurst.compute_Hc(np.random.exponential(1, size=100), kind="change", simplified=True)
print(H) # 1.0118591069505447
Im new to Python, but I tried to run your code and it gets the message NameError: name 'hurst' is not defined....what can be done?
Hello, Sir,
I would like to question you about this part in "hurst":
"
elif kind == 'change':
incs = series
_series = np.hstack([[0.],np.cumsum(incs)])
mean_inc = (series[-1] - series[0]) / len(incs)
deviations = incs - mean_inc
Z = np.cumsum(deviations)
R = max(Z) - min(Z)
S = np.std(incs, ddof=1)
"
shouldn't it be there like this
"mean_inc = (_series[-1] - _series[0])/len(incs)"?
Sorry in advance if I am wrong.
Random series should return 0.5, but:
a=np.random.randint(100,size=(300))
H, c, data = compute_Hc(a)
print(sname,"H={:.4f}, c={:.4f}".format(H,c))
Hello! Just working with your code on a time series analysis, to compute the Hurst exponent of a equity, e.g. Google.
Here is the code:
import matplotlib.pyplot as plt
from hurst import compute_Hc
from datetime import datetime
import pandas_datareader as web
series = web.DataReader("GOOG", "yahoo", datetime(2000,1,1), datetime(2013,1,1))
H, c, data = compute_Hc(series['Adj Close'], kind='price', simplified=True)
Output: H 0.82083 C 0.5268
Following this resource for the Google stock a Hurst of 0.50788 was calculated -> https://www.quantstart.com/articles/basics-of-statistical-mean-reversion-testing
In your script c is the equivalent to the Hurst Exponent being calculated in above link? Or are the two methods not comparable?
Hi Dmitry,
I was working with the latest release of your Hurst Exponent implementation (https://pypi.org/project/hurst/) and am seeing a bit of strangeness. Specifically my crypto price series seems to be getting HE values > 1.0, which obviously is incorrect.
I did email you the notebook as I am unable to attach it here.
Thanks in advance for any help.
The error described in #4 still exists in the current release (0.0.4) and can give very different results.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.