mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1384 from c9s/c9s/backtest-minor-improvements
CHORE: minor improvements on backtest cmd
This commit is contained in:
commit
a8ddf9a8d5
|
@ -382,6 +382,14 @@ func (e *Exchange) SubscribeMarketData(
|
|||
}
|
||||
|
||||
log.Infof("querying klines from database with exchange: %v symbols: %v and intervals: %v for back-testing", e.Name(), symbols, intervals)
|
||||
if len(symbols) == 0 {
|
||||
log.Warnf("empty symbols, will not query kline data from the database")
|
||||
|
||||
c := make(chan types.KLine)
|
||||
close(c)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
klineC, errC := e.srv.QueryKLinesCh(startTime, endTime, e, symbols, intervals)
|
||||
go func() {
|
||||
if err := <-errC; err != nil {
|
||||
|
|
|
@ -528,6 +528,11 @@ var BacktestCmd = &cobra.Command{
|
|||
|
||||
for _, session := range environ.Sessions() {
|
||||
for symbol, trades := range session.Trades {
|
||||
if len(trades.Trades) == 0 {
|
||||
log.Warnf("session has no %s trades", symbol)
|
||||
continue
|
||||
}
|
||||
|
||||
tradeState := sessionTradeStats[session.Name][symbol]
|
||||
profitFactor := tradeState.ProfitFactor
|
||||
winningRatio := tradeState.WinningRatio
|
||||
|
@ -598,8 +603,11 @@ var BacktestCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
func createSymbolReport(userConfig *bbgo.Config, session *bbgo.ExchangeSession, symbol string, trades []types.Trade, intervalProfit *types.IntervalProfitCollector,
|
||||
profitFactor, winningRatio fixedpoint.Value) (
|
||||
func createSymbolReport(
|
||||
userConfig *bbgo.Config, session *bbgo.ExchangeSession, symbol string, trades []types.Trade,
|
||||
intervalProfit *types.IntervalProfitCollector,
|
||||
profitFactor, winningRatio fixedpoint.Value,
|
||||
) (
|
||||
*backtest.SessionSymbolReport,
|
||||
error,
|
||||
) {
|
||||
|
@ -669,7 +677,10 @@ func createSymbolReport(userConfig *bbgo.Config, session *bbgo.ExchangeSession,
|
|||
return &symbolReport, nil
|
||||
}
|
||||
|
||||
func verify(userConfig *bbgo.Config, backtestService *service.BacktestService, sourceExchanges map[types.ExchangeName]types.Exchange, startTime, endTime time.Time) error {
|
||||
func verify(
|
||||
userConfig *bbgo.Config, backtestService *service.BacktestService,
|
||||
sourceExchanges map[types.ExchangeName]types.Exchange, startTime, endTime time.Time,
|
||||
) error {
|
||||
for _, sourceExchange := range sourceExchanges {
|
||||
err := backtestService.Verify(sourceExchange, userConfig.Backtest.Symbols, startTime, endTime)
|
||||
if err != nil {
|
||||
|
@ -709,7 +720,10 @@ func getExchangeIntervals(ex types.Exchange) types.IntervalMap {
|
|||
return types.SupportedIntervals
|
||||
}
|
||||
|
||||
func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service.BacktestService, sourceExchanges map[types.ExchangeName]types.Exchange, syncFrom, syncTo time.Time) error {
|
||||
func sync(
|
||||
ctx context.Context, userConfig *bbgo.Config, backtestService *service.BacktestService,
|
||||
sourceExchanges map[types.ExchangeName]types.Exchange, syncFrom, syncTo time.Time,
|
||||
) error {
|
||||
for _, symbol := range userConfig.Backtest.Symbols {
|
||||
for _, sourceExchange := range sourceExchanges {
|
||||
var supportIntervals = getExchangeIntervals(sourceExchange)
|
||||
|
|
Loading…
Reference in New Issue
Block a user