mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
indicator/v2: add SMA example
This commit is contained in:
parent
66dd5507d1
commit
ee9a3269b6
22
pkg/indicator/v2/sma_test.go
Normal file
22
pkg/indicator/v2/sma_test.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package indicatorv2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func TestSMA(t *testing.T) {
|
||||
source := types.NewFloat64Series()
|
||||
sma := SMA(source, 9)
|
||||
|
||||
data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
for _, d := range data {
|
||||
source.PushAndEmit(d)
|
||||
}
|
||||
|
||||
assert.InDelta(t, 5, sma.Last(0), 0.001)
|
||||
assert.InDelta(t, 4.5, sma.Last(1), 0.001)
|
||||
}
|
Loading…
Reference in New Issue
Block a user