adjust ewma truncate size

This commit is contained in:
c9s 2021-11-21 22:18:07 +08:00
parent 943105d678
commit 540722e430
3 changed files with 7 additions and 7 deletions

View File

@ -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
@ -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

View File

@ -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 {
@ -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

View File

@ -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
@ -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