title: Hurst Exponent in python
body: <pre><code>from datetime import datetime
  from pandas.io.data import DataReader
  from numpy import cumsum, log, polyfit, sqrt, std, subtract
  from numpy.random import randn
  
  def hurst(ts):
  
      """Returns the Hurst Exponent of the time series vector ts"""
      # Create the range of lag values
      lags = range(2, 100)
  
      # Calculate the array of the variances of the lagged differences
      # Here it calculates the variances, but why it uses 
      # standard deviation and then make a root of it?
      tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]
  
      # Use a linear fit to estimate the Hurst Exponent
      poly = polyfit(log(lags), log(tau), 1)
  
      # Return the Hurst exponent from the polyfit output
      return poly[0]*2.0
  
  
  # Download the stock prices series from Yahoo
  aapl = DataReader("AAPL", "yahoo", datetime(2012,1,1), datetime(2015,9,18))
  
  # Call the function
  hurst(aapl['Adj Close'])
  </code></pre>
  
  <p>From this code for estimating Hurst Exponent, when we want to calculate the variance of the lagged difference, why we still use a standard deviation and take a square root? I am confused for a long time, and I don't know why others don't have the same confuse. Do I misunderstand the math behind it? Thanks!</p>