mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
indicator: use pointer for float64series
This commit is contained in:
parent
ea3b1cc937
commit
9d9f898f17
|
@ -11,8 +11,8 @@ type Float64Series struct {
|
|||
slice floats.Slice
|
||||
}
|
||||
|
||||
func NewFloat64Series(v ...float64) Float64Series {
|
||||
s := Float64Series{}
|
||||
func NewFloat64Series(v ...float64) *Float64Series {
|
||||
s := &Float64Series{}
|
||||
s.slice = v
|
||||
s.SeriesBase.Series = s.slice
|
||||
return s
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package indicator
|
||||
|
||||
type ATRPStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
}
|
||||
|
||||
func ATRP2(source KLineSubscription, window int) *ATRPStream {
|
||||
s := &ATRPStream{}
|
||||
s := &ATRPStream{
|
||||
Float64Series: NewFloat64Series(),
|
||||
}
|
||||
tr := TR2(source)
|
||||
atr := RMA2(tr, window, true)
|
||||
atr.OnUpdate(func(x float64) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package indicator
|
||||
|
||||
type CMAStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
}
|
||||
|
||||
func CMA2(source Float64Source) *CMAStream {
|
||||
|
|
|
@ -13,7 +13,7 @@ const (
|
|||
|
||||
// CrossStream subscribes 2 upstreams, and calculate the cross signal
|
||||
type CrossStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
a, b floats.Slice
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package indicator
|
||||
|
||||
type EWMAStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
window int
|
||||
multiplier float64
|
||||
|
|
|
@ -41,7 +41,7 @@ func Test_MACD2(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
prices := &PriceStream{}
|
||||
prices := ClosePrices(nil)
|
||||
macd := MACD2(prices, 12, 26, 9)
|
||||
for _, k := range tt.kLines {
|
||||
prices.EmitUpdate(k.Close.Float64())
|
||||
|
|
|
@ -3,7 +3,7 @@ package indicator
|
|||
import "github.com/c9s/bbgo/pkg/datatype/floats"
|
||||
|
||||
type MultiplyStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
a, b floats.Slice
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type PivotHighStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
rawValues floats.Slice
|
||||
window, rightWindow int
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type PivotLowStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
rawValues floats.Slice
|
||||
window, rightWindow int
|
||||
}
|
||||
|
|
|
@ -11,22 +11,23 @@ type KLineSubscription interface {
|
|||
}
|
||||
|
||||
type PriceStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
mapper KLineValueMapper
|
||||
}
|
||||
|
||||
func Price(source KLineSubscription, mapper KLineValueMapper) *PriceStream {
|
||||
s := &PriceStream{
|
||||
Float64Series: NewFloat64Series(),
|
||||
mapper: mapper,
|
||||
}
|
||||
|
||||
s.SeriesBase.Series = s.slice
|
||||
|
||||
if source != nil {
|
||||
source.AddSubscriber(func(k types.KLine) {
|
||||
v := s.mapper(k)
|
||||
s.PushAndEmit(v)
|
||||
})
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package indicator
|
|||
|
||||
type RMAStream struct {
|
||||
// embedded structs
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
// config fields
|
||||
Adjust bool
|
||||
|
|
|
@ -2,7 +2,7 @@ package indicator
|
|||
|
||||
type RSIStream struct {
|
||||
// embedded structs
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
// config fields
|
||||
window int
|
||||
|
|
|
@ -67,7 +67,7 @@ func Test_RSI2(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// RSI2()
|
||||
prices := &PriceStream{}
|
||||
prices := ClosePrices(nil)
|
||||
rsi := RSI2(prices, tt.window)
|
||||
|
||||
t.Logf("data length: %d", len(tt.values))
|
||||
|
|
|
@ -3,7 +3,7 @@ package indicator
|
|||
import "github.com/c9s/bbgo/pkg/types"
|
||||
|
||||
type SMAStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
window int
|
||||
rawValues *types.Queue
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package indicator
|
|||
import "github.com/c9s/bbgo/pkg/types"
|
||||
|
||||
type StdDevStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
rawValues *types.Queue
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
// SubtractStream subscribes 2 upstream data, and then subtract these 2 values
|
||||
type SubtractStream struct {
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
a, b floats.Slice
|
||||
i int
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
// This TRStream calculates the ATR first
|
||||
type TRStream struct {
|
||||
// embedded struct
|
||||
Float64Series
|
||||
*Float64Series
|
||||
|
||||
// private states
|
||||
previousClose float64
|
||||
|
|
Loading…
Reference in New Issue
Block a user