Added filter options to "hyperopt-list" in order to easier find epochs.

--profitable
	Select only profitable epochs.
  --min-avg-time INT
	Select epochs on above average time.
  --max-avg-time INT
	Select epochs on under average time.
  --min-avg-profit FLOAT
	Select epochs on above average profit.
  --min-total-profit FLOAT
	Select epochs on above total profit.
This commit is contained in:
Fredrik Rydin
2020-02-08 23:21:42 +01:00
parent fff8ced3b0
commit 636bd5acb5
5 changed files with 91 additions and 19 deletions

View File

@@ -19,13 +19,20 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None:
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
only_best = config.get('hyperopt_list_best', False)
only_profitable = config.get('hyperopt_list_profitable', False)
print_colorized = config.get('print_colorized', False)
print_json = config.get('print_json', False)
no_details = config.get('hyperopt_list_no_details', False)
no_header = False
filteroptions = {
'only_best': config.get('hyperopt_list_best', False),
'only_profitable': config.get('hyperopt_list_profitable', False),
'filter_min_avg_time': config.get('hyperopt_list_min_avg_time', 0),
'filter_max_avg_time': config.get('hyperopt_list_max_avg_time', 0),
'filter_min_avg_profit': config.get('hyperopt_list_min_avg_profit', 0.0),
'filter_min_total_profit': config.get('hyperopt_list_min_total_profit', 0.0)
}
trials_file = (config['user_data_dir'] /
'hyperopt_results' / 'hyperopt_results.pickle')
@@ -33,7 +40,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None:
trials = Hyperopt.load_previous_results(trials_file)
total_epochs = len(trials)
trials = _hyperopt_filter_trials(trials, only_best, only_profitable)
trials = _hyperopt_filter_trials(trials, filteroptions)
# TODO: fetch the interval for epochs to print from the cli option
epoch_start, epoch_stop = 0, None
@@ -44,7 +51,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None:
try:
# Human-friendly indexes used here (starting from 1)
for val in trials[epoch_start:epoch_stop]:
Hyperopt.print_results_explanation(val, total_epochs, not only_best, print_colorized)
Hyperopt.print_results_explanation(val, total_epochs, not filteroptions['only_best'], print_colorized)
except KeyboardInterrupt:
print('User interrupted..')
@@ -63,8 +70,14 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None:
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
only_best = config.get('hyperopt_list_best', False)
only_profitable = config.get('hyperopt_list_profitable', False)
filteroptions = {
'only_best': config.get('hyperopt_list_best', False),
'only_profitable': config.get('hyperopt_list_profitable', False),
'filter_min_avg_time': config.get('hyperopt_list_min_avg_time', 0),
'filter_max_avg_time': config.get('hyperopt_list_max_avg_time', 0),
'filter_min_avg_profit': config.get('hyperopt_list_min_avg_profit', 0),
'filter_min_total_profit': config.get('hyperopt_list_min_total_profit', 0)
}
no_header = config.get('hyperopt_show_no_header', False)
trials_file = (config['user_data_dir'] /
@@ -74,7 +87,7 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None:
trials = Hyperopt.load_previous_results(trials_file)
total_epochs = len(trials)
trials = _hyperopt_filter_trials(trials, only_best, only_profitable)
trials = _hyperopt_filter_trials(trials, filteroptions)
trials_epochs = len(trials)
n = config.get('hyperopt_show_index', -1)
@@ -97,18 +110,28 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None:
header_str="Epoch details")
def _hyperopt_filter_trials(trials: List, only_best: bool, only_profitable: bool) -> List:
def _hyperopt_filter_trials(trials: List, filteroptions: dict) -> List:
"""
Filter our items from the list of hyperopt results
"""
if only_best:
if filteroptions['only_best']:
trials = [x for x in trials if x['is_best']]
if only_profitable:
if filteroptions['only_profitable']:
trials = [x for x in trials if x['results_metrics']['profit'] > 0]
if not filteroptions['only_best']:
if filteroptions['filter_min_avg_time'] > 0:
trials = [x for x in trials if x['results_metrics']['duration'] > filteroptions['filter_min_avg_time']]
if filteroptions['filter_max_avg_time'] > 0:
trials = [x for x in trials if x['results_metrics']['duration'] < filteroptions['filter_max_avg_time']]
if filteroptions['filter_min_avg_profit'] > 0:
trials = [x for x in trials if x['results_metrics']['avg_profit'] > filteroptions['filter_min_avg_profit']]
if filteroptions['filter_min_total_profit'] > 0:
trials = [x for x in trials if x['results_metrics']['profit'] > filteroptions['filter_min_total_profit']]
logger.info(f"{len(trials)} " +
("best " if only_best else "") +
("profitable " if only_profitable else "") +
("best " if filteroptions['only_best'] else "") +
("profitable " if filteroptions['only_profitable'] else "") +
"epochs found.")
return trials