mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
all: rename Minus() to Sub()
This commit is contained in:
parent
648e99f52a
commit
9fac61351d
|
@ -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)
|
||||||
|
|
|
@ -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})
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"os"
|
// "os"
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -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.)
|
||||||
|
@ -233,9 +233,9 @@ func TestPlot(t *testing.T) {
|
||||||
ct.Plot("test", &a, Time(time.Now()), 4)
|
ct.Plot("test", &a, Time(time.Now()), 4)
|
||||||
assert.Equal(t, ct.Interval, Interval5m)
|
assert.Equal(t, ct.Interval, Interval5m)
|
||||||
assert.Equal(t, ct.Series[0].(chart.TimeSeries).Len(), 4)
|
assert.Equal(t, ct.Series[0].(chart.TimeSeries).Len(), 4)
|
||||||
//f, _ := os.Create("output.png")
|
// f, _ := os.Create("output.png")
|
||||||
//defer f.Close()
|
// defer f.Close()
|
||||||
//ct.Render(chart.PNG, f)
|
// ct.Render(chart.PNG, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user