[Tutor] NameError: name 'hurst' is not defined

Allan Tanaka allantanaka11 at yahoo.com
Mon Feb 13 20:55:30 EST 2017


Hi. Not sure why this code produces the error like this. This error appears when i run the code of print "Hurst(GBM):   %s" % hurst(gbm): 
Traceback (most recent call last):  File "<pyshell#31>", line 1, in <module>    print "Hurst(GBM):   %s" % hurst(gbm)NameError: name 'hurst' is not defined

Here is the full code:>>> import statsmodels.tsa.stattools as ts
>>> import urllib>>> from datetime import datetime>>> from pandas_datareader import data, wb>>> from pandas_datareader.data import DataReader>>> goog = DataReader("GOOG", "yahoo", datetime(2000,1,1), datetime(2017,1,1))>>> ts.adfuller(goog['Adj Close'], 1>>> import numpy as np
>>> from numpy import cumsum, log, polyfit, sqrt, std, subtract>>> from numpy.random import randn>>> def hurst(ts): lags = range(2, 100) tau = [np.sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags] poly = np.polyfit(log(lags), log(tau), 1) return poly[0]*2.0>>> gbm = log(cumsum(randn(100000))+1000)>>> mr = log(randn(100000)+1000)>>> tr = log(cumsum(randn(100000)+1)+1000)>>> print "Hurst(GBM):   %s" % hurst(gbm)


More information about the Tutor mailing list