mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
Merge pull request #1230 from c9s/c9s/indicator-sma-example
This commit is contained in:
commit
32cd19b852
|
@ -26,7 +26,7 @@ type BOLLStream struct {
|
|||
// -> calculate stdDev -> calculate bandWidth -> get latest SMA -> upBand, downBand
|
||||
func BOLL(source types.Float64Source, window int, k float64) *BOLLStream {
|
||||
// bind these indicators before our main calculator
|
||||
sma := SMA2(source, window)
|
||||
sma := SMA(source, window)
|
||||
stdDev := StdDev(source, window)
|
||||
|
||||
s := &BOLLStream{
|
||||
|
|
|
@ -12,7 +12,7 @@ type SMAStream struct {
|
|||
rawValues *types.Queue
|
||||
}
|
||||
|
||||
func SMA2(source types.Float64Source, window int) *SMAStream {
|
||||
func SMA(source types.Float64Source, window int) *SMAStream {
|
||||
s := &SMAStream{
|
||||
Float64Series: types.NewFloat64Series(),
|
||||
window: window,
|
||||
|
|
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