original_docstring: Estimate the Hurst exponent using R/S method.
  
          Estimates the Hurst (H) exponent using the R/S method from the time series.
          The R/S method consists of dividing the series into pieces of equal size
          `series_len` and calculating the rescaled range. This repeats the process
          for several `series_len` values and adjusts data regression to obtain the H.
          `series_len` will take values between `min_chunksize` and `max_chunksize`,
          the step size from `min_chunksize` to `max_chunksize` can be controlled
          through the parameter `step_chunksize`.
  
          Parameters
          ----------
          x : 1D-array
              A time series to calculate hurst exponent, must have more elements
              than `min_chunksize` and `max_chunksize`.
          min_chunksize : int
              This parameter allow you control the minimum window size.
          max_chunksize : int
              This parameter allow you control the maximum window size.
          num_chunksize : int
              This parameter allow you control the size of the step from minimum to
              maximum window size. Bigger step means fewer calculations.
          out : 1-element-array, optional
              one element array to store the output.
  
          Returns
          -------
          H : float
              A estimation of Hurst exponent.
  
          References
          ----------
          Hurst, H. E. (1951). Long term storage capacity of reservoirs. ASCE
          Transactions, 116(776), 770-808.
          Alessio, E., Carbone, A., Castelli, G. et al. Eur. Phys. J. B (2002) 27:
          197. https://dx.doi.org/10.1140/epjb/e20020150
          
docstring: Estimate the Hurst exponent using R/S method.
  Estimates the Hurst (H) exponent using the R/S method from the time series.
  The R/S method consists of dividing the series into pieces of equal size
  `series_len` and calculating the rescaled range. This repeats the process
  for several `series_len` values and adjusts data regression to obtain the H.
  
  Parameters
  
  x : 1D-array
  A time series to calculate hurst exponent, must have more elements
  than `min_chunksize` and `max_chunksize`.
  min_chunksize : int
  This parameter allow you control the minimum window size.
  max_chunksize : int
  This parameter allow you control the maximum window size.
  num_chunksize : int
  This parameter allow you control the size of the step from minimum to
  maximum window size. Bigger step means fewer calculations.
  out : 1-element-array, optional
  one element array to store the output.
  
  Returns
  
  H : float
  A estimation of Hurst exponent.
  
  References
  
  Hurst, H. E.
docstring_tokens: Estimate the Hurst exponent using R / S method . Estimates the Hurst ( H ) exponent using the R / S method from the time series . The R / S method consists of dividing the series into pieces of equal size ` series_len ` and calculating the rescaled range . This repeats the process for several ` series_len ` values and adjusts data regression to obtain the H . Parameters x : 1D - array A time series to calculate hurst exponent must have more elements than ` min_chunksize ` and ` max_chunksize ` . min_chunksize : int This parameter allow you control the minimum window size . max_chunksize : int This parameter allow you control the maximum window size . num_chunksize : int This parameter allow you control the size of the step from minimum to maximum window size . Bigger step means fewer calculations . out : 1 - element - array optional one element array to store the output . Returns H : float A estimation of Hurst exponent . References Hurst H . E .
code: def hurst_rs(x, min_chunksize, max_chunksize, num_chunksize, out):
          """Estimate the Hurst exponent using R/S method.
  
          Estimates the Hurst (H) exponent using the R/S method from the time series.
          The R/S method consists of dividing the series into pieces of equal size
          `series_len` and calculating the rescaled range. This repeats the process
          for several `series_len` values and adjusts data regression to obtain the H.
          `series_len` will take values between `min_chunksize` and `max_chunksize`,
          the step size from `min_chunksize` to `max_chunksize` can be controlled
          through the parameter `step_chunksize`.
  
          Parameters
          ----------
          x : 1D-array
              A time series to calculate hurst exponent, must have more elements
              than `min_chunksize` and `max_chunksize`.
          min_chunksize : int
              This parameter allow you control the minimum window size.
          max_chunksize : int
              This parameter allow you control the maximum window size.
          num_chunksize : int
              This parameter allow you control the size of the step from minimum to
              maximum window size. Bigger step means fewer calculations.
          out : 1-element-array, optional
              one element array to store the output.
  
          Returns
          -------
          H : float
              A estimation of Hurst exponent.
  
          References
          ----------
          Hurst, H. E. (1951). Long term storage capacity of reservoirs. ASCE
          Transactions, 116(776), 770-808.
          Alessio, E., Carbone, A., Castelli, G. et al. Eur. Phys. J. B (2002) 27:
          197. https://dx.doi.org/10.1140/epjb/e20020150
          """
          N = len(x)
          max_chunksize += 1
          rs_tmp = np.empty(N, dtype=np.float64)
          chunk_size_list = np.linspace(min_chunksize, max_chunksize, num_chunksize)\
                              .astype(np.int64)
          rs_values_list = np.empty(num_chunksize, dtype=np.float64)
  
          # 1. The series is divided into chunks of chunk_size_list size
          for i in range(num_chunksize):
              chunk_size = chunk_size_list[i]
  
              # 2. it iterates on the indices of the first observation of each chunk
              number_of_chunks = int(len(x) / chunk_size)
  
              for idx in range(number_of_chunks):
                  # next means no overlapping
                  # convert index to index selection of each chunk
                  ini = idx * chunk_size
                  end = ini + chunk_size
                  chunk = x[ini:end]
  
                  # 2.1 Calculate the RS (chunk_size)
                  z = np.cumsum(chunk - np.mean(chunk))
                  rs_tmp[idx] = np.divide(
                      np.max(z) - np.min(z),  # range
                      np.nanstd(chunk)  # standar deviation
                  )
  
              # 3. Average of RS(chunk_size)
              rs_values_list[i] = np.nanmean(rs_tmp[:idx + 1])
  
          # 4. calculate the Hurst exponent.
          H, c = np.linalg.lstsq(
              a=np.vstack((np.log(chunk_size_list), np.ones(num_chunksize))).T,
              b=np.log(rs_values_list)
          )[0]
  
          out[0] = H
code_tokens: def hurst_rs ( x , min_chunksize , max_chunksize , num_chunksize , out ) : N = len ( x ) max_chunksize += 1 rs_tmp = np . empty ( N , dtype = np . float64 ) chunk_size_list = np . linspace ( min_chunksize , max_chunksize , num_chunksize ) . astype ( np . int64 ) rs_values_list = np . empty ( num_chunksize , dtype = np . float64 ) for i in range ( num_chunksize ) : chunk_size = chunk_size_list [ i ] number_of_chunks = int ( len ( x ) / chunk_size ) for idx in range ( number_of_chunks ) : ini = idx * chunk_size end = ini + chunk_size chunk = x [ ini : end ] z = np . cumsum ( chunk - np . mean ( chunk ) ) rs_tmp [ idx ] = np . divide ( np . max ( z ) - np . min ( z ) , np . nanstd ( chunk ) ) rs_values_list [ i ] = np . nanmean ( rs_tmp [ : idx + 1 ] ) H , c = np . linalg . lstsq ( a = np . vstack ( ( np . log ( chunk_size_list ) , np . ones ( num_chunksize ) ) ) . T , b = np . log ( rs_values_list ) ) [ 0 ] out [ 0 ] = H
short_docstring: Estimate the Hurst exponent using R/S method.
short_docstring_tokens: Estimate the Hurst exponent using R / S method .
comment: """Estimate the Hurst exponent using R/S method.
  
          Estimates the Hurst (H) exponent using the R/S method from the time series.
          The R/S method consists of dividing the series into pieces of equal size
          `series_len` and calculating the rescaled range. This repeats the process
          for several `series_len` values and adjusts data regression to obtain the H.
          `series_len` will take values between `min_chunksize` and `max_chunksize`,
          the step size from `min_chunksize` to `max_chunksize` can be controlled
          through the parameter `step_chunksize`.
  
          Parameters
          ----------
          x : 1D-array
              A time series to calculate hurst exponent, must have more elements
              than `min_chunksize` and `max_chunksize`.
          min_chunksize : int
              This parameter allow you control the minimum window size.
          max_chunksize : int
              This parameter allow you control the maximum window size.
          num_chunksize : int
              This parameter allow you control the size of the step from minimum to
              maximum window size. Bigger step means fewer calculations.
          out : 1-element-array, optional
              one element array to store the output.
  
          Returns
          -------
          H : float
              A estimation of Hurst exponent.
  
          References
          ----------
          Hurst, H. E. (1951). Long term storage capacity of reservoirs. ASCE
          Transactions, 116(776), 770-808.
          Alessio, E., Carbone, A., Castelli, G. et al. Eur. Phys. J. B (2002) 27:
          197. https://dx.doi.org/10.1140/epjb/e20020150
          """$SEP$# 1. The series is divided into chunks of chunk_size_list size$SEP$# 2. it iterates on the indices of the first observation of each chunk$SEP$# next means no overlapping$SEP$# convert index to index selection of each chunk$SEP$# 2.1 Calculate the RS (chunk_size)$SEP$# range$SEP$# standar deviation$SEP$# 3. Average of RS(chunk_size)$SEP$# 4. calculate the Hurst exponent.