Skip to content

Commit

Permalink
Truncate emwa slice to be the same size as given kLines
Browse files Browse the repository at this point in the history
  • Loading branch information
kkc committed Oct 19, 2021
1 parent 16fca01 commit 8938478
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/indicator/ewma.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/c9s/bbgo/pkg/types"
)

const MaxNumOfEWMA = 1_000
const MaxNumOfEWMATruncateSize = 500
// These numbers should be aligned with bbgo MaxNumOfKLines and MaxNumOfKLinesTruncate
const MaxNumOfEWMA = 5_000
const MaxNumOfEWMATruncateSize = 1000

//go:generate callbackgen -type EWMA
type EWMA struct {
Expand Down Expand Up @@ -72,6 +73,11 @@ func (inc *EWMA) calculateAndUpdate(allKLines []types.KLine) {
}
}

if len(inc.Values) >= MaxNumOfEWMA {
TruncateSize := MaxNumOfEWMATruncateSize
inc.Values = inc.Values[TruncateSize:]
}

for i := from; i < dataLen; i++ {
var k = allKLines[i]
var ewma = priceF(k)*multiplier + (1-multiplier)*inc.Values[i-1]
Expand Down

0 comments on commit 8938478

Please sign in to comment.