mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Refactor hyperopt_filter method
This commit is contained in:
parent
f51c03aa86
commit
56655b97cf
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue
Block a user