Skip to content

Commit

Permalink
prelminary implementation of static hurst exponent
Browse files Browse the repository at this point in the history
things still to do:
* extend static hurst to moving hurst
* extend static r/s range to moving r/s range
* write tests
* review assumptions and methodology
  • Loading branch information
dysonance committed Jul 6, 2018
1 parent 71b222a commit bcf921d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Indicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ VERSION >= v"0.4.0" && __precompile__(true)
module Indicators

export
runmean, runsum, runvar, runsd, runcov, runcor, runmax, runmin, runmad, runquantile, runacf,
wilder_sum, mode, diffn, #lag,
runmean, runsum, runvar, runsd, runcov, runcor, runmax, runmin, runrange, runmad, runquantile, runacf,
wilder_sum, mode, diffn,
sma, trima, wma, ema, mma, kama, mama, hma, swma, dema, tema, alma, zlema,
mlr_beta, mlr_slope, mlr_intercept, mlr, mlr_se, mlr_ub, mlr_lb, mlr_bands, mlr_rsq,
aroon, donch, momentum, roc, macd, rsi, adx, psar, kst, wpr, cci, stoch, smi,
bbands, tr, atr, keltner,
crossover, crossunder,
renko,
maxima, minima, support, resistance
maxima, minima, support, resistance,
rescaled_range, hurst_exponent

include("run.jl")
include("chaos.jl")
include("ma.jl")
include("reg.jl")
include("mom.jl")
include("vol.jl")
include("patterns.jl")
include("reg.jl")
include("run.jl")
include("trendy.jl")
include("utils.jl")
include("patterns.jl")
include("vol.jl")

using Temporal
include("temporal.jl")
Expand Down
59 changes: 59 additions & 0 deletions src/chaos.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#=
Functionality generally related to chaos theory and dynamical systems.
=#

@doc """
# Rescaled Range
Compute the rescaled range of a time series.
`rescaled_range(x::Vector{Float64})::Float64`
""" ->
function rescaled_range(X::Vector{Float64}; corrected::Bool=false)::Float64
return (maximum(X) - minimum(X)) / std(X, corrected=false)
end


@doc """
# Hurst Exponent
Estimate the Hurst exponent of a time series.
## Arguments
* `x`: vector of time series data
* `t`: vector/range of values to use for `t` when estimating the exponent
* `k`: number of times to resample the time series for each partial time series length nᵢ
* `c`: constant number corresponding to \$C\$ in Equation 10 [here](http://www.bearcave.com/misl/misl_tech/wavelets/hurst/index.html#WaveletsAndRS)
* `intercept`: whether an x-intercept should be added when calculating the regression slope
* `seed`: random number generating seed to set before estimation routine, will skip seed setting if nonpositive value given (default)
## References
* Qian and Rasheed 2004, "Hurst Exponent and Financial Market Predictability", https://pdfs.semanticscholar.org/0816/a5a989c8d2431a6d20076d27c4295c00fb77.pdf
* Kaplan 2003, "Estimating the Hurst Exponent", http://www.bearcave.com/misl/misl_tech/wavelets/hurst/index.html#WaveletsAndRS
""" ->
function hurst_exponent(X::Vector{Float64};
t::AbstractVector{Int} = [2^i for i in 1:floor(Int, log(size(X,1)) / log(2))],
c::Float64 = 1.0,
intercept::Bool = true,
seed::Int = 0)
if seed > 0
srand(seed)
end
x = zeros(Int, length(t)) # the size of the periods
y = zeros(length(t))*NaN # rescaled ranges: the y values, or dependent variable
m = mean(X)
for (i, ti) in enumerate(t)
Y = X[1:ti] - m
Z = cumsum(Y)
x[i] = ti
y[i] = rescaled_range(Z)
end
# fit the poiiwer law to the data
log_x = intercept ? [ones(length(x)) log2.(x)] : log2.(x)
log_y = log2.(y)
beta = log_x \ log_y
if beta[end] < 0 || beta[end] > 1
warn("Estimated Hurst exponent ∉ [0, 1].")
end
return beta, log_x, log_y
end

0 comments on commit bcf921d

Please sign in to comment.