# Hurst exponent in Python

In this tutorial, we will learn about using the Hurst exponent in Python. The Hurst exponent is a useful parameter in dealing with time-series. It is a measure of a time-series to either regress near a mean or to tend in a particular direction.

We look at a simple implementation of finding the Hurst exponent in Python with the help of the Hurst module.

## Inferences from the Hurst Exponent

**H = 0.5**This is indicative of a

**Brownian**series. There is no correlation between current observations and future observations. It is difficult to predict values in the future.**H > 0.5**This is indicative of a

**Persistent**time-series. In the short term, values will tend to follow their existing trends. That is, those values which are increasing are predicted to increase and vice-versa.**H < 0.5**This is indicative of an

**Anti-P****ersistent**time-series. In, the short term, values will tend to go against their existing trends. That is, those values which are increasing are predicted to decrease and vice-versa.

## Implementation of the Hurst Exponent in Python

The Hurst module makes it very simple for us to find the Hurst exponent of a time-series. Here are the steps involved.

First, we need to install the Hurst module. We also need to import the necessary libraries and modules into our code.

!pip install hurst import numpy as np import matplotlib.pyplot as plt from hurst import compute_Hc, random_walk

Secondly, we need to have a time-series to work with. We can create such a series using the **random_walk()** function.

# Use random_walk() function to generate a random walk series s = random_walk(10000) # the parameter passed must be 100 or more

Next, we use the **compute_Hc() **function to compute the values of the Hurst exponent (H) and the constant (c).

# compute_Hc returns a tuple of 3 values H, c, val = compute_Hc(s)

This step is optional. We can plot a logarithmic graph of Rescaled Range (R/S) vs Time interval.

# Plot the graph axes = plt.subplots()[1] axes.plot(val[0], c*val[0]**H, color="blue") axes.scatter(val[0], val[1], color="red") axes.set_xscale('log') axes.set_yscale('log') axes.set_xlabel('Time interval') axes.set_ylabel('R/S ratio') axes.grid(True) plt.show()

**Sample Output:**

Finally, we display the value of the Hurst exponent.

# printing the Hurst exponent to 4 decimal places print("Hurst exponent = {:.4f}".format(H))

**Sample Output:**

Hurst exponent = 0.5071

#### Conclusion

In this tutorial, we learned how to find the Hurst exponent for a time-series using Python. We did this with the help of the Hurst module.

Also read: Display various Datetime formats using Python

how can you read and explicate this chart?

I’ve got a time series. how can I compute its Hurst exponent? Please help me.