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)
}
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 {
// Labels is the labels of the given parameters
Labels []string `json:"labels,omitempty"`
@ -188,6 +198,7 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
var valueFunctions = map[string]MetricValueFunc{
"totalProfit": TotalProfitMetricValueFunc,
"totalVolume": TotalVolume,
"totalEquityDiff": TotalEquityDiff,
}
var metrics = map[string][]Metric{}