-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathssf_test.go
71 lines (64 loc) · 1.4 KB
/
ssf_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package indicator
import (
"encoding/json"
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/stretchr/testify/assert"
)
/*
python:
import pandas as pd
import pandas_ta as ta
data = 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])
size = 5
result = ta.ssf(data, size, 2)
print(result)
result = ta.ssf(data, size, 3)
print(result)
*/
func Test_SSF(t *testing.T) {
var Delta = 0.00001
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]`)
var input []fixedpoint.Value
if err := json.Unmarshal(randomPrices, &input); err != nil {
panic(err)
}
tests := []struct {
name string
kLines []types.KLine
poles int
want float64
next float64
all int
}{
{
name: "pole2",
kLines: buildKLines(input),
poles: 2,
want: 8.721776,
next: 7.723223,
all: 30,
},
{
name: "pole3",
kLines: buildKLines(input),
poles: 3,
want: 8.687588,
next: 7.668013,
all: 30,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ssf := SSF{
IntervalWindow: types.IntervalWindow{Window: 5},
Poles: tt.poles,
}
ssf.CalculateAndUpdate(tt.kLines)
assert.InDelta(t, tt.want, ssf.Last(0), Delta)
assert.InDelta(t, tt.next, ssf.Index(1), Delta)
assert.Equal(t, tt.all, ssf.Length())
})
}
}