]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): remove unneeded zigzag caching
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 13 Jun 2025 20:22:22 +0000 (22:22 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 13 Jun 2025 20:22:22 +0000 (22:22 +0200)
no performance improvements

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 d6ae4e823abb3aff73b55366a696bec673174d80..a12bbe029b9a3e99a6fdbfb3276c898d29c68d22 100644 (file)
@@ -1,6 +1,5 @@
 import copy
 from enum import IntEnum
-import hashlib
 import logging
 import json
 import random
@@ -49,7 +48,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
     https://github.com/sponsors/robcaulk
     """
 
-    version = "3.7.86"
+    version = "3.7.87"
 
     @cached_property
     def _optuna_config(self) -> dict:
@@ -1206,45 +1205,6 @@ class TrendDirection(IntEnum):
     DOWN = -1
 
 
-zigzag_cache: dict[str, tuple[list[int], list[float], list[int]], list[float]] = {}
-
-
-def zigzag_cached(
-    df: pd.DataFrame,
-    natr_period: int = 14,
-    natr_ratio: float = 6.0,
-    cache_size: int = 2048,
-) -> tuple[list[int], list[float], list[int], list[float]]:
-    def hash_df(df: pd.DataFrame) -> str:
-        hasher = hashlib.sha256()
-
-        arr = df.to_numpy()
-
-        hasher.update(str(arr.shape).encode())
-        hasher.update(str(arr.dtype).encode())
-
-        hasher.update(arr.tobytes())
-
-        return hasher.hexdigest()
-
-    cache_key = f"{hash_df(df)}-{natr_period}-{natr_ratio}"
-    if cache_key in zigzag_cache:
-        return zigzag_cache[cache_key]
-
-    pivots_indices, pivots_values, pivots_directions, pivots_scaled_natrs = zigzag(
-        df, natr_period=natr_period, natr_ratio=natr_ratio
-    )
-    if len(zigzag_cache) >= cache_size:
-        del zigzag_cache[next(iter(zigzag_cache))]
-    zigzag_cache[cache_key] = (
-        pivots_indices,
-        pivots_values,
-        pivots_directions,
-        pivots_scaled_natrs,
-    )
-    return pivots_indices, pivots_values, pivots_directions, pivots_scaled_natrs
-
-
 def zigzag(
     df: pd.DataFrame,
     natr_period: int = 14,
@@ -1565,7 +1525,7 @@ def label_objective(
     if df.empty:
         return -np.inf, -np.inf
 
-    _, pivots_values, _, pivots_scaled_natrs = zigzag_cached(
+    _, pivots_values, _, pivots_scaled_natrs = zigzag(
         df,
         natr_period=label_period_candles,
         natr_ratio=label_natr_ratio,
index 5056e249b4fce6462f12b2c88dbaebbde59660c3..2db1b5f89028ccb9c983698d409dcf2aab24ed6d 100644 (file)
@@ -61,7 +61,7 @@ class QuickAdapterV3(IStrategy):
     INTERFACE_VERSION = 3
 
     def version(self) -> str:
-        return "3.3.90"
+        return "3.3.91"
 
     timeframe = "5m"
 
index a0e379c5767321f8404113e32d8eba4206dad88e..d9375a9a80adde9c691d1df4a14d9d81fd2dd519 100644 (file)
@@ -1,6 +1,5 @@
 from enum import IntEnum
 from functools import lru_cache
-import hashlib
 from statistics import median
 import numpy as np
 import pandas as pd
@@ -378,45 +377,6 @@ class TrendDirection(IntEnum):
     DOWN = -1
 
 
-zigzag_cache: dict[str, tuple[list[int], list[float], list[int]], list[float]] = {}
-
-
-def zigzag_cached(
-    df: pd.DataFrame,
-    natr_period: int = 14,
-    natr_ratio: float = 6.0,
-    cache_size: int = 2048,
-) -> tuple[list[int], list[float], list[int], list[float]]:
-    def hash_df(df: pd.DataFrame) -> str:
-        hasher = hashlib.sha256()
-
-        arr = df.to_numpy()
-
-        hasher.update(str(arr.shape).encode())
-        hasher.update(str(arr.dtype).encode())
-
-        hasher.update(arr.tobytes())
-
-        return hasher.hexdigest()
-
-    cache_key = f"{hash_df(df)}-{natr_period}-{natr_ratio}"
-    if cache_key in zigzag_cache:
-        return zigzag_cache[cache_key]
-
-    pivots_indices, pivots_values, pivots_directions, pivots_scaled_natrs = zigzag(
-        df, natr_period=natr_period, natr_ratio=natr_ratio
-    )
-    if len(zigzag_cache) >= cache_size:
-        del zigzag_cache[next(iter(zigzag_cache))]
-    zigzag_cache[cache_key] = (
-        pivots_indices,
-        pivots_values,
-        pivots_directions,
-        pivots_scaled_natrs,
-    )
-    return pivots_indices, pivots_values, pivots_directions, pivots_scaled_natrs
-
-
 def zigzag(
     df: pd.DataFrame,
     natr_period: int = 14,