mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
aggregate total profit and total unrealized profit
This commit is contained in:
parent
11ad34e9f7
commit
960f967c34
|
@ -39,6 +39,10 @@ type SummaryReport struct {
|
|||
InitialTotalBalances types.BalanceMap `json:"initialTotalBalances"`
|
||||
FinalTotalBalances types.BalanceMap `json:"finalTotalBalances"`
|
||||
|
||||
// TotalProfit is the profit aggregated from the symbol reports
|
||||
TotalProfit fixedpoint.Value `json:"totalProfit,omitempty"`
|
||||
TotalUnrealizedProfit fixedpoint.Value `json:"totalUnrealizedProfit,omitempty"`
|
||||
|
||||
SymbolReports []SessionSymbolReport `json:"symbolReports,omitempty"`
|
||||
|
||||
Manifests Manifests `json:"manifests,omitempty"`
|
||||
|
|
|
@ -492,6 +492,8 @@ var BacktestCmd = &cobra.Command{
|
|||
|
||||
summaryReport.Symbols = append(summaryReport.Symbols, symbol)
|
||||
summaryReport.SymbolReports = append(summaryReport.SymbolReports, *symbolReport)
|
||||
summaryReport.TotalProfit = symbolReport.PnL.Profit
|
||||
summaryReport.TotalUnrealizedProfit = symbolReport.PnL.UnrealizedProfit
|
||||
|
||||
// write report to a file
|
||||
if generatingReport {
|
||||
|
@ -500,24 +502,32 @@ var BacktestCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
symbolReport.Print(wantBaseAssetBaseline)
|
||||
}
|
||||
}
|
||||
|
||||
if generatingReport && reportFileInSubDir {
|
||||
if generatingReport {
|
||||
summaryReportFile := filepath.Join(reportDir, "summary.json")
|
||||
|
||||
// output summary report filepath to stdout, so that our optimizer can read from it
|
||||
fmt.Println(summaryReportFile)
|
||||
|
||||
if err := util.WriteJsonFile(summaryReportFile, summaryReport); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// append report index
|
||||
if err := backtest.AddReportIndexRun(outputDirectory, backtest.Run{
|
||||
ID: runID,
|
||||
Config: userConfig,
|
||||
Time: time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
if reportFileInSubDir {
|
||||
if err := backtest.AddReportIndexRun(outputDirectory, backtest.Run{
|
||||
ID: runID,
|
||||
Config: userConfig,
|
||||
Time: time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, symbolReport := range summaryReport.SymbolReports {
|
||||
symbolReport.Print(wantBaseAssetBaseline)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ func (e *LocalProcessExecutor) Execute(configJson []byte) error {
|
|||
}
|
||||
|
||||
c := exec.Command(e.Bin, "backtest", "--config", tf.Name(), "--output", e.OutputDir, "--subdir")
|
||||
log.Infof("cmd: %+v", c)
|
||||
|
||||
// c.Output()
|
||||
if e.CombineOutput {
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
)
|
||||
|
||||
|
@ -60,7 +62,6 @@ func (b Balance) String() (o string) {
|
|||
return o
|
||||
}
|
||||
|
||||
|
||||
type BalanceSnapshot struct {
|
||||
Balances BalanceMap `json:"balances"`
|
||||
Session string `json:"session"`
|
||||
|
@ -191,15 +192,16 @@ func (m BalanceMap) Print() {
|
|||
continue
|
||||
}
|
||||
|
||||
fmt.Printf(" %s: %v", balance.Currency, balance.Available)
|
||||
o := fmt.Sprintf(" %s: %v", balance.Currency, balance.Available)
|
||||
if balance.Locked.Sign() > 0 {
|
||||
fmt.Printf(" (locked %v)", balance.Locked)
|
||||
o += fmt.Sprintf(" (locked %v)", balance.Locked)
|
||||
}
|
||||
|
||||
if balance.Borrowed.Sign() > 0 {
|
||||
fmt.Printf(" (borrowed %v)", balance.Borrowed)
|
||||
o += fmt.Sprintf(" (borrowed %v)", balance.Borrowed)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
log.Infoln(o)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user