-
Notifications
You must be signed in to change notification settings - Fork 144
/
indicator_exponential_moving_average_test.go
62 lines (51 loc) · 1.23 KB
/
indicator_exponential_moving_average_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
package techan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExponentialMovingAverage(t *testing.T) {
t.Run("Default Case", func(t *testing.T) {
expectedValues := []float64{
0,
0,
0,
64,
63.82,
63.568,
63.7048,
63.7629,
63.4377,
63.4106,
62.5784,
62.151,
}
closePriceIndicator := NewClosePriceIndicator(mockedTimeSeries)
indicatorEquals(t, expectedValues, NewEMAIndicator(closePriceIndicator, 4))
})
t.Run("Expands Result Cache", func(t *testing.T) {
closeIndicator := NewClosePriceIndicator(randomTimeSeries(1001))
ema := NewEMAIndicator(closeIndicator, 20)
ema.Calculate(1000)
emaStruct, ok := ema.(cachedIndicator)
assert.True(t, ok)
assert.EqualValues(t, 1001, len(emaStruct.cache()))
})
}
func BenchmarkExponetialMovingAverage(b *testing.B) {
size := 10000
ts := randomTimeSeries(size)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ema := NewEMAIndicator(NewClosePriceIndicator(ts), 10)
ema.Calculate(size - 1)
}
}
func BenchmarkExponentialMovingAverage_Cached(b *testing.B) {
size := 10000
ts := randomTimeSeries(size)
ema := NewEMAIndicator(NewClosePriceIndicator(ts), 10)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ema.Calculate(size - 1)
}
}