forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator_relative_strength_test.go
57 lines (48 loc) · 1.02 KB
/
indicator_relative_strength_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
package techan
import (
"math"
"testing"
"github.com/sdcoffey/big"
"github.com/stretchr/testify/assert"
)
func TestRelativeStrengthIndexIndicator(t *testing.T) {
indicator := NewRelativeStrengthIndexIndicator(NewClosePriceIndicator(mockedTimeSeries), 3)
expectedValues := []float64{
0,
0,
0,
0,
0,
0,
57.9952,
54.0751,
21.451,
44.7739,
14.1542,
21.2794,
}
indicatorEquals(t, expectedValues, indicator)
}
func TestRelativeStrengthIndicator(t *testing.T) {
indicator := NewRelativeStrengthIndicator(NewClosePriceIndicator(mockedTimeSeries), 3)
expectedValues := []float64{
0,
0,
0,
0,
0,
0,
1.3807,
1.1775,
0.2731,
0.8107,
0.1649,
0.2703,
}
indicatorEquals(t, expectedValues, indicator)
}
func TestRelativeStrengthIndicatorNoPriceChange(t *testing.T) {
close := NewClosePriceIndicator(mockTimeSeries("42.0", "42.0"))
rsInd := NewRelativeStrengthIndicator(close, 2)
assert.Equal(t, big.NewDecimal(math.Inf(1)).FormattedString(2), rsInd.Calculate(1).FormattedString(2))
}