Code: Select all

`subroutine hurst(series y)`

series ym

!n = @obs(y)

series RS_sum

series RS_ave

for !i=2 to !n

!count = 1

series R

for !j = 1 to !n-!i+1 step !i

series cumser

smpl !j !i+!j-1

!S = @stdev(y)

series ym = y - @mean(y)

cumser = @cumsum(ym)

R(!count) = (@max(cumser) - @min(cumser))/!S

!count = !count+1

next

smpl 1 !count-1

RS_sum = @cumsum(R)

RS_ave(!i) = RS_sum(!count-1)/(!count-1)

next

smpl @all

!start = @floor(10^(@log10(!n)*.25))

!end = @floor(10^(@log10(!n)*.75))

smpl !start !end

equation eq1.ls @log10(RS_ave) c @log10(@trend(0))

vector(1) hurst = eq1.@coefs(2)

smpl @all

delete cumser r rs_ave rs_sum ym

endsub

Code: Select all

`subroutine hurst(series y)`

series ym

series R

!n = @obs(y)

for !i=2 to !n

!R_sum = 0

!S_sum = 0

for !j = 1 to !n-!i+1

series cumser

smpl !j !j+!i-1

!S = @stdevp(y)

ym = y - @mean(y)

cumser = @cumsum(ym)

!R = @max(cumser) - @min(cumser)

!R_sum = !R_sum + !R

!S_sum = !S_sum + !S

next

R(!i) = !R_sum / !S_sum

next

smpl @first+2 @last

equation eq1.ls @log10(R) c @log10(@trend(0))

vector(1) hurst = eq1.@coefs(2)

smpl @all

delete ym r cumser

endsub