Simplifying HO's result function
This commit is contained in:
parent
3cce668353
commit
40f1ede775
@ -206,33 +206,20 @@ class HyperoptTools():
|
|||||||
f"Objective: {results['loss']:.5f}")
|
f"Objective: {results['loss']:.5f}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_result_table(config: dict, results: list, total_epochs: int, highlight_best: bool,
|
def prepare_trials_columns(trials, legacy_mode: bool, has_drawdown: bool) -> str:
|
||||||
print_colorized: bool, remove_header: int) -> str:
|
|
||||||
"""
|
|
||||||
Log result table
|
|
||||||
"""
|
|
||||||
if not results:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
tabulate.PRESERVE_WHITESPACE = True
|
|
||||||
|
|
||||||
trials = json_normalize(results, max_level=1)
|
|
||||||
trials['Best'] = ''
|
trials['Best'] = ''
|
||||||
|
|
||||||
if 'results_metrics.winsdrawslosses' not in trials.columns:
|
if 'results_metrics.winsdrawslosses' not in trials.columns:
|
||||||
# Ensure compatibility with older versions of hyperopt results
|
# Ensure compatibility with older versions of hyperopt results
|
||||||
trials['results_metrics.winsdrawslosses'] = 'N/A'
|
trials['results_metrics.winsdrawslosses'] = 'N/A'
|
||||||
|
|
||||||
has_drawdown = True
|
if not has_drawdown:
|
||||||
if 'results_metrics.max_drawdown_abs' not in trials.columns:
|
|
||||||
# Ensure compatibility with older versions of hyperopt results
|
# Ensure compatibility with older versions of hyperopt results
|
||||||
trials['results_metrics.max_drawdown_abs'] = None
|
trials['results_metrics.max_drawdown_abs'] = None
|
||||||
trials['results_metrics.max_drawdown'] = None
|
trials['results_metrics.max_drawdown'] = None
|
||||||
has_drawdown = False
|
|
||||||
|
|
||||||
legacy_mode = True
|
if not legacy_mode:
|
||||||
|
|
||||||
if 'results_metrics.total_trades' in trials:
|
|
||||||
legacy_mode = False
|
|
||||||
# New mode, using backtest result for metrics
|
# New mode, using backtest result for metrics
|
||||||
trials['results_metrics.winsdrawslosses'] = trials.apply(
|
trials['results_metrics.winsdrawslosses'] = trials.apply(
|
||||||
lambda x: f"{x['results_metrics.wins']} {x['results_metrics.draws']:>4} "
|
lambda x: f"{x['results_metrics.wins']} {x['results_metrics.draws']:>4} "
|
||||||
@ -257,6 +244,25 @@ class HyperoptTools():
|
|||||||
'Total profit', 'Profit', 'Avg duration', 'Max Drawdown',
|
'Total profit', 'Profit', 'Avg duration', 'Max Drawdown',
|
||||||
'max_drawdown_abs', 'Objective', 'is_initial_point', 'is_best']
|
'max_drawdown_abs', 'Objective', 'is_initial_point', 'is_best']
|
||||||
|
|
||||||
|
return trials
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result_table(config: dict, results: list, total_epochs: int, highlight_best: bool,
|
||||||
|
print_colorized: bool, remove_header: int) -> str:
|
||||||
|
"""
|
||||||
|
Log result table
|
||||||
|
"""
|
||||||
|
if not results:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
tabulate.PRESERVE_WHITESPACE = True
|
||||||
|
trials = json_normalize(results, max_level=1)
|
||||||
|
|
||||||
|
legacy_mode = 'results_metrics.total_trades' not in trials
|
||||||
|
has_drawdown = 'results_metrics.max_drawdown_abs' in trials.columns
|
||||||
|
|
||||||
|
trials = HyperoptTools.prepare_trials_columns(trials, legacy_mode, has_drawdown)
|
||||||
|
|
||||||
trials['is_profit'] = False
|
trials['is_profit'] = False
|
||||||
trials.loc[trials['is_initial_point'], 'Best'] = '* '
|
trials.loc[trials['is_initial_point'], 'Best'] = '* '
|
||||||
trials.loc[trials['is_best'], 'Best'] = 'Best'
|
trials.loc[trials['is_best'], 'Best'] = 'Best'
|
||||||
|
Loading…
Reference in New Issue
Block a user