Skip to content

Commit

Permalink
feature: add multiple exchange support in backtest
Browse files Browse the repository at this point in the history
fix: change doc, since --exchange removed from backtest

fix: test for config changes
  • Loading branch information
zenixls2 committed Mar 7, 2022
1 parent d01fcb3 commit 25b5edd
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 184 deletions.
11 changes: 6 additions & 5 deletions config/bollgrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ backtest:
symbols:
- BTCUSDT
account:
makerCommission: 15
takerCommission: 15
balances:
BTC: 0.0
USDT: 10000.0
max:
makerCommission: 15
takerCommission: 15
balances:
BTC: 0.0
USDT: 10000.0

exchangeStrategies:
- on: max
Expand Down
14 changes: 10 additions & 4 deletions config/bollmaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ persistence:
port: 6379
db: 0

sessions:
binance:
exchange: binance
envVarPrefix: BINANCE

# example command:
# godotenv -f .env.local -- go run ./cmd/bbgo backtest --exchange max --sync-from 2020-11-01 --config config/grid.yaml --base-asset-baseline
# godotenv -f .env.local -- go run ./cmd/bbgo backtest --sync-from 2020-11-01 --config config/grid.yaml --base-asset-baseline
backtest:
# for testing max draw down (MDD) at 03-12
# see here for more details
Expand All @@ -16,9 +21,10 @@ backtest:
symbols:
- ETHUSDT
account:
balances:
ETH: 1.0
USDT: 20_000.0
binance:
balances:
ETH: 1.0
USDT: 20_000.0

exchangeStrategies:

Expand Down
13 changes: 7 additions & 6 deletions config/grid-usdttwd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ backtest:
symbols:
- USDTTWD
account:
makerCommission: 15
takerCommission: 15
balances:
BTC: 0.0
USDT: 10_000.0
TWD: 100_000.0
max:
makerCommission: 15
takerCommission: 15
balances:
BTC: 0.0
USDT: 10_000.0
TWD: 100_000.0

exchangeStrategies:
- on: max
Expand Down
23 changes: 12 additions & 11 deletions config/grid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ sessions:
exchange: binance
envVarPrefix: binance

max:
exchange: max
envVarPrefix: max
#max:
# exchange: max
# envVarPrefix: max

riskControls:
# This is the session-based risk controller, which let you configure different risk controller by session.
Expand All @@ -26,23 +26,24 @@ riskControls:
maxOrderAmount: 1000.0

# example command:
# godotenv -f .env.local -- go run ./cmd/bbgo backtest --exchange max --sync-from 2020-11-01 --config config/grid.yaml --base-asset-baseline
# godotenv -f .env.local -- go run ./cmd/bbgo backtest --sync-from 2020-11-01 --config config/grid.yaml --base-asset-baseline
backtest:
# for testing max draw down (MDD) at 03-12
# see here for more details
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
startTime: "2021-01-10"
endTime: "2021-01-21"
startTime: "2022-01-10"
endTime: "2022-01-11"
symbols:
- BTCUSDT
- BTCUSDT
account:
balances:
BTC: 0.0
USDT: 10000.0
binance:
balances:
BTC: 0.0
USDT: 10000.0

exchangeStrategies:

- on: max
- on: binance
grid:
symbol: BTCUSDT
quantity: 0.001
Expand Down
19 changes: 10 additions & 9 deletions config/pricedrop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ backtest:
# for testing max draw down (MDD) at 03-12
# see here for more details
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
startTime: "2020-01-01"
endTime: "2020-01-15"
startTime: "2022-01-01"
endTime: "2022-01-15"
symbols:
- BTCUSDT
account:
makerCommission: 15
takerCommission: 15
buyerCommission: 0
sellerCommission: 0
balances:
BTC: 0.1
USDT: 10000.0
binance:
makerCommission: 15
takerCommission: 15
buyerCommission: 0
sellerCommission: 0
balances:
BTC: 0.1
USDT: 10000.0

exchangeStrategies:
- on: binance
Expand Down
15 changes: 11 additions & 4 deletions config/schedule-ethusdt.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
---
# time godotenv -f .env.local -- go run ./cmd/bbgo backtest --exchange binance --base-asset-baseline --config config/schedule-ethusdt.yaml -v

sessions:
binance:
exchange: binance
envVarPrefix: binance

# time godotenv -f .env.local -- go run ./cmd/bbgo backtest --base-asset-baseline --config config/schedule-ethusdt.yaml -v
backtest:
startTime: "2021-08-01"
endTime: "2021-08-07"
symbols:
- ETHUSDT
account:
balances:
ETH: 1.0
USDT: 20_000.0
binance:
balances:
ETH: 1.0
USDT: 20_000.0

riskControls:
# This is the session-based risk controller, which let you configure different risk controller by session.
Expand Down
7 changes: 4 additions & 3 deletions config/skeleton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ backtest:
symbols:
- BNBBUSD
account:
balances:
BNB: 0
BUSD: 10000
binance:
balances:
BNB: 0
BUSD: 10000
18 changes: 9 additions & 9 deletions config/support-margin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ backtest:
startTime: "2020-09-04"
endTime: "2020-09-14"
symbols:
- BTCUSDT
- ETHUSDT
- LINKUSDT
account:
makerCommission: 15
takerCommission: 15
balances:
BTC: 0.0
USDT: 10000.0
binance:
makerCommission: 15
takerCommission: 15
balances:
LINK: 0.0
USDT: 10000.0

exchangeStrategies:

- on: binance_margin_linkusdt
support:
symbol: LINKUSDT
interval: 1m
minVolume: 1_000
minVolume: 2_000
marginOrderSideEffect: borrow

scaleQuantity:
byVolume:
exp:
domain: [ 1_000, 200_000 ]
range: [ 0.5, 1.0 ]
range: [ 3.0, 5.0 ]

maxBaseAssetBalance: 1000.0
minQuoteAssetBalance: 2000.0
Expand Down
7 changes: 4 additions & 3 deletions config/support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ backtest:
- BTCUSDT
- ETHUSDT
account:
balances:
BTC: 0.0
USDT: 10000.0
binance:
balances:
BTC: 0.0
USDT: 10000.0

exchangeStrategies:

Expand Down
2 changes: 1 addition & 1 deletion doc/commands/bbgo.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bbgo [flags]
* [bbgo orderupdate](bbgo_orderupdate.md) - Listen to order update events
* [bbgo pnl](bbgo_pnl.md) - pnl calculator
* [bbgo run](bbgo_run.md) - run strategies from config file
* [bbgo submit-order](bbgo_submit-order.md) - place limit order to the exchange
* [bbgo submit-order](bbgo_submit-order.md) - place order to the exchange
* [bbgo sync](bbgo_sync.md) - sync trades and orders history
* [bbgo trades](bbgo_trades.md) - Query trading history
* [bbgo tradeupdate](bbgo_tradeupdate.md) - Listen to trade update events
Expand Down
2 changes: 1 addition & 1 deletion doc/commands/bbgo_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
show user account details (ex: balance)

```
bbgo account [--session=[exchange_name]] [flags]
bbgo account [--session SESSION] [flags]
```

### Options
Expand Down
1 change: 0 additions & 1 deletion doc/commands/bbgo_backtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ bbgo backtest [flags]

```
--base-asset-baseline use base asset performance as the competitive baseline performance
--exchange string target exchange
--force force execution without confirm
-h, --help help for backtest
--output string the report output directory
Expand Down
2 changes: 1 addition & 1 deletion doc/commands/bbgo_balances.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Show user account balances

```
bbgo balances --session SESSION [flags]
bbgo balances [--session SESSION] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion doc/commands/bbgo_submit-order.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## bbgo submit-order

place limit order to the exchange
place order to the exchange

```
bbgo submit-order --session SESSION --symbol SYMBOL --side SIDE --quantity QUANTITY [--price PRICE] [flags]
Expand Down
13 changes: 7 additions & 6 deletions doc/topics/back-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ backtest:

account:
# the initial account balance you want to start with
balances:
BTC: 0.0
USDT: 10000.0
binance: # exchange name
balances:
BTC: 0.0
USDT: 10000.0
```
Note on date formats, the following date formats are supported:
Expand All @@ -33,7 +34,7 @@ Note on date formats, the following date formats are supported:
And then, you can sync remote exchange k-lines (candle bars) data for back-testing:

```sh
bbgo backtest --exchange binance -v --sync --sync-only --sync-from 2020-11-01 --config config/grid.yaml
bbgo backtest -v --sync --sync-only --sync-from 2020-11-01 --config config/grid.yaml
```

Note that, you should sync from an earlier date before your startTime because some indicator like EMA needs more data to calculate the current EMA value.
Expand All @@ -48,13 +49,13 @@ Here we sync one month before `2021-01-10`.
Run back-test:

```sh
bbgo backtest --exchange binance --base-asset-baseline --config config/grid.yaml
bbgo backtest --base-asset-baseline --config config/grid.yaml
```

If you're developing a strategy, you might want to start with a command like this:

```shell
godotenv -f .env.local -- go run ./cmd/bbgo backtest --exchange binance --config config/grid.yaml --base-asset-baseline
godotenv -f .env.local -- go run ./cmd/bbgo backtest --config config/grid.yaml --base-asset-baseline
```

## See Also
Expand Down
Loading

0 comments on commit 25b5edd

Please sign in to comment.