Learn to Incorporate Rolling Hurst Values into Your DataFrame
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:], ...
https://www.czetsuyatech.com/2024/02/machine-learning-rolling-hurst-value-in-dataframe.html
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]
Post a Comment