Move format explanation string to HyperoptTools

This commit is contained in:
Matthias 2021-05-01 09:05:46 +02:00
parent 4c00d4496d
commit 97478abb9d
3 changed files with 18 additions and 17 deletions

View File

@ -4,7 +4,6 @@
This module contains the hyperopt logic
"""
import locale
import logging
import random
import warnings
@ -301,7 +300,7 @@ class Hyperopt:
strat_stats = generate_strategy_stats(processed, '', backtesting_results,
min_date, max_date, market_change=0)
results_explanation = self._format_results_explanation_string(
results_explanation = HyperoptTools.format_results_explanation_string(
strat_stats, self.config['stake_currency'])
trade_count = strat_stats['total_trades']
@ -326,20 +325,6 @@ class Hyperopt:
'total_profit': total_profit,
}
def _format_results_explanation_string(self, results_metrics: Dict, stake_currency: str) -> str:
"""
Return the formatted results explanation in a string
"""
return (f"{results_metrics['total_trades']:6d} trades. "
f"{results_metrics['wins']}/{results_metrics['draws']}"
f"/{results_metrics['losses']} Wins/Draws/Losses. "
f"Avg profit {results_metrics['profit_mean'] * 100: 6.2f}%. "
f"Median profit {results_metrics['profit_median'] * 100: 6.2f}%. "
f"Total profit {results_metrics['profit_total_abs']: 11.8f} {stake_currency} "
f"({results_metrics['profit_total']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). "
f"Avg duration {results_metrics['holding_avg']} min."
).encode(locale.getpreferredencoding(), 'replace').decode('utf-8')
def get_optimizer(self, dimensions: List[Dimension], cpu_count) -> Optimizer:
return Optimizer(
dimensions,

View File

@ -1,5 +1,6 @@
import io
import locale
import logging
from collections import OrderedDict
from pathlib import Path
@ -145,6 +146,21 @@ class HyperoptTools():
def is_best_loss(results, current_best_loss: float) -> bool:
return results['loss'] < current_best_loss
@staticmethod
def format_results_explanation_string(results_metrics: Dict, stake_currency: str) -> str:
"""
Return the formatted results explanation in a string
"""
return (f"{results_metrics['total_trades']:6d} trades. "
f"{results_metrics['wins']}/{results_metrics['draws']}"
f"/{results_metrics['losses']} Wins/Draws/Losses. "
f"Avg profit {results_metrics['profit_mean'] * 100: 6.2f}%. "
f"Median profit {results_metrics['profit_median'] * 100: 6.2f}%. "
f"Total profit {results_metrics['profit_total_abs']: 11.8f} {stake_currency} "
f"({results_metrics['profit_total']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). "
f"Avg duration {results_metrics['holding_avg']} min."
).encode(locale.getpreferredencoding(), 'replace').decode('utf-8')
@staticmethod
def _format_explanation_string(results, total_epochs) -> str:
return (("*" if results['is_initial_point'] else " ") +

View File

@ -468,7 +468,7 @@ def test_hyperopt_format_results(hyperopt):
Arrow(2017, 11, 14, 19, 32, 00),
Arrow(2017, 12, 14, 19, 32, 00), market_change=0)
results_explanation = hyperopt._format_results_explanation_string(results_metrics, 'BTC')
results_explanation = HyperoptTools.format_results_explanation_string(results_metrics, 'BTC')
total_profit = results_metrics['profit_total_abs']
results = {