]> Piment Noir Git Repositories - freqai-strategies.git/commit
perf(zigzag): eliminate ~15k np.log() recalculations via pure log space perf/zigzag-pure-log-space
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 12 Jan 2026 14:53:29 +0000 (15:53 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 12 Jan 2026 14:53:29 +0000 (15:53 +0100)
commit7b71b74a3b4de9043029e967fc564a6ba5c358ed
tree0d4134d4ad96b0ee52049e0cdf92af492e42ca49
parent2912c0cd397b36c0d596be0c193f0ed5683a4b78
perf(zigzag): eliminate ~15k np.log() recalculations via pure log space

Comprehensive optimization of zigzag() function to operate entirely in
logarithmic space, eliminating redundant np.log() recalculations.

**Performance Impact:**
- ~11,000-15,000 fewer np.log() calls per zigzag() execution
- Pre-computation: ~10,000 calls eliminated
- Pure log space conversion: ~1,050-5,100 calls eliminated

**Implementation Changes:**

Utils.py (zigzag function):
- Pre-compute log arrays once: closes_log, highs_log, lows_log (L1195-1199)
- Convert update_candidate_pivot() to accept log values (L1245)
- Convert add_pivot() to accept log values (L1401)
- Convert initial phase to log space (L1531-1569)
- Convert main loop comparisons to log space (L1583-1615)
- Rename top_change_percent() → top_log_return() (L813)
- Rename bottom_change_percent() → bottom_log_return() (L834)
- Convert efficiency ratio calculations to log space (L1343, L1368)

**API Changes:**
- zigzag() now returns pivots_values_log instead of pivots_values
- calculate_pivot_metrics() accepts log values directly

**Callers Updated:**
- QuickAdapterV3.py: Use renamed functions, add TODO comments (L674, L676, L702)
- QuickAdapterRegressorV3.py: Use len(pivots_indices) instead of len(pivots_values) (L3350, L3396)

**Mathematical Correctness:**
- Maintains semantic equivalence via log monotonicity: a > b ⟺ log(a) > log(b)
- Provides symmetric treatment of returns in log space
- All comparisons and calculations mathematically equivalent

**Breaking Changes (Future):**
- Added TODO comments for feature renaming (requires model retraining)
  - %-tcp-period → %-top_log_return-period
  - %-bcp-period → %-bottom_log_return-period
  - %-close_pct_change → %-close_log_return
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py