all: rename Minus() to Sub()

This commit is contained in:
c9s 2023-05-26 15:04:58 +08:00
parent 648e99f52a
commit 9fac61351d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
5 changed files with 18 additions and 14 deletions

View File

@ -5,10 +5,11 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/wcharczuk/go-chart/v2"
"github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/interact" "github.com/c9s/bbgo/pkg/interact"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/wcharczuk/go-chart/v2"
) )
func (s *Strategy) InitDrawCommands(profit, cumProfit types.Series) { func (s *Strategy) InitDrawCommands(profit, cumProfit types.Series) {
@ -76,7 +77,7 @@ func (s *Strategy) DrawIndicators(time types.Time) *types.Canvas {
// canvas.Plot("upband", s.ma.Add(s.stdevHigh), time, length) // canvas.Plot("upband", s.ma.Add(s.stdevHigh), time, length)
canvas.Plot("ma", s.ma, time, length) canvas.Plot("ma", s.ma, time, length)
// canvas.Plot("downband", s.ma.Minus(s.stdevLow), time, length) // canvas.Plot("downband", s.ma.Sub(s.stdevLow), time, length)
fmt.Printf("%f %f\n", highestPrice, hi) fmt.Printf("%f %f\n", highestPrice, hi)
canvas.Plot("trend", s.trendLine, time, length) canvas.Plot("trend", s.trendLine, time, length)

View File

@ -408,8 +408,8 @@ type MinusSeriesResult struct {
b Series b Series
} }
// Minus two series, result[i] = a[i] - b[i] // Sub two series, result[i] = a[i] - b[i]
func Minus(a interface{}, b interface{}) SeriesExtend { func Sub(a interface{}, b interface{}) SeriesExtend {
aa := switchIface(a) aa := switchIface(a)
bb := switchIface(b) bb := switchIface(b)
return NewSeries(&MinusSeriesResult{aa, bb}) return NewSeries(&MinusSeriesResult{aa, bb})

View File

@ -22,7 +22,7 @@ func TestQueue(t *testing.T) {
} }
func TestFloat(t *testing.T) { func TestFloat(t *testing.T) {
var a Series = Minus(3., 2.) var a Series = Sub(3., 2.)
assert.Equal(t, a.Last(), 1.) assert.Equal(t, a.Last(), 1.)
assert.Equal(t, a.Index(100), 1.) assert.Equal(t, a.Index(100), 1.)
} }
@ -44,7 +44,7 @@ func TestNextCross(t *testing.T) {
func TestFloat64Slice(t *testing.T) { func TestFloat64Slice(t *testing.T) {
var a = floats.Slice{1.0, 2.0, 3.0} var a = floats.Slice{1.0, 2.0, 3.0}
var b = floats.Slice{1.0, 2.0, 3.0} var b = floats.Slice{1.0, 2.0, 3.0}
var c Series = Minus(&a, &b) var c Series = Sub(&a, &b)
a = append(a, 4.0) a = append(a, 4.0)
b = append(b, 3.0) b = append(b, 3.0)
assert.Equal(t, c.Last(), 1.) assert.Equal(t, c.Last(), 1.)

View File

@ -2,6 +2,9 @@ package types
import "github.com/c9s/bbgo/pkg/datatype/floats" import "github.com/c9s/bbgo/pkg/datatype/floats"
// SeriesBase is a wrapper of the Series interface
// You can assign a data container that implements the Series interface
// And this SeriesBase struct provides the implemented methods for manipulating your data
type SeriesBase struct { type SeriesBase struct {
Series Series
} }
@ -68,7 +71,7 @@ func (s *SeriesBase) Add(b interface{}) SeriesExtend {
} }
func (s *SeriesBase) Minus(b interface{}) SeriesExtend { func (s *SeriesBase) Minus(b interface{}) SeriesExtend {
return Minus(s, b) return Sub(s, b)
} }
func (s *SeriesBase) Div(b interface{}) SeriesExtend { func (s *SeriesBase) Div(b interface{}) SeriesExtend {

View File

@ -126,7 +126,7 @@ func (s *IntervalProfitCollector) GetSharpe() float64 {
if s.Profits == nil { if s.Profits == nil {
panic("profits array empty. Did you create IntervalProfitCollector instance using NewIntervalProfitCollector?") panic("profits array empty. Did you create IntervalProfitCollector instance using NewIntervalProfitCollector?")
} }
return Sharpe(Minus(s.Profits, 1.), s.Profits.Length(), true, false) return Sharpe(Sub(s.Profits, 1.), s.Profits.Length(), true, false)
} }
// Get sortino value with the interval of profit collected. // Get sortino value with the interval of profit collected.
@ -138,11 +138,11 @@ func (s *IntervalProfitCollector) GetSortino() float64 {
if s.Profits == nil { if s.Profits == nil {
panic("profits array empty. Did you create IntervalProfitCollector instance using NewIntervalProfitCollector?") panic("profits array empty. Did you create IntervalProfitCollector instance using NewIntervalProfitCollector?")
} }
return Sortino(Minus(s.Profits, 1.), 0., s.Profits.Length(), true, false) return Sortino(Sub(s.Profits, 1.), 0., s.Profits.Length(), true, false)
} }
func (s *IntervalProfitCollector) GetOmega() float64 { func (s *IntervalProfitCollector) GetOmega() float64 {
return Omega(Minus(s.Profits, 1.)) return Omega(Sub(s.Profits, 1.))
} }
func (s IntervalProfitCollector) MarshalYAML() (interface{}, error) { func (s IntervalProfitCollector) MarshalYAML() (interface{}, error) {