diff --git a/jesse/utils.py b/jesse/utils.py index 9770f0c9e..0d99b2f56 100644 --- a/jesse/utils.py +++ b/jesse/utils.py @@ -313,31 +313,6 @@ def combinations_without_repeat(a: np.ndarray, n: int = 2) -> np.ndarray: return np.array(list(permutations(a, n))) -def wavelet_denoising(raw: np.ndarray, wavelet='haar', level: int = 1, mode: str = 'symmetric', - smoothing_factor: float = 0, threshold_mode: str = 'hard') -> np.ndarray: - """ - deconstructs, thresholds then reconstructs - higher thresholds = less detailed reconstruction - - Only consider haar, db, sym, coif wavelet basis functions, as these are relatively suitable for financial data - """ - import pywt - # Deconstruct - coeff = pywt.wavedec(raw, wavelet, mode=mode) - # Mean absolute deviation of a signal - max_level = pywt.dwt_max_level(len(raw), wavelet) - level = min(level, max_level) - madev = np.mean(np.absolute(coeff[-level] - np.mean(coeff[-level]))) - # The hardcored factor is explained here: https://en.wikipedia.org/wiki/Median_absolute_deviation - sigma = (1 / 0.67449) * madev * smoothing_factor - threshold = sigma * np.sqrt(2 * np.log(len(raw))) - coeff[1:] = (pywt.threshold(i, value=threshold, mode=threshold_mode) for i in coeff[1:]) - signal = pywt.waverec(coeff, wavelet, mode=mode) - if len(signal) > len(raw): - signal = np.delete(signal, -1) - return signal - - def calculate_alpha_beta(returns1: np.ndarray, returns2: np.ndarray) -> tuple: # Add a constant to the independent variable (returns2) X = sm.add_constant(returns2) # Independent variable diff --git a/requirements.txt b/requirements.txt index abd24d60e..8f245a465 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,6 @@ psycopg2-binary~=2.9.9 pydash~=6.0.0 fnc~=0.5.3 pytest~=6.2.5 -PyWavelets~=1.2.0 requests~=2.32.0 scipy~=1.15.0 statsmodels~=0.14.4 diff --git a/tests/test_utils.py b/tests/test_utils.py index e3e8f95c2..3def9ad29 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -176,12 +176,6 @@ def test_combinations_without_repeat(): [3, 1]])) -def test_wavelet_denoising(): - candles = np.array(test_candles_19) - denoised = utils.wavelet_denoising(candles[:, 2], wavelet="sym4", level=1, mode='symmetric', smoothing_factor=2) - assert len(candles) == len(denoised) - - def test_timeframe_to_one_minutes(): assert utils.timeframe_to_one_minutes("1m") == 1 assert utils.timeframe_to_one_minutes("3m") == 3