I want to evaluate the Hurst coefficient in my batch of time series, but I have an issue with these two specific types of `time series, for zero and constant values.
To give you a rough idea of the time series, it's a system that is perturbed at t=0, and I let it free running run for 2000 time steps. I change some parameters of the system, and for each specific parameter, I want to associate its H value.
To compute the Hurst exponent, I tried two technics that I found online:
- The R/S ratio from Wikipedia.
Here is the code that I applied:
n_min = 10
ns = np.arange(n_min, len(time_series), 5)
R = []
S = []
E = []
for n in ns:
Xt = time_series[:n]
m = np.mean(Xt)
Yt = Xt - m
Zt = [sum(Yt[:i]) for i in range(len(Yt))]
# Compute the range
R.append(max(Zt)-min(Zt))
# Compute standard deviation
S.append(np.std(Xt))
E.append(np.mean(np.array(R)/np.array(S)))
reg = np.polyfit(np.log(ns), np.log(E), 1)
H = reg[0]
- And I used a second method that I found here, based on the first exponent:
def hurst(p):
tau = []; lagvec = []
# Step through the different lags
for lag in range(2,20):
# produce price difference with lag
pp = subtract(p[lag:],p[:-lag])
# Write the different lags into a vector
lagvec.append(lag)
# Calculate the variance of the differnce vector
tau.append(sqrt(std(pp)))
# linear fit to double-log graph (gives power)
m = polyfit(log10(lagvec),log10(tau),1)
# calculate hurst
hurst = m[0]*2
# plot lag vs variance
#py.plot(lagvec,tau,'o'); show()
return hurst
Now both techniques give me entirely different results:
Zero time series
H (S/R ratio) = 0.4732894
H (1st exponent) = 0.001971641
Note that fix and zero time series give me almost the same results.
So as you can see, depending on the technique I am using, I have very different results, and now I am wondering if the analysis I am performing on the whole set of time series is even accurate.
So I have a bunch of questions related to this:
- I have read that the Hurst coefficient can be applied on stationary distribution, so my guess is that this might not be possible to measure H for these time series. Do you know a way to compute it on non-stationary time series, maybe?
- Initially, I removed the first half of these time series, but it can't evaluate H when the signals are constant, and I get errors! If I want to stick with the stationary time series, is there a way for me to evaluate H correctly for these constant series?
- Lastly, how can I evaluate the statistical significance of these results, any python code? That could help me decide which implementation is correct or not.
Thank you!