mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fixedpoint: add counter func
This commit is contained in:
parent
e28921879d
commit
c62330b2c1
13
pkg/fixedpoint/count.go
Normal file
13
pkg/fixedpoint/count.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package fixedpoint
|
||||
|
||||
type Counter func(a Value) bool
|
||||
|
||||
func Count(values []Value, counter Counter) int {
|
||||
var c = 0
|
||||
for _, value := range values {
|
||||
if counter(value) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
|
@ -291,6 +291,12 @@ func (s *TradeStats) update() {
|
|||
netProfitsByOrder = append(netProfitsByOrder, sumNetProfit)
|
||||
}
|
||||
|
||||
s.NumOfProfitTrade = fixedpoint.Count(profitsByOrder, func(a fixedpoint.Value) bool {
|
||||
return a.Sign() > 0
|
||||
})
|
||||
s.NumOfLossTrade = fixedpoint.Count(profitsByOrder, func(a fixedpoint.Value) bool {
|
||||
return a.Sign() < 0
|
||||
})
|
||||
s.TotalNetProfit = fixedpoint.Reduce(profitsByOrder, fixedpoint.SumReducer)
|
||||
s.GrossProfit = fixedpoint.Reduce(profitsByOrder, grossProfitReducer)
|
||||
s.GrossLoss = fixedpoint.Reduce(profitsByOrder, grossLossReducer)
|
||||
|
|
Loading…
Reference in New Issue
Block a user