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

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Feb 14 00:37:04 CET 2017

This question is off topic here. 
Sent from my phone. Please excuse my brevity.

On February 13, 2017 9:08:18 AM PST, Allan Tanaka <allantanaka11 at yahoo.com> wrote:
>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" %
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list