sort metrics

This commit is contained in:
c9s 2022-05-19 20:36:56 +08:00
parent b3da6caddb
commit b4b4546220
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 16 additions and 5 deletions

View File

@ -6,12 +6,12 @@
matrix:
- type: iterate
path: '/exchangeStrategies/0/bollmaker/interval'
values: ["1m", "5m", "30m"]
values: ["1m", "5m"]
- type: range
path: '/exchangeStrategies/0/bollmaker/amount'
min: 20.0
max: 100.0
max: 40.0
step: 20.0
- type: range

View File

@ -2,6 +2,7 @@ package optimizer
import (
"fmt"
"sort"
"github.com/evanphx/json-patch/v5"
@ -16,8 +17,8 @@ var TotalProfitMetricValueFunc = func(summaryReport *backtest.SummaryReport) fix
}
type Metric struct {
Params []interface{}
Value fixedpoint.Value
Params []interface{} `json:"params,omitempty"`
Value fixedpoint.Value `json:"value,omitempty"`
}
type GridOptimizer struct {
@ -124,6 +125,7 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) error {
// TODO: Add other metric value function
metricValue := TotalProfitMetricValueFunc(summaryReport)
// TODO: replace this with a local variable and return it as a function result
o.Metrics = append(o.Metrics, Metric{
Params: o.CurrentParams,
Value: metricValue,
@ -147,5 +149,14 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) error {
}
}
return wrapper(configJson)
err := wrapper(configJson)
// sort metrics
sort.Slice(o.Metrics, func(i, j int) bool {
a := o.Metrics[i].Value
b := o.Metrics[j].Value
return a.Compare(b) > 0
})
log.Infof("metrics: %+v", o.Metrics)
return err
}