2022-05-06 11:16:15 +00:00
|
|
|
package backtest
|
|
|
|
|
|
|
|
import (
|
2022-05-09 11:27:02 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2022-05-06 11:16:15 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/accounting/pnl"
|
2022-05-17 10:10:37 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/bbgo"
|
2022-05-06 11:16:15 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
2022-05-17 10:10:37 +00:00
|
|
|
type Run struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Config *bbgo.Config `json:"config"`
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReportIndex struct {
|
|
|
|
Runs []Run `json:"runs,omitempty"`
|
|
|
|
}
|
|
|
|
|
2022-05-10 10:27:23 +00:00
|
|
|
// SummaryReport is the summary of the back-test session
|
|
|
|
type SummaryReport struct {
|
|
|
|
StartTime time.Time `json:"startTime"`
|
|
|
|
EndTime time.Time `json:"endTime"`
|
|
|
|
Sessions []string `json:"sessions"`
|
2022-05-17 10:10:37 +00:00
|
|
|
Symbols []string `json:"symbols"`
|
2022-05-10 10:27:23 +00:00
|
|
|
InitialTotalBalances types.BalanceMap `json:"initialTotalBalances"`
|
|
|
|
FinalTotalBalances types.BalanceMap `json:"finalTotalBalances"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionSymbolReport is the report per exchange session
|
|
|
|
// trades are merged, collected and re-calculated
|
|
|
|
type SessionSymbolReport struct {
|
2022-05-09 17:06:16 +00:00
|
|
|
StartTime time.Time `json:"startTime"`
|
|
|
|
EndTime time.Time `json:"endTime"`
|
2022-05-06 11:16:15 +00:00
|
|
|
Symbol string `json:"symbol,omitempty"`
|
|
|
|
LastPrice fixedpoint.Value `json:"lastPrice,omitempty"`
|
|
|
|
StartPrice fixedpoint.Value `json:"startPrice,omitempty"`
|
|
|
|
PnLReport *pnl.AverageCostPnlReport `json:"pnlReport,omitempty"`
|
|
|
|
InitialBalances types.BalanceMap `json:"initialBalances,omitempty"`
|
|
|
|
FinalBalances types.BalanceMap `json:"finalBalances,omitempty"`
|
2022-05-10 06:05:44 +00:00
|
|
|
Manifests Manifests `json:"manifests,omitempty"`
|
2022-05-06 11:16:15 +00:00
|
|
|
}
|
2022-05-09 10:03:03 +00:00
|
|
|
|
2022-05-09 11:27:02 +00:00
|
|
|
const SessionTimeFormat = "2006-01-02T15_04"
|
|
|
|
|
|
|
|
// FormatSessionName returns the back-test session name
|
|
|
|
func FormatSessionName(sessions []string, symbols []string, startTime, endTime time.Time) string {
|
|
|
|
return fmt.Sprintf("%s_%s_%s-%s",
|
|
|
|
strings.Join(sessions, "-"),
|
|
|
|
strings.Join(symbols, "-"),
|
|
|
|
startTime.Format(SessionTimeFormat),
|
|
|
|
endTime.Format(SessionTimeFormat),
|
|
|
|
)
|
|
|
|
}
|