Refactor trend detection logic in trend_detector_simple.py by removing the implementation for finding valleys between peaks

This commit is contained in:
Simon Moisy 2025-05-06 16:22:20 +08:00
parent e1f1e7f561
commit 1decd0d0ce

View File

@ -63,39 +63,6 @@ class TrendDetectorSimple:
for peak in min_peaks:
df.at[peak, 'is_min'] = True
# Find consecutive peaks and add the valley in between
if len(max_peaks) >= 2:
for i in range(len(max_peaks) - 1):
start_idx = max_peaks[i]
end_idx = max_peaks[i + 1]
# Find the minimum value between these two peaks
segment = close_prices[start_idx:end_idx + 1]
valley_idx = start_idx + np.argmin(segment)
# Add to min_peaks if not already there
if valley_idx not in min_peaks:
min_peaks = np.append(min_peaks, valley_idx)
df.at[valley_idx, 'is_min'] = True
self.logger.info(f"Added valley at index {valley_idx} between peaks {start_idx} and {end_idx}")
# Find consecutive valleys and add the peak in between
if len(min_peaks) >= 2:
min_peaks = np.sort(min_peaks) # Sort after potential additions
for i in range(len(min_peaks) - 1):
start_idx = min_peaks[i]
end_idx = min_peaks[i + 1]
# Find the maximum value between these two valleys
segment = close_prices[start_idx:end_idx + 1]
peak_idx = start_idx + np.argmax(segment)
# Add to max_peaks if not already there
if peak_idx not in max_peaks:
max_peaks = np.append(max_peaks, peak_idx)
df.at[peak_idx, 'is_max'] = True
self.logger.info(f"Added peak at index {peak_idx} between valleys {start_idx} and {end_idx}")
result = df[['datetime', 'close', 'is_min', 'is_max']]
return result