Skip to content

Commit

Permalink
indicator/v2: add SMA example
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jul 11, 2023
1 parent 66dd550 commit ee9a326
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/indicator/v2/sma_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit ee9a326

Please sign in to comment.