Skip to content

Commit 8b7b2f8

Browse files
committed
Update with new backtest example
1 parent 072c813 commit 8b7b2f8

File tree

3 files changed

+45
-35
lines changed

3 files changed

+45
-35
lines changed

README.md

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,66 @@ For example if you run the [moving average example trading bot](./examples/cross
139139
you will get the following backtesting report:
140140

141141
```bash
142-
====================Backtest report===============================
143-
* Start date: 2023-08-24 00:00:00
144-
* End date: 2023-12-02 00:00:00
145-
* Number of days: 100
146-
* Number of runs: 1201
147-
====================Portfolio overview============================
148-
* Number of orders: 10
149-
* Initial balance: 400.0000 EUR
150-
* Final balance: 431.8837 EUR
151-
* Total net gain: 28.4171 EUR
152-
* Total net gain percentage: 7.1043%
153-
* Growth rate: 7.9709%
154-
* Growth 31.8837 EUR
155-
====================Positions overview========================
142+
143+
/&# #&( Backtest report
144+
&&&&&&&&&&&# &&&&&&&&&&&& ---------------------------
145+
&&&&&&&&&&&&&&&& (&&&&&&&&&&&&&&& Start date: 2023-08-24 00:00:00
146+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& End date: 2023-12-02 00:00:00
147+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of days: 100
148+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of runs: 1201
149+
.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of orders: 10
150+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&. Initial balance: 400.0
151+
&&&&&&&# /((( &&&&&&&&&&&&*((( .&&&&&&&. Final balance: 431.1499
152+
&&&&&&&&&&&&&&&&&&& (((( &&&&&&&& (((( &&&&&&&&&&&&&&&&&&& Total net gain: 28.5542 7.139%
153+
(((&&&&&&&& (((( &&&&&& (((( &&&&&&&&&(( Growth: 31.1499 7.787%
154+
/((((((((((&&&&&&&&&& (((, &&&&&& (((**&&&&&&&&&((((((((((( Number of trades closed: 4
155+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of trades open(end of backtest): 2
156+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage positive trades: 60.0%
157+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage negative trades: 20.0%
158+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&( Average trade size: 98.9886 EUR
159+
((((( &&&&&&&&&&&&&&&&&&&&&&&&, Average trade duration: 184.0 hours
160+
((((( &&&&&&&&&&&&&#
161+
((((( #&&&&&&&&&&###
162+
((((( &&&&&&&&&&&###.
163+
.((((( &&&&&&&&&&&&&&###(
164+
((((( &&&&&&&&&&&&&&&&#(((/
165+
((((( &&&&&&&&&&&&&&&&&&&@((((
166+
((((( &&&&&&&&&&&&&&&&&&&&&&((((
167+
((((( &&&&&&&&&&&&&&&&&&&&&&&&((((,
168+
.((((( &&&&&&&&&&&&&&&&&&&&&&&&&&((((
169+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
170+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
171+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
172+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&#((((
173+
(((((((((((((((((((#########&&&&&&&&&&&&&&&&&&&&&&&&&&&&(((((
174+
(((((((((((((((((((((######&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
175+
176+
Positions overview
156177
╭────────────┬──────────┬──────────────────────┬───────────────────────┬──────────────┬───────────────┬───────────────────────────┬────────────────┬───────────────╮
157178
│ Position │ Amount │ Pending buy amount │ Pending sell amount │ Cost (EUR) │ Value (EUR) │ Percentage of portfolio │ Growth (EUR) │ Growth_rate │
158179
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
159-
│ EUR │ 214.219 │ 0 │ 0 │ 214.219214.21949.6010% │ 0 │ 0.0000% │
180+
│ EUR │ 217.04400217.044217.04450.3407% │ 00.0000% │
160181
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
161-
│ BTC │ 0.0031 │ 0 │ 0 │ 107.095110.401 │ 25.5627% │ 3.30663.0875% │
182+
│ BTC │ 0.003 00104.372106.8424.7802% │ 2.46782.3644% │
162183
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
163-
│ DOT │ 21.3291 │ 0 │ 0 │ 107.104 │ 107.264 │ 24.8363% │ 0.16 │ 0.1494% │
184+
│ DOT │ 21.329500107.138107.26624.8791% │ 0.128 0.1195% │
164185
╰────────────┴──────────┴──────────────────────┴───────────────────────┴──────────────┴───────────────┴───────────────────────────┴────────────────┴───────────────╯
165-
====================Trades overview===========================
166-
* Number of trades closed: 4
167-
* Number of trades open: 2
168-
* Percentage of positive trades: 60.0%
169-
* Percentage of negative trades: 20.0%
170-
* Average trade size: 98.8728 EUR
171-
* Average trade duration: 183.5 hours
186+
Trades overview
172187
╭─────────┬─────────────────────┬─────────────────────┬────────────────────┬──────────────┬──────────────────┬───────────────────────┬────────────────────┬─────────────────────╮
173188
│ Pair │ Open date │ Close date │ Duration (hours) │ Size (EUR) │ Net gain (EUR) │ Net gain percentage │ Open price (EUR) │ Close price (EUR) │
174189
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
175-
│ DOT-EUR │ 2023-11-30 20:00:00 │ │ 2976.65 │ 107.104 │ 0 │ 0.0000% │ 5.0215 │ │
190+
│ DOT-EUR │ 2023-11-30 18:00:00 │ │ 3207.26107.13800.0000% │ 5.023 │ │
176191
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
177-
│ BTC-EUR │ 2023-11-29 14:00:00 │ │ 3006.65107.095 │ 0 │ 0.0000% │ 34546.6 │ │
192+
│ BTC-EUR │ 2023-11-29 12:00:00 │ │ 3237.26104.37200.0000% │ 34790.7 │ │
178193
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
179-
│ BTC-EUR │ 2023-11-08 00:00:00 │ 2023-11-14 16:00:00 │ 160 │ 99.22651.33521.3456% │ 33075.533520.6
194+
│ BTC-EUR │ 2023-11-07 22:00:002023-11-14 14:00:0016099.23372.53952.5591% │ 33077.933924.4
180195
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
181-
│ BTC-EUR │ 2023-11-06 16:00:00 │ 2023-11-06 20:00:00 │ 4 │ 97.8607 │ -0.0026 │ -0.0026% │ 32620.232619.4
196+
│ BTC-EUR │ 2023-11-06 14:00:002023-11-06 18:00:00498.2854 │ -0.4248 │ -0.4322% │ 32761.832620.2
182197
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
183-
│ DOT-EUR │ 2023-10-30 06:00:00 │ 2023-11-14 00:00:00 │ 354 │ 100.551 │ 24.8794 │ 24.7430% │ 4.0375 │ 5.0365 │
198+
│ DOT-EUR │ 2023-10-30 04:00:002023-11-14 00:00:00356100.53724.288624.1588% │ 4.05655.0365
184199
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
185-
│ BTC-EUR │ 2023-09-13 16:00:00 │ 2023-09-22 16:00:00 │ 216 │ 97.8529 │ 2.2051 │ 2.2534% │ 24463.225014.5
200+
│ BTC-EUR │ 2023-09-13 14:00:002023-09-22 14:00:0021697.89762.15082.1970% │ 24474.425012.1
186201
╰─────────┴─────────────────────┴─────────────────────┴────────────────────┴──────────────┴──────────────────┴───────────────────────┴────────────────────┴─────────────────────╯
187-
==================================================================
188202
```
189203
190204
### Backtest experiments

examples/backtest/algorithm/strategy.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def apply_strategy(self, algorithm: Algorithm, market_data):
7676
if not algorithm.has_position(target_symbol) \
7777
and is_crossover(fast, slow) \
7878
and is_above_trend(fast, trend):
79-
print(f"opening trade on {algorithm.config['BACKTESTING_INDEX_DATETIME']} with price {price}")
80-
8179
algorithm.create_limit_order(
8280
target_symbol=target_symbol,
8381
order_side=OrderSide.BUY,
@@ -88,7 +86,6 @@ def apply_strategy(self, algorithm: Algorithm, market_data):
8886

8987
if algorithm.has_position(target_symbol) \
9088
and is_below_trend(fast, slow):
91-
print(f"closing trade on {algorithm.config['BACKTESTING_INDEX_DATETIME']} with price {price}")
9289
open_trades = algorithm.get_open_trades(
9390
target_symbol=target_symbol
9491
)
@@ -105,5 +102,4 @@ def apply_strategy(self, algorithm: Algorithm, market_data):
105102
current_price=market_data[f"{symbol}-ticker"]["bid"],
106103
stop_loss_percentage=self.stop_loss_percentage
107104
):
108-
print(f"stop los triggered on {algorithm.config['BACKTESTING_INDEX_DATETIME']} with price {price} ")
109105
algorithm.close_trade(open_trade)
File renamed without changes.

0 commit comments

Comments
 (0)