[R] [Python] NameError: name 'hurst' is not defined

Allan Tanaka allantanaka11 at yahoo.com
Mon Feb 13 18:08:18 CET 2017


Correction, it should look like this:**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 

    On Tuesday, 14 February 2017, 0:06, Allan Tanaka <allantanaka11 at yahoo.com> wrote:
 

 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 = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags] poly = 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)



   
	[[alternative HTML version deleted]]



More information about the R-help mailing list