-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmacd_test.go
81 lines (63 loc) · 2.29 KB
/
macd_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
80
81
package ma_test
import (
"testing"
"github.com/MicahParks/go-ma"
)
func BenchmarkMACDBig_Calculate(b *testing.B) {
_, shortSMA := ma.NewBigSMA(bigPrices[:ma.DefaultShortMACDPeriod])
shortEMA := ma.NewBigEMA(ma.DefaultShortMACDPeriod, shortSMA, nil)
for _, p := range bigPrices[ma.DefaultShortMACDPeriod:ma.DefaultLongMACDPeriod] {
shortEMA.Calculate(p)
}
_, longSMA := ma.NewBigSMA(bigPrices[:ma.DefaultLongMACDPeriod])
longEMA := ma.NewBigEMA(ma.DefaultLongMACDPeriod, longSMA, nil)
macd := ma.NewBigMACD(longEMA, shortEMA)
for _, p := range bigPrices[ma.DefaultLongMACDPeriod:] {
macd.Calculate(p)
}
}
func BenchmarkMACDFloat_Calculate(b *testing.B) {
_, shortSMA := ma.NewSMA(prices[:ma.DefaultShortMACDPeriod])
shortEMA := ma.NewEMA(ma.DefaultShortMACDPeriod, shortSMA, 0)
for _, p := range prices[ma.DefaultShortMACDPeriod:ma.DefaultLongMACDPeriod] {
shortEMA.Calculate(p)
}
_, longSMA := ma.NewSMA(prices[:ma.DefaultLongMACDPeriod])
longEMA := ma.NewEMA(ma.DefaultLongMACDPeriod, longSMA, 0)
macd := ma.NewMACD(longEMA, shortEMA)
for _, p := range prices[ma.DefaultLongMACDPeriod:] {
macd.Calculate(p)
}
}
func TestMACDBig_Calculate(t *testing.T) {
_, shortSMA := ma.NewBigSMA(bigPrices[:ma.DefaultShortMACDPeriod])
shortEMA := ma.NewBigEMA(ma.DefaultShortMACDPeriod, shortSMA, nil)
for _, p := range bigPrices[ma.DefaultShortMACDPeriod:ma.DefaultLongMACDPeriod] {
shortEMA.Calculate(p)
}
_, longSMA := ma.NewBigSMA(bigPrices[:ma.DefaultLongMACDPeriod])
longEMA := ma.NewBigEMA(ma.DefaultLongMACDPeriod, longSMA, nil)
macd := ma.NewBigMACD(longEMA, shortEMA)
var res float64
for i, p := range bigPrices[ma.DefaultLongMACDPeriod:] {
res, _ = macd.Calculate(p).Result.Float64()
if res != results[i] {
t.FailNow()
}
}
}
func TestMACD_Calculate(t *testing.T) {
_, shortSMA := ma.NewSMA(prices[:ma.DefaultShortMACDPeriod])
shortEMA := ma.NewEMA(ma.DefaultShortMACDPeriod, shortSMA, 0)
for _, p := range prices[ma.DefaultShortMACDPeriod:ma.DefaultLongMACDPeriod] {
shortEMA.Calculate(p)
}
_, longSMA := ma.NewSMA(prices[:ma.DefaultLongMACDPeriod])
longEMA := ma.NewEMA(ma.DefaultLongMACDPeriod, longSMA, 0)
macd := ma.NewMACD(longEMA, shortEMA)
for i, p := range prices[ma.DefaultLongMACDPeriod:] {
if macd.Calculate(p).Result != results[i] {
t.FailNow()
}
}
}