import pandas as pd
import scipy as sp
import talib.abstract as ta
+from freqtrade.misc import pair_to_filename
from LabelTransformer import (
COMBINED_AGGREGATIONS,
COMBINED_METRICS,
_OPTUNA_NAMESPACES: Final[_OptunaNamespaces] = _OptunaNamespaces()
+def _optuna_best_params_path(
+ base_path: Path, pair: str, namespace: OptunaNamespace
+) -> Path:
+ return base_path / f"optuna-{namespace}-best-params-{pair_to_filename(pair)}.json"
+
+
_OPTUNA_LABEL_BEST_PARAMS_SCHEMA_VERSION: Final[int] = 2
-"""Wire format version of optuna-label-best-params-{pair}.json.
+"""Wire format version of pair-specific Optuna label best-params JSON files.
Incremented on every on-disk JSON shape change (top-level keys, params layout).
"""
expected_selection_metadata: dict[str, Any] | None = None,
expected_objective_identity: str | None = None,
) -> dict[str, Any] | None:
- best_params_path = (
- base_path / f"optuna-{namespace}-best-params-{pair.split('/')[0]}.json"
- )
+ best_params_path = _optuna_best_params_path(base_path, pair, namespace)
if best_params_path.is_file():
with best_params_path.open("r", encoding="utf-8") as read_file:
best_params = json.load(read_file)
return None
return best_params["params"]
return best_params
+ legacy_best_params_path = (
+ base_path / f"optuna-{namespace}-best-params-{pair.split('/')[0]}.json"
+ )
+ if (
+ logger is not None
+ and legacy_best_params_path != best_params_path
+ and legacy_best_params_path.is_file()
+ ):
+ logger.warning(
+ f"[{pair}] Ignoring ambiguous legacy Optuna {namespace} best params "
+ f"at {legacy_best_params_path}: filename does not encode the complete "
+ f"pair identity"
+ )
return None
selection_metadata: dict[str, Any] | None = None,
objective_identity: str | None = None,
) -> None:
- best_params_path = (
- base_path / f"optuna-{namespace}-best-params-{pair.split('/')[0]}.json"
- )
+ best_params_path = _optuna_best_params_path(base_path, pair, namespace)
try:
if namespace == _OPTUNA_NAMESPACES.label:
best_params: dict[str, Any] = {