bbgo_origin/pkg/indicator/v2/subtract_test.go

31 lines
789 B
Go
Raw Permalink Normal View History

2023-07-10 08:54:22 +00:00
package indicatorv2
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
2023-05-29 13:44:23 +00:00
func Test_v2_Subtract(t *testing.T) {
stream := &types.StandardStream{}
2023-06-01 04:39:30 +00:00
kLines := KLines(stream, "", "")
closePrices := ClosePrices(kLines)
fastEMA := EWMA2(closePrices, 10)
slowEMA := EWMA2(closePrices, 25)
subtract := Subtract(fastEMA, slowEMA)
for i := .0; i < 50.0; i++ {
stream.EmitKLineClosed(types.KLine{Close: fixedpoint.NewFromFloat(19_000.0 + i)})
}
2023-07-10 08:54:22 +00:00
t.Logf("fastEMA: %+v", fastEMA.Slice)
t.Logf("slowEMA: %+v", slowEMA.Slice)
assert.Equal(t, len(subtract.a), len(subtract.b))
2023-07-10 08:54:22 +00:00
assert.Equal(t, len(subtract.a), len(subtract.Slice))
assert.InDelta(t, subtract.Slice[0], subtract.a[0]-subtract.b[0], 0.0001)
}