You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromnumpyimportcumsum, log, polyfit, sqrt, std, subtractfromnumpy.randomimportrandndefhurst(ts):
"""Returns the Hurst Exponent of the time series vector ts"""# Create the range of lag valueslags=range(2, 100)
# Calculate the array of the variances of the lagged differencestau= [sqrt(std(subtract(ts[lag:], ts[:-lag]))) forlaginlags]
# Use a linear fit to estimate the Hurst Exponentpoly=polyfit(log(lags), log(tau), 1)
# Return the Hurst exponent from the polyfit outputreturnpoly[0]*2.0# Create a Gometric Brownian Motion, Mean-Reverting and Trending Seriesgbm=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 articleprint"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
The text was updated successfully, but these errors were encountered:
@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.
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?
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
The text was updated successfully, but these errors were encountered: