optimizer: print equity diff in final report

This commit is contained in:
Raphanus Lo 2022-07-28 12:31:17 +08:00
parent 30978ecbd4
commit 3c0d5727e6

View File

@ -30,6 +30,16 @@ var TotalVolume = func(summaryReport *backtest.SummaryReport) fixedpoint.Value {
return buyVolume.Add(sellVolume) return buyVolume.Add(sellVolume)
} }
var TotalEquityDiff = func(summaryReport *backtest.SummaryReport) fixedpoint.Value {
if len(summaryReport.SymbolReports) == 0 {
return fixedpoint.Zero
}
initEquity := summaryReport.SymbolReports[0].InitialEquityValue()
finalEquity := summaryReport.SymbolReports[0].FinalEquityValue()
return finalEquity.Sub(initEquity)
}
type Metric struct { type Metric struct {
// Labels is the labels of the given parameters // Labels is the labels of the given parameters
Labels []string `json:"labels,omitempty"` Labels []string `json:"labels,omitempty"`
@ -186,8 +196,9 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
o.CurrentParams = make([]interface{}, len(o.Config.Matrix)) o.CurrentParams = make([]interface{}, len(o.Config.Matrix))
var valueFunctions = map[string]MetricValueFunc{ var valueFunctions = map[string]MetricValueFunc{
"totalProfit": TotalProfitMetricValueFunc, "totalProfit": TotalProfitMetricValueFunc,
"totalVolume": TotalVolume, "totalVolume": TotalVolume,
"totalEquityDiff": TotalEquityDiff,
} }
var metrics = map[string][]Metric{} var metrics = map[string][]Metric{}