Learn to Incorporate Rolling Hurst Values into Your DataFrame

czetsuya
Feb 24, 2024

--

The hurst function.

def hurst(ts, min_lag=1, max_lag=7):
lags = range(min_lag, max_lag)
tau = [np.sqrt(np.std(np.subtract(ts[lag:], ts[:-lag]))) for lag in lags]
poly = np.polyfit(np.log(lags), np.log(tau), 1)
return poly[0]*2.0

Adding to our DataFrame

The hurst value is computed with the last 14 close values.

df['Hurst'] = df['close'].rolling(14).apply(hurst, raw=True)
df[10:20]

--

--

czetsuya

Open for Collaboration | Senior Java Backend Developer