improve/profitStatsTracker: use strconv instead of Sprintf()

This commit is contained in:
Andy Cheng 2023-07-11 10:21:38 +08:00
parent 2a80d708af
commit 928a77cb8b
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -7,6 +7,7 @@ import (
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/indicator" "github.com/c9s/bbgo/pkg/indicator"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"strconv"
) )
// AccumulatedProfitReport For accumulated profit report output // AccumulatedProfitReport For accumulated profit report output
@ -135,15 +136,15 @@ func (r *AccumulatedProfitReport) Output() {
// Output data row // Output data row
for i := 0; i <= r.Window-1; i++ { for i := 0; i <= r.Window-1; i++ {
values := []string{ values := []string{
fmt.Sprintf("%d", i+1), strconv.Itoa(i + 1),
r.symbol, r.symbol,
fmt.Sprintf("%f", r.accumulatedProfitPerInterval.Last(i)), strconv.FormatFloat(r.accumulatedProfitPerInterval.Last(i), 'f', 4, 64),
fmt.Sprintf("%f", r.profitMAPerInterval.Last(i)), strconv.FormatFloat(r.profitMAPerInterval.Last(i), 'f', 4, 64),
fmt.Sprintf("%f", r.accumulatedProfitPerInterval.Last(i)-r.accumulatedProfitPerInterval.Last(i+r.ShortTermProfitWindow)), strconv.FormatFloat(r.accumulatedProfitPerInterval.Last(i)-r.accumulatedProfitPerInterval.Last(i+r.ShortTermProfitWindow), 'f', 4, 64),
fmt.Sprintf("%f", r.accumulatedFeePerInterval.Last(i)), strconv.FormatFloat(r.accumulatedFeePerInterval.Last(i), 'f', 4, 64),
fmt.Sprintf("%f", r.winRatioPerInterval.Last(i)), strconv.FormatFloat(r.winRatioPerInterval.Last(i), 'f', 4, 64),
fmt.Sprintf("%f", r.profitFactorPerInterval.Last(i)), strconv.FormatFloat(r.profitFactorPerInterval.Last(i), 'f', 4, 64),
fmt.Sprintf("%f", r.accumulatedTradesPerInterval.Last(i)), strconv.FormatFloat(r.accumulatedTradesPerInterval.Last(i), 'f', 4, 64),
} }
for j := 0; j < len(r.strategyParameters); j++ { for j := 0; j < len(r.strategyParameters); j++ {
values = append(values, r.strategyParameters[j][1]) values = append(values, r.strategyParameters[j][1])