mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
sort metrics
This commit is contained in:
parent
b3da6caddb
commit
b4b4546220
|
@ -6,12 +6,12 @@
|
||||||
matrix:
|
matrix:
|
||||||
- type: iterate
|
- type: iterate
|
||||||
path: '/exchangeStrategies/0/bollmaker/interval'
|
path: '/exchangeStrategies/0/bollmaker/interval'
|
||||||
values: ["1m", "5m", "30m"]
|
values: ["1m", "5m"]
|
||||||
|
|
||||||
- type: range
|
- type: range
|
||||||
path: '/exchangeStrategies/0/bollmaker/amount'
|
path: '/exchangeStrategies/0/bollmaker/amount'
|
||||||
min: 20.0
|
min: 20.0
|
||||||
max: 100.0
|
max: 40.0
|
||||||
step: 20.0
|
step: 20.0
|
||||||
|
|
||||||
- type: range
|
- type: range
|
||||||
|
|
|
@ -2,6 +2,7 @@ package optimizer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/evanphx/json-patch/v5"
|
"github.com/evanphx/json-patch/v5"
|
||||||
|
|
||||||
|
@ -16,8 +17,8 @@ var TotalProfitMetricValueFunc = func(summaryReport *backtest.SummaryReport) fix
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
Params []interface{}
|
Params []interface{} `json:"params,omitempty"`
|
||||||
Value fixedpoint.Value
|
Value fixedpoint.Value `json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GridOptimizer struct {
|
type GridOptimizer struct {
|
||||||
|
@ -124,6 +125,7 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) error {
|
||||||
// TODO: Add other metric value function
|
// TODO: Add other metric value function
|
||||||
metricValue := TotalProfitMetricValueFunc(summaryReport)
|
metricValue := TotalProfitMetricValueFunc(summaryReport)
|
||||||
|
|
||||||
|
// TODO: replace this with a local variable and return it as a function result
|
||||||
o.Metrics = append(o.Metrics, Metric{
|
o.Metrics = append(o.Metrics, Metric{
|
||||||
Params: o.CurrentParams,
|
Params: o.CurrentParams,
|
||||||
Value: metricValue,
|
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