Skip to content

Commit 56c5395

Browse files
committed
fixedpoint: positive tester and negative tester
1 parent c62330b commit 56c5395

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/fixedpoint/filter.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fixedpoint
2+
3+
type Tester func(value Value) bool
4+
5+
func PositiveTester(value Value) bool {
6+
return value.Sign() > 0
7+
}
8+
9+
func NegativeTester(value Value) bool {
10+
return value.Sign() < 0
11+
}
12+
13+
func Filter(values []Value, f Tester) (slice []Value) {
14+
for _, v := range values {
15+
if f(v) {
16+
slice = append(slice, v)
17+
}
18+
}
19+
return slice
20+
}

pkg/types/trade_stats.go

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ func (s *TradeStats) update() {
304304
sort.Sort(fixedpoint.Descending(profitsByOrder))
305305
sort.Sort(fixedpoint.Descending(netProfitsByOrder))
306306

307+
s.Losses = fixedpoint.Filter(profitsByOrder, fixedpoint.NegativeTester)
308+
s.Profits = fixedpoint.Filter(profitsByOrder, fixedpoint.PositiveTester)
307309
s.LargestProfitTrade = profitsByOrder[0]
308310
s.LargestLossTrade = profitsByOrder[len(profitsByOrder)-1]
309311
if s.LargestLossTrade.Sign() > 0 {

0 commit comments

Comments
 (0)