Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of the hurst exponent are wrong #17

Open
fabiofumarola opened this issue Jan 29, 2016 · 2 comments
Open

Result of the hurst exponent are wrong #17

fabiofumarola opened this issue Jan 29, 2016 · 2 comments

Comments

@fabiofumarola
Copy link

from numpy import cumsum, log, polyfit, sqrt, std, subtract
from numpy.random import randn

def hurst(ts):
    """Returns the Hurst Exponent of the time series vector ts"""
    # Create the range of lag values
    lags = range(2, 100)

    # Calculate the array of the variances of the lagged differences
    tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]

    # Use a linear fit to estimate the Hurst Exponent
    poly = polyfit(log(lags), log(tau), 1)

    # Return the Hurst exponent from the polyfit output
    return poly[0]*2.0

# Create a Gometric Brownian Motion, Mean-Reverting and Trending Series
gbm = log(cumsum(randn(100000))+1000)
mr = log(randn(100000)+1000)
tr = log(cumsum(randn(100000)+1)+1000)

# Output the Hurst Exponent for each of the above series
# and the price of Google (the Adjusted Close price) for 
# the ADF test given above in the article
print "Hurst(GBM):   %s" % hurst(gbm)
print "Hurst(MR):    %s" % hurst(mr)
print "Hurst(TR):    %s" % hurst(tr)

I compared with the results of pyeeg.hurst and they are quite different.
I you want I can do a pull request to update the method

@Borzou
Copy link
Contributor

Borzou commented Jan 29, 2016

@fabiofumarola Could you please tell us based on which article you have implemented this algorithm for calculating the hurst exponent? Why are you taking the square root of standard deviation? We have implemented hurst exponent based on this http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.137.207&rep=rep1&type=pdf article. And as to my understanding you have not implemented the same algorithm as one disclosed in the above article.

@fabiofumarola
Copy link
Author

Hi @Borzou, sorry I was to rude in the post. Anyway I got the function from QuantStart blog post. The blog post talks about mean reversion testing but it uses the Hurst Exponent as a measure to evaluate is the time series is: reverting, a Geometric Brownian Motion or trending.
I tested its formula and it looks ok for me. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants