qbtrade/pkg/indicator/v2/stddev.go

29 lines
541 B
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package indicatorv2
import "git.qtrade.icu/lychiyu/qbtrade/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
}