-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathcci_test.go
38 lines (32 loc) · 1.02 KB
/
cci_test.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
38
package indicator
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/types"
)
/*
python:
import pandas as pd
s = pd.Series([0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9])
cci = pd.Series((s - s.rolling(16).mean()) / (0.015 * s.rolling(16).std(ddof=0)), name="CCI")
print(cci)
*/
func Test_CCI(t *testing.T) {
var randomPrices = []byte(`[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]`)
var input []float64
var delta = 4.3e-2
if err := json.Unmarshal(randomPrices, &input); err != nil {
panic(err)
}
t.Run("random_case", func(t *testing.T) {
cci := CCI{IntervalWindow: types.IntervalWindow{Window: 16}}
for _, value := range input {
cci.Update(value)
}
last := cci.Last(0)
assert.InDelta(t, 93.250481, last, delta)
assert.InDelta(t, 81.813449, cci.Index(1), delta)
assert.Equal(t, 50-16+1, cci.Length())
})
}