mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
add base-asset-baseline flag for backtest
This commit is contained in:
parent
04f6da3cb8
commit
097b2d30a6
|
@ -20,6 +20,7 @@ import (
|
|||
func init() {
|
||||
BacktestCmd.Flags().String("exchange", "", "target exchange")
|
||||
BacktestCmd.Flags().Bool("sync", false, "sync backtest data")
|
||||
BacktestCmd.Flags().Bool("base-asset-baseline", false, "use base asset performance as the competitive baseline performance")
|
||||
BacktestCmd.Flags().CountP("verbose", "v", "verbose level")
|
||||
BacktestCmd.Flags().String("config", "config/bbgo.yaml", "strategy config file")
|
||||
RootCmd.AddCommand(BacktestCmd)
|
||||
|
@ -44,6 +45,11 @@ var BacktestCmd = &cobra.Command{
|
|||
return errors.New("--config option is required")
|
||||
}
|
||||
|
||||
wantBaseAssetBaseline, err := cmd.Flags().GetBool("base-asset-baseline")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wantSync, err := cmd.Flags().GetBool("sync")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -183,13 +189,15 @@ var BacktestCmd = &cobra.Command{
|
|||
log.Infof("FINAL BALANCES:")
|
||||
finalBalances.Print()
|
||||
|
||||
initBaseAsset := InBaseAsset(initBalances, market, startPrice)
|
||||
finalBaseAsset := InBaseAsset(finalBalances, market, lastPrice)
|
||||
log.Infof("INITIAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(initBaseAsset), market.BaseCurrency, market.BaseCurrency, startPrice)
|
||||
log.Infof("FINAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(finalBaseAsset), market.BaseCurrency, market.BaseCurrency, lastPrice)
|
||||
if wantBaseAssetBaseline {
|
||||
initBaseAsset := InBaseAsset(initBalances, market, startPrice)
|
||||
finalBaseAsset := InBaseAsset(finalBalances, market, lastPrice)
|
||||
log.Infof("INITIAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(initBaseAsset), market.BaseCurrency, market.BaseCurrency, startPrice)
|
||||
log.Infof("FINAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(finalBaseAsset), market.BaseCurrency, market.BaseCurrency, lastPrice)
|
||||
|
||||
log.Infof("%s BASE ASSET PERFORMANCE: %.2f%% (= (%.2f - %.2f) / %.2f)", symbol, (finalBaseAsset-initBaseAsset)/initBaseAsset*100.0, finalBaseAsset, initBaseAsset, initBaseAsset)
|
||||
log.Infof("%s PERFORMANCE: %.2f%% (= (%.2f - %.2f) / %.2f)", symbol, (lastPrice-startPrice)/startPrice*100.0, lastPrice, startPrice, startPrice)
|
||||
log.Infof("%s BASE ASSET PERFORMANCE: %.2f%% (= (%.2f - %.2f) / %.2f)", symbol, (finalBaseAsset-initBaseAsset)/initBaseAsset*100.0, finalBaseAsset, initBaseAsset, initBaseAsset)
|
||||
log.Infof("%s PERFORMANCE: %.2f%% (= (%.2f - %.2f) / %.2f)", symbol, (lastPrice-startPrice)/startPrice*100.0, lastPrice, startPrice, startPrice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user