]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): improve type hints and variable declarations
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 23 Nov 2025 18:38:15 +0000 (19:38 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 23 Nov 2025 18:38:15 +0000 (19:38 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py

index e5aaea4a08418941566b6e3ec3392f956be96a3c..c971cddd89edb4b644ddd3d319a5d36ec5cd79ad 100644 (file)
@@ -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:
index 4e2dd37b96b724a88d356b3433af42ce40a2d041..080065a73bdde26b803d315d9e64bbed707d39ec 100644 (file)
@@ -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)
 
index dd26e10e007e60b8f86b232d0913c7e13b1f3118..3a6ede8b6c22448a191fdb809ecccbe207f30daf 100644 (file)
@@ -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),