]> Piment Noir Git Repositories - freqai-strategies.git/commit
perf(quickadapter): eliminate ~15k np.log() recalculations via pure log space (#41)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 12 Jan 2026 15:58:52 +0000 (16:58 +0100)
committerGitHub <noreply@github.com>
Mon, 12 Jan 2026 15:58:52 +0000 (16:58 +0100)
commit80994b167e8c4504236635abd03995558ac94a02
tree66a41dc0c28fb4f1cc5f7dcf46fa31b4fb45f896
parent2912c0cd397b36c0d596be0c193f0ed5683a4b78
perf(quickadapter): eliminate ~15k np.log() recalculations via pure log space (#41)

* 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

* refactor(zigzag): harmonize log variable naming to _log suffix

Rename variables for consistency:
- log_candidate_pivot_close → candidate_pivot_close_log
- log_current_close → current_close_log
- log_slope_close → slope_close_log

All log-space variables now consistently use _log suffix.

* fix: revert incorrect global state usage in zigzag()

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
* refactor: code formatting in zigzag()

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
* refactor: remove redundant variable assignments

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
* chore: bump version to 3.10.11

---------

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py