Add best / worst day to statistics

This commit is contained in:
Matthias 2020-07-03 19:30:29 +02:00
parent 804c42933d
commit 42868ad24a
2 changed files with 15 additions and 4 deletions

View File

@ -233,6 +233,8 @@ It contains some useful key metrics about your strategy.
| Backtesting from | 2019-01-01 00:00:00 |
| Backtesting to | 2019-05-01 00:00:00 |
| Trades per day | 3.575 |
| Best day | 25.27% |
| Worst day | -30.67% |
| | |
| Max Drawdown | 50.63% |
| Drawdown Start | 2019-02-15 14:10:00 |
@ -244,11 +246,12 @@ It contains some useful key metrics about your strategy.
- `Total trades`: Identical to the total trades of the backtest output table.
- `First trade`: First trade entered.
- `First trade pair`: Which pair was part of the first trade
- `Backtesting from` / `Backtesting to`: Backtesting range (usually defined as `--timerange from-to`)
- `Trades per day`: Total trades / Backtest duration (this will give you information about how many trades to expect from the strategy)
- `First trade pair`: Which pair was part of the first trade.
- `Backtesting from` / `Backtesting to`: Backtesting range (usually defined as `--timerange from-to`).
- `Trades per day`: Total trades / Backtest duration (this will give you information about how many trades to expect from the strategy).
- `Best day` / `Worst day`: Best and worst day based on daily profit.
- `Max Drawdown`: Maximum drawown experienced. a value of 50% means that from highest to subsequent lowest point, a 50% drop was experiened).
- `Drawdown Start` / `Drawdown End`: From when to when was this large drawdown (can also be visualized via `plot-dataframe` subcommand)
- `Drawdown Start` / `Drawdown End`: From when to when was this large drawdown (can also be visualized via `plot-dataframe` subcommand).
- `Market change`: Change of the market during the backtest period. Calculated as average of all pairs changes from the first to the last candle using the "close" column.
### Assumptions made by backtesting

View File

@ -239,6 +239,9 @@ def generate_backtest_stats(config: Dict, btdata: Dict[str, DataFrame],
max_open_trades=max_open_trades,
results=results.loc[results['open_at_end']],
skip_nan=True)
daily_profit = results.resample('1d', on='close_date')['profit_percent'].sum()
worst = min(daily_profit)
best = max(daily_profit)
backtest_days = (max_date - min_date).days
strat_stats = {
@ -252,6 +255,9 @@ def generate_backtest_stats(config: Dict, btdata: Dict[str, DataFrame],
'backtest_end': max_date.datetime,
'backtest_end_ts': max_date.timestamp,
'backtest_days': backtest_days,
'backtest_best_day': best,
'backtest_worst_day': worst,
'trades_per_day': round(len(results) / backtest_days, 2) if backtest_days > 0 else None,
'market_change': market_change,
'pairlist': list(btdata.keys()),
@ -366,6 +372,8 @@ def text_table_add_metrics(strat_results: Dict) -> str:
('Backtesting from', strat_results['backtest_start'].strftime(DATETIME_PRINT_FORMAT)),
('Backtesting to', strat_results['backtest_end'].strftime(DATETIME_PRINT_FORMAT)),
('Trades per day', strat_results['trades_per_day']),
('Best day', f"{round(strat_results['backtest_best_day'] * 100, 2)}%"),
('Worst day', f"{round(strat_results['backtest_worst_day'] * 100, 2)}%"),
('', ''), # Empty line to improve readability
('Max Drawdown', f"{round(strat_results['max_drawdown'] * 100, 2)}%"),
('Drawdown Start', strat_results['drawdown_start'].strftime(DATETIME_PRINT_FORMAT)),