Merge pull request #3008 from yazeed/more_info_hyperopt_fixed
Wins/draws/losses/median profit in hyperopt output
This commit is contained in:
commit
93717cfef1
@ -312,11 +312,16 @@ class Hyperopt:
|
|||||||
|
|
||||||
trials = json_normalize(results, max_level=1)
|
trials = json_normalize(results, max_level=1)
|
||||||
trials['Best'] = ''
|
trials['Best'] = ''
|
||||||
|
if 'results_metrics.winsdrawslosses' not in trials.columns:
|
||||||
|
# Ensure compatibility with older versions of hyperopt results
|
||||||
|
trials['results_metrics.winsdrawslosses'] = 'N/A'
|
||||||
|
|
||||||
trials = trials[['Best', 'current_epoch', 'results_metrics.trade_count',
|
trials = trials[['Best', 'current_epoch', 'results_metrics.trade_count',
|
||||||
|
'results_metrics.winsdrawslosses',
|
||||||
'results_metrics.avg_profit', 'results_metrics.total_profit',
|
'results_metrics.avg_profit', 'results_metrics.total_profit',
|
||||||
'results_metrics.profit', 'results_metrics.duration',
|
'results_metrics.profit', 'results_metrics.duration',
|
||||||
'loss', 'is_initial_point', 'is_best']]
|
'loss', 'is_initial_point', 'is_best']]
|
||||||
trials.columns = ['Best', 'Epoch', 'Trades', 'Avg profit', 'Total profit',
|
trials.columns = ['Best', 'Epoch', 'Trades', 'W/D/L', 'Avg profit', 'Total profit',
|
||||||
'Profit', 'Avg duration', 'Objective', 'is_initial_point', 'is_best']
|
'Profit', 'Avg duration', 'Objective', 'is_initial_point', 'is_best']
|
||||||
trials['is_profit'] = False
|
trials['is_profit'] = False
|
||||||
trials.loc[trials['is_initial_point'], 'Best'] = '* '
|
trials.loc[trials['is_initial_point'], 'Best'] = '* '
|
||||||
@ -558,9 +563,17 @@ class Hyperopt:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _calculate_results_metrics(self, backtesting_results: DataFrame) -> Dict:
|
def _calculate_results_metrics(self, backtesting_results: DataFrame) -> Dict:
|
||||||
|
wins = len(backtesting_results[backtesting_results.profit_percent > 0])
|
||||||
|
draws = len(backtesting_results[backtesting_results.profit_percent == 0])
|
||||||
|
losses = len(backtesting_results[backtesting_results.profit_percent < 0])
|
||||||
return {
|
return {
|
||||||
'trade_count': len(backtesting_results.index),
|
'trade_count': len(backtesting_results.index),
|
||||||
|
'wins': wins,
|
||||||
|
'draws': draws,
|
||||||
|
'losses': losses,
|
||||||
|
'winsdrawslosses': f"{wins}/{draws}/{losses}",
|
||||||
'avg_profit': backtesting_results.profit_percent.mean() * 100.0,
|
'avg_profit': backtesting_results.profit_percent.mean() * 100.0,
|
||||||
|
'median_profit': backtesting_results.profit_percent.median() * 100.0,
|
||||||
'total_profit': backtesting_results.profit_abs.sum(),
|
'total_profit': backtesting_results.profit_abs.sum(),
|
||||||
'profit': backtesting_results.profit_percent.sum() * 100.0,
|
'profit': backtesting_results.profit_percent.sum() * 100.0,
|
||||||
'duration': backtesting_results.trade_duration.mean(),
|
'duration': backtesting_results.trade_duration.mean(),
|
||||||
@ -572,7 +585,10 @@ class Hyperopt:
|
|||||||
"""
|
"""
|
||||||
stake_cur = self.config['stake_currency']
|
stake_cur = self.config['stake_currency']
|
||||||
return (f"{results_metrics['trade_count']:6d} trades. "
|
return (f"{results_metrics['trade_count']:6d} trades. "
|
||||||
|
f"{results_metrics['wins']}/{results_metrics['draws']}"
|
||||||
|
f"/{results_metrics['losses']} Wins/Draws/Losses. "
|
||||||
f"Avg profit {results_metrics['avg_profit']: 6.2f}%. "
|
f"Avg profit {results_metrics['avg_profit']: 6.2f}%. "
|
||||||
|
f"Median profit {results_metrics['median_profit']: 6.2f}%. "
|
||||||
f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} "
|
f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} "
|
||||||
f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). "
|
f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). "
|
||||||
f"Avg duration {results_metrics['duration']:5.1f} min."
|
f"Avg duration {results_metrics['duration']:5.1f} min."
|
||||||
|
@ -744,8 +744,10 @@ def test_generate_optimizer(mocker, default_conf) -> None:
|
|||||||
}
|
}
|
||||||
response_expected = {
|
response_expected = {
|
||||||
'loss': 1.9840569076926293,
|
'loss': 1.9840569076926293,
|
||||||
'results_explanation': (' 1 trades. Avg profit 2.31%. Total profit 0.00023300 BTC '
|
'results_explanation': (' 1 trades. 1/0/0 Wins/Draws/Losses. '
|
||||||
'( 2.31\N{GREEK CAPITAL LETTER SIGMA}%). Avg duration 100.0 min.'
|
'Avg profit 2.31%. Median profit 2.31%. Total profit '
|
||||||
|
'0.00023300 BTC ( 2.31\N{GREEK CAPITAL LETTER SIGMA}%). '
|
||||||
|
'Avg duration 100.0 min.'
|
||||||
).encode(locale.getpreferredencoding(), 'replace').decode('utf-8'),
|
).encode(locale.getpreferredencoding(), 'replace').decode('utf-8'),
|
||||||
'params_details': {'buy': {'adx-enabled': False,
|
'params_details': {'buy': {'adx-enabled': False,
|
||||||
'adx-value': 0,
|
'adx-value': 0,
|
||||||
@ -776,10 +778,15 @@ def test_generate_optimizer(mocker, default_conf) -> None:
|
|||||||
'trailing_stop_positive_offset': 0.07}},
|
'trailing_stop_positive_offset': 0.07}},
|
||||||
'params_dict': optimizer_param,
|
'params_dict': optimizer_param,
|
||||||
'results_metrics': {'avg_profit': 2.3117,
|
'results_metrics': {'avg_profit': 2.3117,
|
||||||
|
'draws': 0,
|
||||||
'duration': 100.0,
|
'duration': 100.0,
|
||||||
|
'losses': 0,
|
||||||
|
'winsdrawslosses': '1/0/0',
|
||||||
|
'median_profit': 2.3117,
|
||||||
'profit': 2.3117,
|
'profit': 2.3117,
|
||||||
'total_profit': 0.000233,
|
'total_profit': 0.000233,
|
||||||
'trade_count': 1},
|
'trade_count': 1,
|
||||||
|
'wins': 1},
|
||||||
'total_profit': 0.00023300
|
'total_profit': 0.00023300
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user