Getting Started

Hurst.jl allows you to calculate Generalised Hurst Exponents (GHEs) in a robust and performant way.

Install Hurst.jl

Before anything else, install Hurst.jl in the usual way:

using Pkg
Pkg.add("Hurst")
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `~/work/Hurst.jl/Hurst.jl/docs/Project.toml`
  [f5425a1d] ~ Hurst v0.1.5 `~/work/Hurst.jl/Hurst.jl` ⇒ v0.1.4 [loaded: v0.1.5]
    Updating `~/work/Hurst.jl/Hurst.jl/docs/Manifest.toml`
  [f5425a1d] ~ Hurst v0.1.5 `~/work/Hurst.jl/Hurst.jl` ⇒ v0.1.4 [loaded: v0.1.5]
Precompiling packages...
    412.0 ms  ✓ Hurst
  1 dependency successfully precompiled in 1 seconds. 238 already precompiled.
  1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version. Otherwise, loading dependents of this package may trigger further precompilation to work with the unexpected version.

Get some data

The easiest way to demonstrate how to use Hurst.jl is with Gaussian data, so we will generate a Gaussian walk ($Z(t) = \sum_\tau X(\tau), X(\tau) \sim \mathcal{N}(0, 1)$).

using Hurst, Plots, Random
Random.seed!(1)
X = cumsum(randn(3000))
plot(X, label = "Gaussian walk", xlabel = "t", ylabel = "X(t)")
Example block output

Define your $\tau$ range

Hurst.jl calculates the Hurst exponent $H$ by estimating the moments of the absolute increments over some time delay $\tau$. If that sounds like gibberish, take a look at the Troubleshooting section which explains things in more detail. τ_range = 30:250 is a good place to start:

τ_range = 30:250
30:250

Calculate $H$

Calclating $H$ is as simple as:

H, SD = hurst_exponent(X, τ_range)
1×2 Matrix{Float64}:
 0.538651  0.0053268

Notice that hurst_exponent returns a 1x2 array. This is because we want to be able to calculate the Generalised Hurst Exponent (GHE) quickly as well and have a consistent API:

q_range = 0.1:0.1:1.
GHE_data = generalised_hurst_range(X, τ_range, q_range)
10×2 Matrix{Float64}:
 0.608553  0.000867734
 0.600029  0.00164231
 0.591653  0.00233204
 0.583453  0.00294414
 0.575449  0.00348517
 0.567653  0.00396123
 0.560072  0.00437808
 0.55271   0.00474119
 0.54557   0.00505577
 0.538651  0.0053268
plot(q_range, GHE_data[:,1], yerror = GHE_data[:, 2], xlabel = "q",
    ylabel = "H(q)", label = nothing, ylims = (0, 1))
Example block output

Further analysis

If you are trying to reproduce some results from papers that use the GHE, you might be interested in the quantity $\zeta(q) = qH(q)$:

zeta_data = Hurst.zeta_estimator_range(X, τ_range, q_range)
plot(q_range, zeta_data[:,1], yerror = zeta_data[:, 2], xlabel = "q",
    ylabel = "ζ(q)", label = nothing)
Example block output

If you want to see if the data is multi-scaling, you can fit parabola to this data with Polynomials.jl:

using Polynomials
quadratic_fit = fit(q_range, zeta_data[:, 1], 2)
scatter!(q_range, zeta_data[:, 1], label = nothing)
plot!(quadratic_fit, extrema(q_range)..., label = "Quadratic fit")
Example block output
#first coefficient should be almost zero...
coeffs(quadratic_fit)
3-element Vector{Float64}:
  0.0008999857186664548
  0.6094966065230799
 -0.07202452793451812