mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53: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 {
|
func (s *RMAStream) Calculate(x float64) float64 {
|
||||||
lambda := 1 / float64(s.window)
|
lambda := 1 / float64(s.window)
|
||||||
tmp := 0.0
|
|
||||||
if s.counter == 0 {
|
if s.counter == 0 {
|
||||||
s.sum = 1
|
s.sum = 1
|
||||||
tmp = x
|
s.previous = x
|
||||||
} else {
|
} else {
|
||||||
if s.Adjust {
|
if s.Adjust {
|
||||||
s.sum = s.sum*(1-lambda) + 1
|
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 {
|
} else {
|
||||||
tmp = s.previous*(1-lambda) + x*lambda
|
s.previous = s.previous*(1-lambda) + x*lambda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.counter++
|
s.counter++
|
||||||
|
|
||||||
s.Slice.Push(tmp)
|
return s.previous
|
||||||
s.previous = tmp
|
|
||||||
return tmp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RMAStream) Truncate() {
|
func (s *RMAStream) Truncate() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user