forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator_stochastic_rsi_test.go
79 lines (67 loc) · 1.42 KB
/
indicator_stochastic_rsi_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
72
73
74
75
76
77
78
79
package techan
import (
"testing"
"github.com/sdcoffey/big"
"github.com/stretchr/testify/assert"
)
func TestStochasticRSIIndicator(t *testing.T) {
indicator := NewStochasticRSIIndicator(NewClosePriceIndicator(mockedTimeSeries), 5)
expectedValues := []float64{
100,
100,
100,
100,
100,
100,
100,
95.9481,
54.5245,
93.1791,
0,
21.6754,
}
indicatorEquals(t, expectedValues, indicator)
}
func TestFastStochasticRSIIndicator(t *testing.T) {
indicator := NewFastStochasticRSIIndicator(NewStochasticRSIIndicator(NewClosePriceIndicator(mockedTimeSeries),
5), 3)
expectedValues := []float64{
0,
0,
100,
100,
100,
100,
100,
98.6494,
83.4909,
81.2173,
49.2346,
38.2848,
}
indicatorEquals(t, expectedValues, indicator)
}
func TestSlowStochasticRSIIndicator(t *testing.T) {
indicator := NewSlowStochasticRSIIndicator(NewFastStochasticRSIIndicator(NewStochasticRSIIndicator(
NewClosePriceIndicator(mockedTimeSeries), 5), 3), 3)
expectedValues := []float64{
0,
0,
33.3333,
66.6667,
100,
100,
100,
99.5498,
94.0468,
87.7858,
71.3142,
56.2456,
}
indicatorEquals(t, expectedValues, indicator)
}
func TestFastStochasticRSIIndicatorNoPriceChange(t *testing.T) {
close := NewClosePriceIndicator(mockTimeSeries("42.0", "42.0"))
rsInd := NewStochasticRSIIndicator(close, 2)
assert.Equal(t, big.NewDecimal(100).FormattedString(2), rsInd.Calculate(1).FormattedString(2))
}