mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
sort metrics
This commit is contained in:
parent
b3da6caddb
commit
b4b4546220
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user