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]]
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]]
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" % >hurst(gbm) > > > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.