Skip to content
forked from c9s/bbgo

Commit

Permalink
adjust ewma truncate size
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 21, 2021
1 parent 943105d commit 540722e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/bbgo/marketdatastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bbgo
import "github.com/c9s/bbgo/pkg/types"

const MaxNumOfKLines = 5_000
const MaxNumOfKLinesTruncate = 1_000
const MaxNumOfKLinesTruncate = 100

// MarketDataStore receives and maintain the public market data
//go:generate callbackgen -type MarketDataStore
Expand Down Expand Up @@ -56,7 +56,7 @@ func (store *MarketDataStore) AddKLine(kline types.KLine) {
}

if len(window) > MaxNumOfKLines {
window = window[MaxNumOfKLinesTruncate:]
window = window[MaxNumOfKLinesTruncate-1:]
}

store.KLineWindows[kline.Interval] = window
Expand Down
4 changes: 2 additions & 2 deletions pkg/indicator/ewma.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

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

//go:generate callbackgen -type EWMA
type EWMA struct {
Expand All @@ -29,7 +29,7 @@ func (inc *EWMA) Update(value float64) {
inc.Values.Push(value)
return
} else if len(inc.Values) > MaxNumOfEWMA {
inc.Values = inc.Values[MaxNumOfEWMATruncateSize:]
inc.Values = inc.Values[MaxNumOfEWMATruncateSize - 1:]
}

ema := (1-multiplier)*inc.Last() + multiplier*value
Expand Down
6 changes: 3 additions & 3 deletions pkg/indicator/sma.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/c9s/bbgo/pkg/types"
)

const MaxNumOfSMA = 1_000
const MaxNumOfSMATruncateSize = 500
const MaxNumOfSMA = 5_000
const MaxNumOfSMATruncateSize = 100

var zeroTime time.Time

Expand Down Expand Up @@ -52,7 +52,7 @@ func (inc *SMA) calculateAndUpdate(kLines []types.KLine) {
inc.Values.Push(sma)

if len(inc.Values) > MaxNumOfSMA {
inc.Values = inc.Values[MaxNumOfSMATruncateSize:]
inc.Values = inc.Values[MaxNumOfSMATruncateSize - 1:]
}

inc.EndTime = kLines[index].EndTime
Expand Down

0 comments on commit 540722e

Please sign in to comment.