Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Last active April 30, 2019 04:30
Show Gist options
  • Save DustinAlandzes/a43a887eb4be38e26970c22dace49c1e to your computer and use it in GitHub Desktop.
Save DustinAlandzes/a43a887eb4be38e26970c22dace49c1e to your computer and use it in GitHub Desktop.
#http://www.long-memory.com/hurst/hurst.cpp
#The calculation requires at least 4 data points.
# https://en.wikipedia.org/wiki/Rescaled_range
data = []
array1 = []
array2 = []
for n in range(len(data)):
totalR = 0
totalS = 0
NoOfPeriods = len(data) - n + 1
for period in range(len(NoOfPeriods)):
for i in range(n):
array1.append(data[period + i])
for i in range(n):
array2.append(0)
Summ = 0
for it1 in array1:
Summ = Summ + it1
SumSquared = SumSquared + (it1 * it1)
Mean = Summ / n
S = sqrt((SummSquared - (Summ * Summ) / n) / n)
for it1 in array1:
it1 = it1 - Mean
for i2 in array2:
i2 = i2 + array1[i1]
Maxi = array2[0]
Mini = array2[0]
for it2 in array2:
if it2 > Maxi:
Maxi = it2
if it2 < Mini:
Mini = it2
R = Maxi - Mini
totalR = totalR + R
totalS = totalS + S
R = totalR / NoOfPeriods
S = totalS / NoOfPeriods
RS = R/S
PlottedPointNo = n - 3;
graph[PlottedPointNo].x = (log(n)) / logten;
graph[PlottedPointNo].y = (log(RS)) / logten;
Sumx = 0
Sumy = 0
Sumxy = 0
Sumxx = 0
for i in range():
Sumx = Sumx + graph[i].x;
Sumy = Sumy + graph[i].y;
Sumxy = Sumxy + (graph[i].x) * (graph[i].y);
Sumxx = Sumxx + (graph[i].x) * (graph[i].x);
H = (Sumxy - ((Sumx * Sumy) / NoOfPlottedPoints)) / (Sumxx - ((Sumx * Sumx) / NoOfPlottedPoints))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment