Skip to content

Commit

Permalink
Remove wavelet denoising function and related tests; update requirements
Browse files Browse the repository at this point in the history
- Deleted the `wavelet_denoising` function from `jesse/utils.py`, which was designed for signal processing using wavelet transforms.
- Removed the corresponding test case from `tests/test_utils.py` to reflect the function's removal.
- Updated `requirements.txt` to exclude the `PyWavelets` dependency, as it is no longer needed.
- These changes streamline the codebase by eliminating unused functionality and dependencies.
  • Loading branch information
saleh-mir committed Jan 4, 2025
1 parent 8af2dda commit a00dc84
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 32 deletions.
25 changes: 0 additions & 25 deletions jesse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a00dc84

Please sign in to comment.