Skip to content

Commit bcece70

Browse files
committed
Cycle Of min max
1 parent f07a68e commit bcece70

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎gpu_wavelet_gpu_console.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,29 @@ def normalize(data):
997997
detail_mean_abs = np.abs(detail_data).mean()
998998
zero_crossings = np.sum(np.diff(np.sign(detail_data)) != 0)
999999

1000+
# Find local minima and maxima for period calculation
1001+
from scipy.signal import find_peaks
1002+
1003+
# Find minima (peaks in negative signal)
1004+
minima_indices, _ = find_peaks(-detail_data)
1005+
# Find maxima (peaks in positive signal)
1006+
maxima_indices, _ = find_peaks(detail_data)
1007+
1008+
# Calculate average periods
1009+
if len(minima_indices) > 1:
1010+
min_periods = np.diff(minima_indices)
1011+
avg_min_period = min_periods.mean()
1012+
avg_min_period_hours = avg_min_period * (2 ** (i + 1)) # Account for downsampling
1013+
else:
1014+
avg_min_period_hours = 0
1015+
1016+
if len(maxima_indices) > 1:
1017+
max_periods = np.diff(maxima_indices)
1018+
avg_max_period = max_periods.mean()
1019+
avg_max_period_hours = avg_max_period * (2 ** (i + 1)) # Account for downsampling
1020+
else:
1021+
avg_max_period_hours = 0
1022+
10001023
# Interpolate to original length (150 points for display)
10011024
display_length = min(150, len(prices))
10021025
if len(detail_data) < display_length:
@@ -1011,7 +1034,8 @@ def normalize(data):
10111034
plot_ascii(interpolated, height=8, width=70,
10121035
title=f"Level {i+1} Detail - {freq_bands}")
10131036
print(f" Stats: σ=${detail_std:.2f}, Mean|Δ|=${detail_mean_abs:.2f}, "
1014-
f"Zero-crossings={zero_crossings} (higher=more oscillations)\n")
1037+
f"Zero-crossings={zero_crossings} (higher=more oscillations)")
1038+
print(f" Period: Min→Min={avg_min_period_hours:.1f}h, Max→Max={avg_max_period_hours:.1f}h\n")
10151039

10161040
# =============================================================================
10171041
# STEP 10: TRADING SIGNAL GENERATION

‎gpu_wavelet_gpu_plot.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,27 @@ def gpu_convolve(signal, filter_coeffs, kernel, mode='symmetric'):
545545
# Zero-crossings indicate oscillation frequency
546546
zero_crossings = np.sum(np.diff(np.sign(current_detail_interp)) != 0)
547547

548+
# Find local minima and maxima for period calculation
549+
from scipy.signal import find_peaks
550+
551+
# Use original detail data (before interpolation) for accurate period calculation
552+
minima_indices, _ = find_peaks(-current_detail)
553+
maxima_indices, _ = find_peaks(current_detail)
554+
555+
# Calculate average periods (in hours, accounting for downsampling)
556+
downsample_factor = 2 ** (i + 1)
557+
if len(minima_indices) > 1:
558+
min_periods = np.diff(minima_indices)
559+
avg_min_period_hours = min_periods.mean() * downsample_factor
560+
else:
561+
avg_min_period_hours = 0
562+
563+
if len(maxima_indices) > 1:
564+
max_periods = np.diff(maxima_indices)
565+
avg_max_period_hours = max_periods.mean() * downsample_factor
566+
else:
567+
avg_max_period_hours = 0
568+
548569
# Title with comprehensive info
549570
ax_detail.set_title(f'Band {i+1}: {freq_bands[i][0]} - {freq_bands[i][2]}',
550571
fontsize=12, fontweight='bold', pad=10)
@@ -554,7 +575,7 @@ def gpu_convolve(signal, filter_coeffs, kernel, mode='symmetric'):
554575

555576
# Enhanced stats box showing frequency characteristics
556577
ax_detail.text(0.02, 0.97,
557-
f'σ: ${detail_std:.1f}\nMean|Δ|: ${detail_mean_abs:.1f}\nRange: ${detail_range:.1f}\nZero-crossings: {zero_crossings}\n{freq_bands[i][1]}',
578+
f'σ: ${detail_std:.1f}\nMean|Δ|: ${detail_mean_abs:.1f}\nRange: ${detail_range:.1f}\nZero-crossings: {zero_crossings}\nMin→Min: {avg_min_period_hours:.1f}h\nMax→Max: {avg_max_period_hours:.1f}h\n{freq_bands[i][1]}',
558579
transform=ax_detail.transAxes, fontsize=8, verticalalignment='top',
559580
bbox=dict(boxstyle='round', facecolor='lightblue', alpha=0.7))
560581

0 commit comments

Comments
 (0)