mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
indicator: add stddev v2
This commit is contained in:
parent
3d4b88fa7d
commit
b141ae3ece
28
pkg/indicator/v2_stddev.go
Normal file
28
pkg/indicator/v2_stddev.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package indicator
|
||||
|
||||
import "github.com/c9s/bbgo/pkg/types"
|
||||
|
||||
type StdDevStream struct {
|
||||
Float64Series
|
||||
|
||||
rawValues *types.Queue
|
||||
|
||||
window int
|
||||
multiplier float64
|
||||
}
|
||||
|
||||
func StdDev2(source Float64Source, window int) *StdDevStream {
|
||||
s := &StdDevStream{
|
||||
Float64Series: NewFloat64Series(),
|
||||
rawValues: types.NewQueue(window),
|
||||
window: window,
|
||||
}
|
||||
s.Bind(source, s)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *StdDevStream) Calculate(x float64) float64 {
|
||||
s.rawValues.Update(x)
|
||||
var std = s.rawValues.Stdev()
|
||||
return std
|
||||
}
|
Loading…
Reference in New Issue
Block a user