hurst
Hurst exponent evaluation and R/S-analysis
hurst is a small Python module for analysing random walks and evaluating the Hurst exponent (H).
H = 0.5 — Brownian motion,
0.5 < H < 1.0 — persistent behavior,
0 < H < 0.5 — anti-persistent behavior.
Usage
import matplotlib.pyplot as plt
import numpy as np
import matplotplotlib.pyplot as plt
from hurst import compute_Hc, random_walk
# Use random_walk() function or generate a random walk series manually:
random_increments = np.random.randn(99999)
series = np.cumsum(random_increments) # create a random walk from random increments
# Evaluate Hurst equation
H, c, data = hurst.compute_Hc(series)
# Plot
f, ax = plt.subplots()
ax.plot(data[0], c*data[0]**H, color="deepskyblue")
ax.scatter(data[0], data[1], color="purple")
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel('Time interval')
ax.set_ylabel('R/S ratio')
ax.grid(True)
plt.show()
print("H={:.4f}, c={:.4f}".format(H,c))
H=0.4964, c=1.4877
Brownian motion, persistent and antipersistent random walks
You can generate random walks with random_walk()
function as following:
Brownian
brownian = random_walk(99999, proba=0.5)
Persistent
persistent = random_walk(99999, proba=0.7)
Antipersistent
antipersistent = random_walk(99999, proba=0.3)