From 1976aaf13e366da4c9b6008fc3f5ddd169bb6d1c Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Sun, 22 Mar 2020 02:22:06 +0100 Subject: [PATCH 01/10] initial push --- docs/utils.md | 10 +++++--- freqtrade/commands/arguments.py | 1 + freqtrade/commands/cli_options.py | 12 +++++++++ freqtrade/commands/hyperopt_commands.py | 32 ++++++++++++++++++++++-- freqtrade/configuration/configuration.py | 6 +++++ tests/commands/test_commands.py | 28 +++++++++++++++++++++ 6 files changed, 84 insertions(+), 5 deletions(-) diff --git a/docs/utils.md b/docs/utils.md index 269b9affd..03924c581 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -426,9 +426,9 @@ usage: freqtrade hyperopt-list [-h] [-v] [--logfile FILE] [-V] [-c PATH] [--max-trades INT] [--min-avg-time FLOAT] [--max-avg-time FLOAT] [--min-avg-profit FLOAT] [--max-avg-profit FLOAT] - [--min-total-profit FLOAT] - [--max-total-profit FLOAT] [--no-color] - [--print-json] [--no-details] + [--min-total-profit FLOAT] [--max-total-profit FLOAT] + [--min-objective FLOAT] [--max-objective FLOAT] + [--no-color] [--print-json] [--no-details] [--export-csv FILE] optional arguments: @@ -447,6 +447,10 @@ optional arguments: Select epochs on above total profit. --max-total-profit FLOAT Select epochs on below total profit. + --min-objective FLOAT + Select epochs on above objective (- is added by default). + --max-objective FLOAT + Select epochs on below objective (- is added by default). --no-color Disable colorization of hyperopt results. May be useful if you are redirecting output to a file. --print-json Print best result detailization in JSON format. diff --git a/freqtrade/commands/arguments.py b/freqtrade/commands/arguments.py index 8c64c5857..9edd143a6 100644 --- a/freqtrade/commands/arguments.py +++ b/freqtrade/commands/arguments.py @@ -69,6 +69,7 @@ ARGS_HYPEROPT_LIST = ["hyperopt_list_best", "hyperopt_list_profitable", "hyperopt_list_min_avg_time", "hyperopt_list_max_avg_time", "hyperopt_list_min_avg_profit", "hyperopt_list_max_avg_profit", "hyperopt_list_min_total_profit", "hyperopt_list_max_total_profit", + "hyperopt_list_min_objective", "hyperopt_list_max_objective", "print_colorized", "print_json", "hyperopt_list_no_details", "export_csv"] diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 5cf1b7fce..1402e64ef 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -484,6 +484,18 @@ AVAILABLE_CLI_OPTIONS = { type=float, metavar='FLOAT', ), + "hyperopt_list_min_objective": Arg( + '--min-objective', + help='Select epochs on above objective.', + type=float, + metavar='FLOAT', + ), + "hyperopt_list_max_objective": Arg( + '--max-objective', + help='Select epochs on below objective.', + type=float, + metavar='FLOAT', + ), "hyperopt_list_no_details": Arg( '--no-details', help='Do not print best epoch details.', diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index 5b2388252..dd9de19e7 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -35,9 +35,16 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None: 'filter_min_avg_profit': config.get('hyperopt_list_min_avg_profit', None), 'filter_max_avg_profit': config.get('hyperopt_list_max_avg_profit', None), 'filter_min_total_profit': config.get('hyperopt_list_min_total_profit', None), - 'filter_max_total_profit': config.get('hyperopt_list_max_total_profit', None) + 'filter_max_total_profit': config.get('hyperopt_list_max_total_profit', None), + 'filter_min_objective': config.get('hyperopt_list_min_objective', None), + 'filter_max_objective': config.get('hyperopt_list_max_objective', None) } + if filteroptions['filter_min_objective'] is not None: + filteroptions['filter_min_objective'] = -filteroptions['filter_min_objective'] + if filteroptions['filter_max_objective'] is not None: + filteroptions['filter_max_objective'] = -filteroptions['filter_max_objective'] + trials_file = (config['user_data_dir'] / 'hyperopt_results' / 'hyperopt_results.pickle') @@ -92,9 +99,16 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: 'filter_min_avg_profit': config.get('hyperopt_list_min_avg_profit', None), 'filter_max_avg_profit': config.get('hyperopt_list_max_avg_profit', None), 'filter_min_total_profit': config.get('hyperopt_list_min_total_profit', None), - 'filter_max_total_profit': config.get('hyperopt_list_max_total_profit', None) + 'filter_max_total_profit': config.get('hyperopt_list_max_total_profit', None), + 'filter_min_objective': config.get('hyperopt_list_min_objective', None), + 'filter_max_objective': config.get('hyperopt_list_max_objective', None) } + if filteroptions['filter_min_objective'] is not None: + filteroptions['filter_min_objective'] = -filteroptions['filter_min_objective'] + if filteroptions['filter_max_objective'] is not None: + filteroptions['filter_max_objective'] = -filteroptions['filter_max_objective'] + # Previous evaluations trials = Hyperopt.load_previous_results(trials_file) total_epochs = len(trials) @@ -175,6 +189,20 @@ def _hyperopt_filter_trials(trials: List, filteroptions: dict) -> List: x for x in trials if x['results_metrics']['profit'] < filteroptions['filter_max_total_profit'] ] + if filteroptions['filter_min_objective'] is not None: + trials = [x for x in trials if x['results_metrics']['trade_count'] > 0] + # trials = [x for x in trials if x['loss'] != 20] + trials = [ + x for x in trials + if x['loss'] < filteroptions['filter_min_objective'] + ] + if filteroptions['filter_max_objective'] is not None: + trials = [x for x in trials if x['results_metrics']['trade_count'] > 0] + # trials = [x for x in trials if x['loss'] != 20] + trials = [ + x for x in trials + if x['loss'] > filteroptions['filter_max_objective'] + ] logger.info(f"{len(trials)} " + ("best " if filteroptions['only_best'] else "") + diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index e5515670d..c26610336 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -334,6 +334,12 @@ class Configuration: self._args_to_config(config, argname='hyperopt_list_max_total_profit', logstring='Parameter --max-total-profit detected: {}') + self._args_to_config(config, argname='hyperopt_list_min_objective', + logstring='Parameter --min-objective detected: {}') + + self._args_to_config(config, argname='hyperopt_list_max_objective', + logstring='Parameter --max-objective detected: {}') + self._args_to_config(config, argname='hyperopt_list_no_details', logstring='Parameter --no-details detected: {}') diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 4530cd03d..2825a4679 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -868,6 +868,34 @@ def test_hyperopt_list(mocker, capsys, hyperopt_results): pargs['config'] = None start_hyperopt_list(pargs) captured = capsys.readouterr() + assert all(x in captured.out + for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", + " 9/12", " 11/12"]) + assert all(x not in captured.out + for x in [" 4/12", " 10/12", " 12/12"]) + args = [ + "hyperopt-list", + "--no-details", + "--min-objective", "0.1" + ] + pargs = get_args(args) + pargs['config'] = None + start_hyperopt_list(pargs) + captured = capsys.readouterr() + assert all(x in captured.out + for x in [" 10/12"]) + assert all(x not in captured.out + for x in [" 1/12", " 2/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12", + " 9/12", " 11/12", " 12/12"]) + args = [ + "hyperopt-list", + "--no-details", + "--max-objective", "0.1" + ] + pargs = get_args(args) + pargs['config'] = None + start_hyperopt_list(pargs) + captured = capsys.readouterr() assert all(x in captured.out for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12", " 11/12"]) From bf96ef08e0b7bf5c9d47a297f386f64d905a90be Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Sun, 22 Mar 2020 09:39:38 +0100 Subject: [PATCH 02/10] added # flake8: noqa C901 --- freqtrade/commands/hyperopt_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index dd9de19e7..c5cf9a969 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -10,7 +10,7 @@ from freqtrade.state import RunMode logger = logging.getLogger(__name__) - +# flake8: noqa C901 def start_hyperopt_list(args: Dict[str, Any]) -> None: """ List hyperopt epochs previously evaluated From 7143cac64f7c9d3ccd5f14d2ae689016157dcee3 Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Mon, 23 Mar 2020 09:41:01 +0100 Subject: [PATCH 03/10] fixed wording of all in cli_options --- freqtrade/commands/cli_options.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 1402e64ef..e1927a901 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -450,49 +450,49 @@ AVAILABLE_CLI_OPTIONS = { ), "hyperopt_list_min_avg_time": Arg( '--min-avg-time', - help='Select epochs on above average time.', + help='Select epochs above average time.', type=float, metavar='FLOAT', ), "hyperopt_list_max_avg_time": Arg( '--max-avg-time', - help='Select epochs on under average time.', + help='Select epochs under average time.', type=float, metavar='FLOAT', ), "hyperopt_list_min_avg_profit": Arg( '--min-avg-profit', - help='Select epochs on above average profit.', + help='Select epochs above average profit.', type=float, metavar='FLOAT', ), "hyperopt_list_max_avg_profit": Arg( '--max-avg-profit', - help='Select epochs on below average profit.', + help='Select epochs below average profit.', type=float, metavar='FLOAT', ), "hyperopt_list_min_total_profit": Arg( '--min-total-profit', - help='Select epochs on above total profit.', + help='Select epochs above total profit.', type=float, metavar='FLOAT', ), "hyperopt_list_max_total_profit": Arg( '--max-total-profit', - help='Select epochs on below total profit.', + help='Select epochs below total profit.', type=float, metavar='FLOAT', ), "hyperopt_list_min_objective": Arg( '--min-objective', - help='Select epochs on above objective.', + help='Select epochs above objective.', type=float, metavar='FLOAT', ), "hyperopt_list_max_objective": Arg( '--max-objective', - help='Select epochs on below objective.', + help='Select epochs below objective.', type=float, metavar='FLOAT', ), From 0a87fe76a363db2056aee42fed2d3dd4902b48fa Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Mon, 23 Mar 2020 11:17:56 +0100 Subject: [PATCH 04/10] unified language --- freqtrade/commands/cli_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index e1927a901..47e7187a8 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -456,7 +456,7 @@ AVAILABLE_CLI_OPTIONS = { ), "hyperopt_list_max_avg_time": Arg( '--max-avg-time', - help='Select epochs under average time.', + help='Select epochs below average time.', type=float, metavar='FLOAT', ), From ef4426a65c08f767314a1a789d3b06c7b9a98072 Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Fri, 27 Mar 2020 03:01:51 +0100 Subject: [PATCH 05/10] added comma --- freqtrade/commands/hyperopt_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index c5cf9a969..33abb7823 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -37,7 +37,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None: 'filter_min_total_profit': config.get('hyperopt_list_min_total_profit', None), 'filter_max_total_profit': config.get('hyperopt_list_max_total_profit', None), 'filter_min_objective': config.get('hyperopt_list_min_objective', None), - 'filter_max_objective': config.get('hyperopt_list_max_objective', None) + 'filter_max_objective': config.get('hyperopt_list_max_objective', None), } if filteroptions['filter_min_objective'] is not None: From 77541935a8d686b0b1feb1ce345261a2c40436e8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Aug 2020 20:10:43 +0200 Subject: [PATCH 06/10] Fix small merge mistake --- freqtrade/commands/hyperopt_commands.py | 16 ++++----- tests/commands/test_commands.py | 44 ++++++++++++++++--------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index 7b079bdfe..b769100be 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -183,17 +183,17 @@ def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: if x['results_metrics']['profit'] < filteroptions['filter_max_total_profit'] ] if filteroptions['filter_min_objective'] is not None: - trials = [x for x in trials if x['results_metrics']['trade_count'] > 0] - # trials = [x for x in trials if x['loss'] != 20] - trials = [ - x for x in trials + epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] + # epochs = [x for x in epochs if x['loss'] != 20] + epochs = [ + x for x in epochs if x['loss'] < filteroptions['filter_min_objective'] ] if filteroptions['filter_max_objective'] is not None: - trials = [x for x in trials if x['results_metrics']['trade_count'] > 0] - # trials = [x for x in trials if x['loss'] != 20] - trials = [ - x for x in trials + epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] + # epochs = [x for x in epochs if x['loss'] != 20] + epochs = [ + x for x in epochs if x['loss'] > filteroptions['filter_max_objective'] ] diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 4ef4ec6c5..1eb017465 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -736,7 +736,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", - "--no-details" + "--no-details", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -749,7 +750,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--best", - "--no-details" + "--no-details", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -763,7 +765,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--profitable", - "--no-details" + "--no-details", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -776,7 +779,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): " 11/12", " 12/12"]) args = [ "hyperopt-list", - "--profitable" + "--profitable", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -792,7 +796,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--no-color", - "--min-trades", "20" + "--min-trades", "20", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -806,7 +811,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--profitable", "--no-details", - "--max-trades", "20" + "--max-trades", "20", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -821,7 +827,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--profitable", "--no-details", - "--min-avg-profit", "0.11" + "--min-avg-profit", "0.11", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -835,7 +842,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--max-avg-profit", "0.10" + "--max-avg-profit", "0.10", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -849,7 +857,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--min-total-profit", "0.4" + "--min-total-profit", "0.4", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -863,7 +872,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--max-total-profit", "0.4" + "--max-total-profit", "0.4", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -877,7 +887,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--min-objective", "0.1" + "--min-objective", "0.1", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -891,7 +902,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--max-objective", "0.1" + "--max-objective", "0.1", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -906,7 +918,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--profitable", "--no-details", - "--min-avg-time", "2000" + "--min-avg-time", "2000", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -920,7 +933,8 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--max-avg-time", "1500" + "--max-avg-time", "1500", + "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -934,7 +948,7 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--export-csv", "test_file.csv" + "--export-csv", "test_file.csv", ] pargs = get_args(args) pargs['config'] = None From f51c03aa864e4489bb55886cf86b3be0bc413216 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Aug 2020 20:29:47 +0200 Subject: [PATCH 07/10] Revert changes to color using --no-color --- tests/commands/test_commands.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 1eb017465..69d80d2cd 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -737,7 +737,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--no-details", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -751,7 +750,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--best", "--no-details", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -766,7 +764,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--profitable", "--no-details", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -780,7 +777,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): args = [ "hyperopt-list", "--profitable", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -797,7 +793,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "--no-details", "--no-color", "--min-trades", "20", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -812,7 +807,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "--profitable", "--no-details", "--max-trades", "20", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -828,7 +822,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "--profitable", "--no-details", "--min-avg-profit", "0.11", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -843,7 +836,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--max-avg-profit", "0.10", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -858,7 +850,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--min-total-profit", "0.4", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -873,7 +864,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--max-total-profit", "0.4", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -888,7 +878,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--min-objective", "0.1", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -903,7 +892,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--max-objective", "0.1", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -919,7 +907,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "--profitable", "--no-details", "--min-avg-time", "2000", - "--no-color", ] pargs = get_args(args) pargs['config'] = None @@ -934,7 +921,6 @@ def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results): "hyperopt-list", "--no-details", "--max-avg-time", "1500", - "--no-color", ] pargs = get_args(args) pargs['config'] = None From 56655b97cfc52116c7f990405dee6d5ebaea2ce7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Aug 2020 20:37:01 +0200 Subject: [PATCH 08/10] Refactor hyperopt_filter method --- freqtrade/commands/hyperopt_commands.py | 38 ++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index b769100be..a724443cf 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -10,7 +10,7 @@ from freqtrade.state import RunMode logger = logging.getLogger(__name__) -# flake8: noqa C901 + def start_hyperopt_list(args: Dict[str, Any]) -> None: """ List hyperopt epochs previously evaluated @@ -47,7 +47,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None: epochs = Hyperopt.load_previous_results(results_file) total_epochs = len(epochs) - epochs = _hyperopt_filter_epochs(epochs, filteroptions) + epochs = hyperopt_filter_epochs(epochs, filteroptions) if print_colorized: colorama_init(autoreset=True) @@ -108,7 +108,7 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: epochs = Hyperopt.load_previous_results(results_file) total_epochs = len(epochs) - epochs = _hyperopt_filter_epochs(epochs, filteroptions) + epochs = hyperopt_filter_epochs(epochs, filteroptions) filtered_epochs = len(epochs) if n > filtered_epochs: @@ -128,7 +128,7 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: header_str="Epoch details") -def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: +def hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: """ Filter our items from the list of hyperopt results """ @@ -136,6 +136,20 @@ def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: epochs = [x for x in epochs if x['is_best']] if filteroptions['only_profitable']: epochs = [x for x in epochs if x['results_metrics']['profit'] > 0] + + epochs = _hyperopt_filter_epochs_trade_count(epochs, filteroptions) + + epochs = _hyperopt_filter_epochs_duration(epochs, filteroptions) + + epochs = _hyperopt_filter_epochs_profit(epochs, filteroptions) + + epochs = _hyperopt_filter_epochs_objective(epochs, filteroptions) + + return epochs + + +def _hyperopt_filter_epochs_trade_count(epochs: List, filteroptions: dict) -> List: + if filteroptions['filter_min_trades'] > 0: epochs = [ x for x in epochs @@ -146,6 +160,11 @@ def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: x for x in epochs if x['results_metrics']['trade_count'] < filteroptions['filter_max_trades'] ] + return epochs + + +def _hyperopt_filter_epochs_duration(epochs: List, filteroptions: dict) -> List: + if filteroptions['filter_min_avg_time'] is not None: epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] epochs = [ @@ -158,6 +177,12 @@ def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: x for x in epochs if x['results_metrics']['duration'] < filteroptions['filter_max_avg_time'] ] + + return epochs + + +def _hyperopt_filter_epochs_profit(epochs: List, filteroptions: dict) -> List: + if filteroptions['filter_min_avg_profit'] is not None: epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] epochs = [ @@ -182,6 +207,11 @@ def _hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: x for x in epochs if x['results_metrics']['profit'] < filteroptions['filter_max_total_profit'] ] + return epochs + + +def _hyperopt_filter_epochs_objective(epochs: List, filteroptions: dict) -> List: + if filteroptions['filter_min_objective'] is not None: epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] # epochs = [x for x in epochs if x['loss'] != 20] From 2dc36bb79eece79fd20c7ffac92fb1c12ba4177e Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Aug 2020 20:52:18 +0200 Subject: [PATCH 09/10] Remove inversion of min/max objective selection --- freqtrade/commands/hyperopt_commands.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index a724443cf..d37c1f13b 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -99,11 +99,6 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: 'filter_max_objective': config.get('hyperopt_list_max_objective', None) } - if filteroptions['filter_min_objective'] is not None: - filteroptions['filter_min_objective'] = -filteroptions['filter_min_objective'] - if filteroptions['filter_max_objective'] is not None: - filteroptions['filter_max_objective'] = -filteroptions['filter_max_objective'] - # Previous evaluations epochs = Hyperopt.load_previous_results(results_file) total_epochs = len(epochs) From 2fed066e767bb3c3015af5d4a9f31ad588619fad Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 12 Aug 2020 10:39:53 +0200 Subject: [PATCH 10/10] Simplify objective code formatting --- freqtrade/commands/hyperopt_commands.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index d37c1f13b..4fae51e28 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -140,6 +140,10 @@ def hyperopt_filter_epochs(epochs: List, filteroptions: dict) -> List: epochs = _hyperopt_filter_epochs_objective(epochs, filteroptions) + logger.info(f"{len(epochs)} " + + ("best " if filteroptions['only_best'] else "") + + ("profitable " if filteroptions['only_profitable'] else "") + + "epochs found.") return epochs @@ -209,22 +213,11 @@ def _hyperopt_filter_epochs_objective(epochs: List, filteroptions: dict) -> List if filteroptions['filter_min_objective'] is not None: epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] - # epochs = [x for x in epochs if x['loss'] != 20] - epochs = [ - x for x in epochs - if x['loss'] < filteroptions['filter_min_objective'] - ] + + epochs = [x for x in epochs if x['loss'] < filteroptions['filter_min_objective']] if filteroptions['filter_max_objective'] is not None: epochs = [x for x in epochs if x['results_metrics']['trade_count'] > 0] - # epochs = [x for x in epochs if x['loss'] != 20] - epochs = [ - x for x in epochs - if x['loss'] > filteroptions['filter_max_objective'] - ] - logger.info(f"{len(epochs)} " + - ("best " if filteroptions['only_best'] else "") + - ("profitable " if filteroptions['only_profitable'] else "") + - "epochs found.") + epochs = [x for x in epochs if x['loss'] > filteroptions['filter_max_objective']] return epochs