Move format explanation string to HyperoptTools
This commit is contained in:
parent
4c00d4496d
commit
97478abb9d
@ -4,7 +4,6 @@
|
|||||||
This module contains the hyperopt logic
|
This module contains the hyperopt logic
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import locale
|
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import warnings
|
import warnings
|
||||||
@ -301,7 +300,7 @@ class Hyperopt:
|
|||||||
|
|
||||||
strat_stats = generate_strategy_stats(processed, '', backtesting_results,
|
strat_stats = generate_strategy_stats(processed, '', backtesting_results,
|
||||||
min_date, max_date, market_change=0)
|
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'])
|
strat_stats, self.config['stake_currency'])
|
||||||
|
|
||||||
trade_count = strat_stats['total_trades']
|
trade_count = strat_stats['total_trades']
|
||||||
@ -326,20 +325,6 @@ class Hyperopt:
|
|||||||
'total_profit': total_profit,
|
'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:
|
def get_optimizer(self, dimensions: List[Dimension], cpu_count) -> Optimizer:
|
||||||
return Optimizer(
|
return Optimizer(
|
||||||
dimensions,
|
dimensions,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import io
|
import io
|
||||||
|
import locale
|
||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -145,6 +146,21 @@ class HyperoptTools():
|
|||||||
def is_best_loss(results, current_best_loss: float) -> bool:
|
def is_best_loss(results, current_best_loss: float) -> bool:
|
||||||
return results['loss'] < current_best_loss
|
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
|
@staticmethod
|
||||||
def _format_explanation_string(results, total_epochs) -> str:
|
def _format_explanation_string(results, total_epochs) -> str:
|
||||||
return (("*" if results['is_initial_point'] else " ") +
|
return (("*" if results['is_initial_point'] else " ") +
|
||||||
|
@ -468,7 +468,7 @@ def test_hyperopt_format_results(hyperopt):
|
|||||||
Arrow(2017, 11, 14, 19, 32, 00),
|
Arrow(2017, 11, 14, 19, 32, 00),
|
||||||
Arrow(2017, 12, 14, 19, 32, 00), market_change=0)
|
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']
|
total_profit = results_metrics['profit_total_abs']
|
||||||
|
|
||||||
results = {
|
results = {
|
||||||
|
Loading…
Reference in New Issue
Block a user