mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fixedpoint: positive tester and negative tester
This commit is contained in:
parent
c62330b2c1
commit
56c53958cd
20
pkg/fixedpoint/filter.go
Normal file
20
pkg/fixedpoint/filter.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package fixedpoint
|
||||||
|
|
||||||
|
type Tester func(value Value) bool
|
||||||
|
|
||||||
|
func PositiveTester(value Value) bool {
|
||||||
|
return value.Sign() > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func NegativeTester(value Value) bool {
|
||||||
|
return value.Sign() < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Filter(values []Value, f Tester) (slice []Value) {
|
||||||
|
for _, v := range values {
|
||||||
|
if f(v) {
|
||||||
|
slice = append(slice, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slice
|
||||||
|
}
|
|
@ -304,6 +304,8 @@ func (s *TradeStats) update() {
|
||||||
sort.Sort(fixedpoint.Descending(profitsByOrder))
|
sort.Sort(fixedpoint.Descending(profitsByOrder))
|
||||||
sort.Sort(fixedpoint.Descending(netProfitsByOrder))
|
sort.Sort(fixedpoint.Descending(netProfitsByOrder))
|
||||||
|
|
||||||
|
s.Losses = fixedpoint.Filter(profitsByOrder, fixedpoint.NegativeTester)
|
||||||
|
s.Profits = fixedpoint.Filter(profitsByOrder, fixedpoint.PositiveTester)
|
||||||
s.LargestProfitTrade = profitsByOrder[0]
|
s.LargestProfitTrade = profitsByOrder[0]
|
||||||
s.LargestLossTrade = profitsByOrder[len(profitsByOrder)-1]
|
s.LargestLossTrade = profitsByOrder[len(profitsByOrder)-1]
|
||||||
if s.LargestLossTrade.Sign() > 0 {
|
if s.LargestLossTrade.Sign() > 0 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user