-
Notifications
You must be signed in to change notification settings - Fork 17
/
cyber_cycle.go
37 lines (28 loc) · 1.14 KB
/
cyber_cycle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package go_ehlers_indicators
import "math"
// CyberCycle Indicator with alpha set to standard ema alpha: 2.0 / (windowLen + 1)
// from paper: https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
func CyberCycle(vals []float64, windowLen int) []float64 {
out := make([]float64, len(vals))
alpha := 2.0 / float64(windowLen+1)
smooth := make([]float64, len(vals))
for i := windowLen; i < len(out); i++ {
smooth[i] = (vals[i] + 2*vals[i-1] + 2*vals[i-2] + vals[i-3]) / 6
cc := math.Pow(1-0.5*alpha, 2)*(smooth[i]-2*smooth[i-1]+smooth[i-2]) + 2*(1-alpha)*out[i-1] - math.Pow(1-alpha, 2)*out[i-2]
out[i] = cc
}
return out
}
// CyberCycle Indicator with custom alpha
func CyberCycleAlpha(vals []float64, windowLen int, alpha float64) []float64 {
out := make([]float64, len(vals))
for i := windowLen; i < len(out); i++ {
smooth := make([]float64, windowLen)
for j := 3; j < len(smooth); j++ {
smooth[i] = (vals[i-j] + 2*vals[i-j-1] + 2*vals[i-j-2] + vals[i-j-3]) / 6
}
cc := math.Pow(1-0.5*alpha, 2)*(smooth[windowLen-1]-2*smooth[windowLen-2]) + 2*(1-alpha)*out[i-1] - math.Pow(1-alpha, 2)*out[i-2]
out[i] = cc
}
return out
}