mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
adjust ewma truncate size
This commit is contained in:
parent
943105d678
commit
540722e430
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user