Show wins / draws / losses in hyperopt table

This commit is contained in:
Matthias 2020-08-14 07:12:57 +02:00
parent 05bd099f51
commit d76ee43246
2 changed files with 14 additions and 4 deletions

View File

@ -312,11 +312,16 @@ class Hyperopt:
trials = json_normalize(results, max_level=1)
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',
'results_metrics.winsdrawslosses',
'results_metrics.avg_profit', 'results_metrics.total_profit',
'results_metrics.profit', 'results_metrics.duration',
'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']
trials['is_profit'] = False
trials.loc[trials['is_initial_point'], 'Best'] = '* '
@ -558,11 +563,15 @@ class Hyperopt:
}
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 {
'trade_count': len(backtesting_results.index),
'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]),
'wins': wins,
'draws': draws,
'losses': losses,
'winsdrawslosses': f"{wins}/{draws}/{losses}",
'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(),

View File

@ -781,6 +781,7 @@ def test_generate_optimizer(mocker, default_conf) -> None:
'draws': 0,
'duration': 100.0,
'losses': 0,
'winsdrawslosses': '1/0/0',
'median_profit': 2.3117,
'profit': 2.3117,
'total_profit': 0.000233,