From: Jérôme Benoit Date: Sun, 23 Nov 2025 18:38:15 +0000 (+0100) Subject: refactor(qav3): improve type hints and variable declarations X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=88134d42da0fe4939de7853c153c1fa004d9f268;p=freqai-strategies.git refactor(qav3): improve type hints and variable declarations Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index e5aaea4..c971cdd 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -1885,7 +1885,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel): self, pair: str, namespace: str, study: Optional[optuna.study.Study] ) -> None: best_params = self.get_optuna_params(pair, namespace) - if best_params and self.optuna_validate_params(pair, namespace, study): + if study and best_params and self.optuna_validate_params(pair, namespace, study): study.enqueue_trial(best_params) def optuna_save_best_params(self, pair: str, namespace: str) -> None: diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 4e2dd37..080065a 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -1403,7 +1403,7 @@ class QuickAdapterV3(IStrategy): @staticmethod def weighted_close(series: Series, weight: float = 2.0) -> float: - return ( + return float( series.get("high") + series.get("low") + weight * series.get("close") ) / (2.0 + weight) diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index dd26e10..3a6ede8 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -483,7 +483,7 @@ def get_weighted_extrema( raise ValueError(f"Unknown weight strategy: {strategy}") -def get_callable_sha256(fn: Callable) -> str: +def get_callable_sha256(fn: Callable[..., Any]) -> str: if not callable(fn): raise ValueError("fn must be callable") code = getattr(fn, "__code__", None) @@ -1074,10 +1074,10 @@ def zigzag( initial_move_from_high = (initial_high - current_low) / initial_high initial_move_from_low = (current_high - initial_low) / initial_low - is_initial_high_move_significant = ( + is_initial_high_move_significant: bool = ( initial_move_from_high >= thresholds[initial_high_pos] ) - is_initial_low_move_significant = ( + is_initial_low_move_significant: bool = ( initial_move_from_low >= thresholds[initial_low_pos] ) if is_initial_high_move_significant and is_initial_low_move_significant: @@ -1239,7 +1239,7 @@ def get_optuna_study_model_parameters( raise ValueError( f"expansion_ratio must be a float between 0 and 1, got {expansion_ratio}" ) - default_ranges = { + default_ranges: dict[str, tuple[float, float]] = { "n_estimators": (100, 2000), "learning_rate": (1e-3, 0.5), "min_child_weight": (1e-8, 100.0),