2020-01-26 12:08:58 +00:00
|
|
|
import logging
|
|
|
|
from operator import itemgetter
|
2021-08-08 08:05:28 +00:00
|
|
|
from typing import Any, Dict
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
from colorama import init as colorama_init
|
|
|
|
|
2020-01-26 12:55:48 +00:00
|
|
|
from freqtrade.configuration import setup_utils_configuration
|
2020-09-28 18:21:55 +00:00
|
|
|
from freqtrade.data.btanalysis import get_latest_hyperopt_file
|
2021-06-08 19:20:35 +00:00
|
|
|
from freqtrade.enums import RunMode
|
2020-01-26 12:08:58 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2021-05-01 11:32:34 +00:00
|
|
|
from freqtrade.optimize.optimize_reports import show_backtest_result
|
2020-01-26 12:08:58 +00:00
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2020-01-26 12:08:58 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-08-11 18:37:01 +00:00
|
|
|
|
2020-01-26 12:08:58 +00:00
|
|
|
def start_hyperopt_list(args: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
List hyperopt epochs previously evaluated
|
|
|
|
"""
|
2021-03-17 19:43:51 +00:00
|
|
|
from freqtrade.optimize.hyperopt_tools import HyperoptTools
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
print_colorized = config.get("print_colorized", False)
|
|
|
|
print_json = config.get("print_json", False)
|
|
|
|
export_csv = config.get("export_csv")
|
|
|
|
no_details = config.get("hyperopt_list_no_details", False)
|
2020-01-26 12:08:58 +00:00
|
|
|
no_header = False
|
|
|
|
|
2020-09-27 15:00:23 +00:00
|
|
|
results_file = get_latest_hyperopt_file(
|
2024-05-12 14:27:03 +00:00
|
|
|
config["user_data_dir"] / "hyperopt_results", config.get("hyperoptexportfilename")
|
|
|
|
)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
# Previous evaluations
|
2021-08-08 08:05:28 +00:00
|
|
|
epochs, total_epochs = HyperoptTools.load_filtered_results(results_file, config)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
if print_colorized:
|
|
|
|
colorama_init(autoreset=True)
|
|
|
|
|
2020-03-05 18:43:43 +00:00
|
|
|
if not export_csv:
|
|
|
|
try:
|
2024-05-12 14:27:03 +00:00
|
|
|
print(
|
|
|
|
HyperoptTools.get_result_table(
|
|
|
|
config,
|
|
|
|
epochs,
|
|
|
|
total_epochs,
|
|
|
|
not config.get("hyperopt_list_best", False),
|
|
|
|
print_colorized,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
)
|
2020-03-05 18:43:43 +00:00
|
|
|
except KeyboardInterrupt:
|
2024-05-12 14:27:03 +00:00
|
|
|
print("User interrupted..")
|
2020-01-26 12:08:58 +00:00
|
|
|
|
2020-04-28 20:14:02 +00:00
|
|
|
if epochs and not no_details:
|
2024-05-12 14:27:03 +00:00
|
|
|
sorted_epochs = sorted(epochs, key=itemgetter("loss"))
|
2020-04-28 20:14:02 +00:00
|
|
|
results = sorted_epochs[0]
|
2021-06-13 09:24:24 +00:00
|
|
|
HyperoptTools.show_epoch_details(results, total_epochs, print_json, no_header)
|
2020-03-05 18:43:43 +00:00
|
|
|
|
2020-04-28 20:14:02 +00:00
|
|
|
if epochs and export_csv:
|
2024-05-12 14:27:03 +00:00
|
|
|
HyperoptTools.export_csv_file(config, epochs, export_csv)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_hyperopt_show(args: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Show details of a hyperopt epoch previously evaluated
|
|
|
|
"""
|
2021-03-17 19:43:51 +00:00
|
|
|
from freqtrade.optimize.hyperopt_tools import HyperoptTools
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
print_json = config.get("print_json", False)
|
|
|
|
no_header = config.get("hyperopt_show_no_header", False)
|
2020-09-27 15:00:23 +00:00
|
|
|
results_file = get_latest_hyperopt_file(
|
2024-05-12 14:27:03 +00:00
|
|
|
config["user_data_dir"] / "hyperopt_results", config.get("hyperoptexportfilename")
|
|
|
|
)
|
2020-09-27 15:00:23 +00:00
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
n = config.get("hyperopt_show_index", -1)
|
2020-02-18 21:46:53 +00:00
|
|
|
|
2020-01-26 12:08:58 +00:00
|
|
|
# Previous evaluations
|
2021-08-08 08:05:28 +00:00
|
|
|
epochs, total_epochs = HyperoptTools.load_filtered_results(results_file, config)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
2020-04-28 20:14:02 +00:00
|
|
|
filtered_epochs = len(epochs)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
2020-04-28 20:14:02 +00:00
|
|
|
if n > filtered_epochs:
|
2020-01-26 12:08:58 +00:00
|
|
|
raise OperationalException(
|
2024-05-12 14:27:03 +00:00
|
|
|
f"The index of the epoch to show should be less than {filtered_epochs + 1}."
|
|
|
|
)
|
2020-04-28 20:14:02 +00:00
|
|
|
if n < -filtered_epochs:
|
2020-01-26 12:08:58 +00:00
|
|
|
raise OperationalException(
|
2024-05-12 14:27:03 +00:00
|
|
|
f"The index of the epoch to show should be greater than {-filtered_epochs - 1}."
|
|
|
|
)
|
2020-01-26 12:08:58 +00:00
|
|
|
|
|
|
|
# Translate epoch index from human-readable format to pythonic
|
|
|
|
if n > 0:
|
|
|
|
n -= 1
|
|
|
|
|
2020-04-28 20:14:02 +00:00
|
|
|
if epochs:
|
|
|
|
val = epochs[n]
|
2021-05-01 11:32:34 +00:00
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
metrics = val["results_metrics"]
|
|
|
|
if "strategy_name" in metrics:
|
|
|
|
strategy_name = metrics["strategy_name"]
|
|
|
|
show_backtest_result(
|
|
|
|
strategy_name,
|
|
|
|
metrics,
|
|
|
|
metrics["stake_currency"],
|
|
|
|
config.get("backtest_breakdown", []),
|
|
|
|
)
|
2021-05-01 11:32:34 +00:00
|
|
|
|
2021-06-29 18:22:30 +00:00
|
|
|
HyperoptTools.try_export_params(config, strategy_name, val)
|
2021-05-29 14:49:28 +00:00
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
HyperoptTools.show_epoch_details(
|
|
|
|
val, total_epochs, print_json, no_header, header_str="Epoch details"
|
|
|
|
)
|