From 813724bd824744f7c33022f927bd346054cb0702 Mon Sep 17 00:00:00 2001 From: froggleston Date: Mon, 16 Jan 2023 13:28:40 +0000 Subject: [PATCH] Add a new analysis group to output stats grouped by exit_tag --- docs/advanced-backtesting.md | 3 ++- freqtrade/commands/cli_options.py | 5 +++-- freqtrade/data/entryexitanalysis.py | 6 ++++++ tests/data/test_entryexitanalysis.py | 9 +++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/advanced-backtesting.md b/docs/advanced-backtesting.md index ae3eb2e4e..be9099df8 100644 --- a/docs/advanced-backtesting.md +++ b/docs/advanced-backtesting.md @@ -32,7 +32,7 @@ To analyze the entry/exit tags, we now need to use the `freqtrade backtesting-an with `--analysis-groups` option provided with space-separated arguments (default `0 1 2`): ``` bash -freqtrade backtesting-analysis -c --analysis-groups 0 1 2 3 4 +freqtrade backtesting-analysis -c --analysis-groups 0 1 2 3 4 5 ``` This command will read from the last backtesting results. The `--analysis-groups` option is @@ -43,6 +43,7 @@ ranging from the simplest (0) to the most detailed per pair, per buy and per sel * 2: profit summaries grouped by enter_tag and exit_tag * 3: profit summaries grouped by pair and enter_tag * 4: profit summaries grouped by pair, enter_ and exit_tag (this can get quite large) +* 5: profit summaries grouped by exit_tag More options are available by running with the `-h` option. diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 91ac16365..50fdb1aa2 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -632,10 +632,11 @@ AVAILABLE_CLI_OPTIONS = { "1: by enter_tag, " "2: by enter_tag and exit_tag, " "3: by pair and enter_tag, " - "4: by pair, enter_ and exit_tag (this can get quite large)"), + "4: by pair, enter_ and exit_tag (this can get quite large), " + "5: by exit_tag"), nargs='+', default=['0', '1', '2'], - choices=['0', '1', '2', '3', '4'], + choices=['0', '1', '2', '3', '4', '5'], ), "enter_reason_list": Arg( "--enter-reason-list", diff --git a/freqtrade/data/entryexitanalysis.py b/freqtrade/data/entryexitanalysis.py index baa1cca3a..b2679bcea 100755 --- a/freqtrade/data/entryexitanalysis.py +++ b/freqtrade/data/entryexitanalysis.py @@ -141,6 +141,12 @@ def _do_group_table_output(bigdf, glist): # 4: profit summaries grouped by pair, enter_ and exit_tag (this can get quite large) if g == "4": group_mask = ['pair', 'enter_reason', 'exit_reason'] + + # 5: profit summaries grouped by exit_tag + if g == "5": + group_mask = ['exit_reason'] + sortcols = ['exit_reason'] + if group_mask: new = bigdf.groupby(group_mask).agg(agg_mask).reset_index() new.columns = group_mask + agg_cols diff --git a/tests/data/test_entryexitanalysis.py b/tests/data/test_entryexitanalysis.py index e33ed4955..3b073bc32 100755 --- a/tests/data/test_entryexitanalysis.py +++ b/tests/data/test_entryexitanalysis.py @@ -190,6 +190,15 @@ def test_backtest_analysis_nomock(default_conf, mocker, caplog, testdatadir, tmp assert '1' in captured.out assert '2.5' in captured.out + # test group 5 + args = get_args(base_args + ['--analysis-groups', "5"]) + start_analysis_entries_exits(args) + captured = capsys.readouterr() + assert 'exit_signal' in captured.out + assert 'roi' in captured.out + assert 'stop_loss' in captured.out + assert 'trailing_stop_loss' in captured.out + # test date filtering args = get_args(base_args + ['--timerange', "20180129-20180130"]) start_analysis_entries_exits(args)