-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathalma_test.go
61 lines (55 loc) · 1.26 KB
/
alma_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
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])
sigma = 6
offset = 0.9
size = 5
result = ta.alma(data, size, sigma, offset)
print(result)
*/
func Test_ALMA(t *testing.T) {
var Delta = 0.01
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
want float64
next float64
all int
}{
{
name: "random_case",
kLines: buildKLines(input),
want: 5.60785,
next: 4.60785,
all: 26,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
alma := ALMA{
IntervalWindow: types.IntervalWindow{Window: 5},
Offset: 0.9,
Sigma: 6,
}
alma.CalculateAndUpdate(tt.kLines)
assert.InDelta(t, tt.want, alma.Last(0), Delta)
assert.InDelta(t, tt.next, alma.Index(1), Delta)
assert.Equal(t, tt.all, alma.Length())
})
}
}