mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fix duplicate rma value
This commit is contained in:
parent
4c1654652e
commit
22a7232e8b
|
@ -34,23 +34,20 @@ func RMA2(source types.Float64Source, window int, adjust bool) *RMAStream {
|
|||
|
||||
func (s *RMAStream) Calculate(x float64) float64 {
|
||||
lambda := 1 / float64(s.window)
|
||||
tmp := 0.0
|
||||
if s.counter == 0 {
|
||||
s.sum = 1
|
||||
tmp = x
|
||||
s.previous = x
|
||||
} else {
|
||||
if s.Adjust {
|
||||
s.sum = s.sum*(1-lambda) + 1
|
||||
tmp = s.previous + (x-s.previous)/s.sum
|
||||
s.previous = s.previous + (x-s.previous)/s.sum
|
||||
} else {
|
||||
tmp = s.previous*(1-lambda) + x*lambda
|
||||
s.previous = s.previous*(1-lambda) + x*lambda
|
||||
}
|
||||
}
|
||||
s.counter++
|
||||
|
||||
s.Slice.Push(tmp)
|
||||
s.previous = tmp
|
||||
return tmp
|
||||
return s.previous
|
||||
}
|
||||
|
||||
func (s *RMAStream) Truncate() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user