From 42868ad24ac8812ec295867fd5f9728aaad9635a Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 3 Jul 2020 19:30:29 +0200 Subject: [PATCH] Add best / worst day to statistics --- docs/backtesting.md | 11 +++++++---- freqtrade/optimize/optimize_reports.py | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/backtesting.md b/docs/backtesting.md index 52506215d..6c01e1c62 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -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 diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index d0e29d98f..4f169c53a 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -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)),