mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
indicator: implement Truncate method on the indicators
This commit is contained in:
parent
4f1b216fbf
commit
8ce587f5f5
|
@ -55,3 +55,7 @@ func (s *BOLLStream) Calculate(v float64) float64 {
|
|||
band := stdDev * s.k
|
||||
return band
|
||||
}
|
||||
|
||||
func (s *BOLLStream) Truncate() {
|
||||
s.Slice = generalTruncate(s.Slice)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
)
|
||||
|
||||
const MaxNumOfRMA = 1000
|
||||
const MaxNumOfRMATruncateSize = 500
|
||||
|
||||
type RMAStream struct {
|
||||
// embedded structs
|
||||
|
@ -51,9 +50,7 @@ func (s *RMAStream) Calculate(x float64) float64 {
|
|||
}
|
||||
|
||||
func (s *RMAStream) Truncate() {
|
||||
if len(s.Slice) > MaxNumOfRMA {
|
||||
s.Slice = s.Slice[MaxNumOfRMATruncateSize-1:]
|
||||
}
|
||||
s.Slice = generalTruncate(s.Slice)
|
||||
}
|
||||
|
||||
func checkWindow(window int) {
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
const MaxNumOfSMA = 5_000
|
||||
|
||||
type SMAStream struct {
|
||||
*types.Float64Series
|
||||
window int
|
||||
|
@ -29,5 +27,5 @@ func (s *SMAStream) Calculate(v float64) float64 {
|
|||
}
|
||||
|
||||
func (s *SMAStream) Truncate() {
|
||||
s.Slice = s.Slice.Truncate(MaxNumOfSMA)
|
||||
s.Slice = generalTruncate(s.Slice)
|
||||
}
|
||||
|
|
|
@ -26,3 +26,7 @@ func (s *StdDevStream) Calculate(x float64) float64 {
|
|||
var std = s.rawValues.Stdev()
|
||||
return std
|
||||
}
|
||||
|
||||
func (s *StdDevStream) Truncate() {
|
||||
s.Slice = generalTruncate(s.Slice)
|
||||
}
|
||||
|
|
16
pkg/indicator/v2/truncate.go
Normal file
16
pkg/indicator/v2/truncate.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package indicatorv2
|
||||
|
||||
// MaxSliceSize is the maximum slice size
|
||||
// byte size = 8 * 5000 = 40KB per slice
|
||||
const MaxSliceSize = 5000
|
||||
|
||||
// TruncateSize is the truncate size for the slice per truncate call
|
||||
const TruncateSize = 1000
|
||||
|
||||
func generalTruncate(slice []float64) []float64 {
|
||||
if len(slice) < MaxSliceSize {
|
||||
return slice
|
||||
}
|
||||
|
||||
return slice[TruncateSize-1:]
|
||||
}
|
Loading…
Reference in New Issue
Block a user