mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-15 03:23:52 +00:00
33 lines
605 B
Go
33 lines
605 B
Go
package indicatorv2
|
|
|
|
import "github.com/c9s/bbgo/pkg/types"
|
|
|
|
type StdDevStream struct {
|
|
*types.Float64Series
|
|
|
|
rawValues *types.Queue
|
|
|
|
window int
|
|
multiplier float64
|
|
}
|
|
|
|
func StdDev(source types.Float64Source, window int) *StdDevStream {
|
|
s := &StdDevStream{
|
|
Float64Series: types.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
|
|
}
|
|
|
|
func (s *StdDevStream) Truncate() {
|
|
s.Slice = generalTruncate(s.Slice)
|
|
}
|