Skip to content

Commit

Permalink
indicator: add stddev v2
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 1, 2023
1 parent 3d4b88f commit b141ae3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/indicator/v2_stddev.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b141ae3

Please sign in to comment.