mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
Merge pull request #1689 from anywhy/fix_float64_series
fix float64 series use mean or stdev function result is zero
This commit is contained in:
commit
baffefac07
|
@ -13,7 +13,7 @@ type Float64Series struct {
|
||||||
func NewFloat64Series(v ...float64) *Float64Series {
|
func NewFloat64Series(v ...float64) *Float64Series {
|
||||||
s := &Float64Series{}
|
s := &Float64Series{}
|
||||||
s.Slice = v
|
s.Slice = v
|
||||||
s.SeriesBase.Series = s.Slice
|
s.SeriesBase.Series = &s.Slice
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
pkg/types/series_float64_test.go
Normal file
18
pkg/types/series_float64_test.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSeriesBaseFuncWithPushData(t *testing.T) {
|
||||||
|
series := NewFloat64Series(0.5, 1.0)
|
||||||
|
series.Push(2.5)
|
||||||
|
series.Push(3.0)
|
||||||
|
series.Push(4.0)
|
||||||
|
mean := series.Mean(5)
|
||||||
|
assert.Equal(t, 2.2, mean)
|
||||||
|
stdev := series.Stdev(5)
|
||||||
|
assert.Equal(t, 1.2884098726725126, stdev)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user