Add TRAMA implementation and comprehensive tests

- Implemented the TRAMA (Trend Regularity Adaptive Moving Average) class with adaptive EMA logic.
- Added unit tests for TRAMA functionality, including constructor validation, basic calculations, state management, and robustness checks.
- Created validation tests to ensure consistency across different modes of operation (streaming, batch, and static calculations).
- Enhanced documentation for TRAMA, including performance profiles and quality metrics.
- Updated workspace configuration by removing unnecessary folder references.
This commit is contained in:
Miha Kralj
2026-02-21 20:45:38 -08:00
parent 90d5638008
commit 7253f61299
199 changed files with 29577 additions and 234 deletions
+29
View File
@@ -82,6 +82,35 @@ function ABBER(source, ma_line, period, multiplier):
| `lower` | Lower aberration band |
| `avg_dev` | Current average absolute deviation (band half-width before scaling) |
## Performance Profile
### Operation Count (Streaming Mode)
ABBER maintains two running-sum ring buffers (SMA of price and SMA of absolute deviations), each updated in $O(1)$:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (oldest from running sum) | 2 | 1 | 2 |
| ADD (new value to running sum) | 2 | 1 | 2 |
| DIV (sum / count, two SMAs) | 2 | 15 | 30 |
| SUB (price - prevMiddle) | 1 | 1 | 1 |
| ABS (deviation) | 1 | 1 | 1 |
| MUL (multiplier × avgDev) | 1 | 3 | 3 |
| ADD/SUB (middle ± width) | 2 | 1 | 2 |
| **Total (hot)** | **11** | — | **~41 cycles** |
Warmup overhead is negligible: the ring buffer tracks count, adding one CMP per bar until full.
### Batch Mode (SIMD Analysis)
The running-sum SMA is inherently sequential (each bar depends on the previous running sum). SIMD parallelization across bars is not possible for the core SMA path:
| Optimization | Benefit |
| :--- | :--- |
| Band arithmetic (middle ± k × dev) | Vectorizable across output array with `Vector<double>` |
| ABS of deviations | Vectorizable with `Vector.Abs` for batch deviation pass |
| Running-sum maintenance | Sequential; cannot parallelize |
## Resources
- **Pham-Gia, T. & Hung, T.L.** "The Mean and Median Absolute Deviations." *Mathematical and Computer Modelling*, 34(7-8), 2001. (MAD vs. standard deviation theory)
+30
View File
@@ -83,6 +83,36 @@ $$\text{Close}_t > \text{Upper}_t \quad \text{AND} \quad \text{Close}_{t-1} > \t
| `lower` | SMA of adjusted lows (support envelope) |
| `middle` | SMA of close (center line) |
## Performance Profile
### Operation Count (Streaming Mode)
ACCBANDS computes per-bar normalized width, two adjusted prices, and three independent SMA running sums:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| ADD (H + L for denom) | 1 | 1 | 1 |
| SUB (H - L for range) | 1 | 1 | 1 |
| DIV (range / denom for w) | 1 | 15 | 15 |
| MUL (factor × w) | 1 | 3 | 3 |
| MUL (H × (1 + F·w), L × (1 - F·w)) | 2 | 3 | 6 |
| SUB (oldest from 3 running sums) | 3 | 1 | 3 |
| ADD (new value to 3 running sums) | 3 | 1 | 3 |
| DIV (sum / count, three SMAs) | 3 | 15 | 45 |
| **Total (hot)** | **15** | — | **~77 cycles** |
The three DIV operations dominate. When the denominator is zero ($H + L = 0$), a branch sets $w = 0$, adding one CMP.
### Batch Mode (SIMD Analysis)
The three SMA running sums are sequential. The per-bar width computation ($w$, adjusted prices) is independent across bars and vectorizable in a batch pre-pass:
| Optimization | Benefit |
| :--- | :--- |
| Width + adjusted price computation | Vectorizable with `Vector<double>` (ADD, SUB, MUL, DIV) |
| Three SMA running sums | Sequential; cannot parallelize across bars |
| Band output assembly | Trivial; already scalar from SMA |
## Resources
- **Headley, P.** *Big Trends in Trading*. Wiley, 2002. (Original Acceleration Bands specification)
+26
View File
@@ -90,6 +90,32 @@ function APCHANNEL(high, low, alpha):
| `lower` | Exponentially smoothed low (support) |
| `middle` | Arithmetic mean of upper and lower |
## Performance Profile
### Operation Count (Streaming Mode)
APCHANNEL is pure IIR with no buffers. Two independent EMA updates plus a midpoint:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| FMA (decay × Upper + α × H) | 1 | 4 | 4 |
| FMA (decay × Lower + α × L) | 1 | 4 | 4 |
| ADD (Upper + Lower) | 1 | 1 | 1 |
| MUL (× 0.5 for midpoint) | 1 | 3 | 3 |
| **Total (hot)** | **4** | — | **~12 cycles** |
No warmup overhead. First bar initializes directly from input, adding one CMP.
### Batch Mode (SIMD Analysis)
Both EMA recursions are state-dependent ($\text{Upper}_t$ depends on $\text{Upper}_{t-1}$), preventing SIMD parallelization across bars:
| Optimization | Benefit |
| :--- | :--- |
| FMA instructions | Already using 2 FMAs per bar; hardware-accelerated |
| State locality | Upper + Lower fit in 2 registers; zero cache pressure |
| Midpoint computation | Vectorizable in a post-pass across output arrays |
## Resources
- **Wilder, J.W.** *New Concepts in Technical Trading Systems*. Trend Research, 1978. (EMA smoothing foundations)
+40
View File
@@ -113,6 +113,46 @@ function APZ(source, high, low, period, multiplier):
| `upper` | Center + scaled adaptive range (overbought zone) |
| `lower` | Center - scaled adaptive range (oversold zone) |
## Performance Profile
### Operation Count (Streaming Mode)
APZ runs four EMA updates (double-smoothed price + double-smoothed range) plus warmup compensation and band arithmetic:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (H - L for range) | 1 | 1 | 1 |
| FMA (EMA1 price) | 1 | 4 | 4 |
| FMA (EMA2 price → center) | 1 | 4 | 4 |
| FMA (EMA1 range) | 1 | 4 | 4 |
| FMA (EMA2 range → smoothRange) | 1 | 4 | 4 |
| MUL (multiplier × smoothRange) | 1 | 3 | 3 |
| ADD/SUB (center ± width) | 2 | 1 | 2 |
| **Total (hot)** | **8** | — | **~22 cycles** |
During warmup (compensator active):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (e × β²) | 1 | 3 | 3 |
| SUB (1 - e) | 1 | 1 | 1 |
| DIV (center / compensator) | 1 | 15 | 15 |
| DIV (smoothRange / compensator) | 1 | 15 | 15 |
| CMP (e > threshold) | 1 | 1 | 1 |
| **Warmup overhead** | **5** | — | **~35 cycles** |
**Total during warmup:** ~57 cycles/bar; **Post-warmup:** ~22 cycles/bar.
### Batch Mode (SIMD Analysis)
All four EMA recursions are state-dependent, preventing SIMD parallelization across bars:
| Optimization | Benefit |
| :--- | :--- |
| FMA instructions | 4 hardware FMAs per bar; no software emulation |
| State locality | 4 EMA states + compensator fit in registers |
| Band arithmetic | Vectorizable in a post-pass across output arrays |
## Resources
- **Leibfarth, L.** "Trading With An Adaptive Price Zone." *Technical Analysis of Stocks & Commodities*, September 2006. (Original APZ specification)
+42
View File
@@ -91,6 +91,48 @@ function ATRBANDS(source, high, low, close, period, multiplier):
| `upper` | Middle + scaled ATR (volatility-adjusted resistance) |
| `lower` | Middle - scaled ATR (volatility-adjusted support) |
## Performance Profile
### Operation Count (Streaming Mode)
ATRBANDS combines an SMA running sum (center line), True Range computation, and Wilder's RMA with warmup compensation:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (oldest from SMA sum) | 1 | 1 | 1 |
| ADD (new to SMA sum) | 1 | 1 | 1 |
| DIV (SMA = sum / count) | 1 | 15 | 15 |
| SUB (H - L) | 1 | 1 | 1 |
| SUB + ABS (H - prevC, L - prevC) | 2 | 2 | 4 |
| CMP (max of 3 for TR) | 2 | 1 | 2 |
| FMA (RMA: prev×(n-1)/n + TR/n) | 1 | 4 | 4 |
| MUL (multiplier × ATR) | 1 | 3 | 3 |
| ADD/SUB (middle ± width) | 2 | 1 | 2 |
| **Total (hot)** | **12** | — | **~33 cycles** |
During warmup (compensator active):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (e × (1 - α)) | 1 | 3 | 3 |
| SUB (1 - e) | 1 | 1 | 1 |
| DIV (raw_rma / (1 - e)) | 1 | 15 | 15 |
| CMP (e > ε) | 1 | 1 | 1 |
| **Warmup overhead** | **4** | — | **~20 cycles** |
**Total during warmup:** ~53 cycles/bar; **Post-warmup:** ~33 cycles/bar.
### Batch Mode (SIMD Analysis)
The SMA running sum and RMA recursion are both sequential. True Range computation is independent per bar and vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| True Range (3-way max) | Vectorizable with `Vector.Max` and `Vector.Abs` |
| RMA recursion | Sequential (IIR dependency) |
| SMA running sum | Sequential |
| Band arithmetic | Vectorizable in a post-pass |
## Resources
- **Wilder, J.W.** *New Concepts in Technical Trading Systems*. Trend Research, 1978. (Original ATR and Wilder's Smoothing)
+32
View File
@@ -102,6 +102,38 @@ function BBANDS(source, period, multiplier):
| `bandwidth` | $[0, \infty)$ | Normalized volatility; low values signal "squeeze" |
| `percentB` | typically $[0, 1]$ | $> 1$: above upper band; $< 0$: below lower band |
## Performance Profile
### Operation Count (Streaming Mode)
BBANDS maintains running sums of $x$ and $x^2$ via a circular buffer for $O(1)$ mean and variance:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (source² for sumSq) | 1 | 3 | 3 |
| SUB (oldest from sum, sumSq) | 2 | 1 | 2 |
| ADD (new to sum, sumSq) | 2 | 1 | 2 |
| DIV (sum / count for mean) | 1 | 15 | 15 |
| MUL (mean² for variance) | 1 | 3 | 3 |
| DIV (sumSq / count) | 1 | 15 | 15 |
| SUB (sumSq/n - mean²) | 1 | 1 | 1 |
| SQRT (σ from variance) | 1 | 20 | 20 |
| MUL (k × σ) | 1 | 3 | 3 |
| ADD/SUB (middle ± dev) | 2 | 1 | 2 |
| **Total (hot)** | **13** | — | **~66 cycles** |
The SQRT dominates. Derived metrics (%B, BandWidth) add 2 DIV + 2 SUB (~34 cycles) when requested.
### Batch Mode (SIMD Analysis)
The running-sum maintenance is sequential. The variance and SQRT are per-bar and parallelizable in a batch post-pass:
| Optimization | Benefit |
| :--- | :--- |
| Running sum/sumSq | Sequential (sliding window dependency) |
| Variance → SQRT → bands | Vectorizable with `Vector.SquareRoot` across output |
| %B and BandWidth derivations | Vectorizable (element-wise arithmetic) |
## Resources
- **Bollinger, J.** *Bollinger on Bollinger Bands*. McGraw-Hill, 2001. (Definitive reference)
+28
View File
@@ -78,6 +78,34 @@ function DCHANNEL(high, low, period):
| `lower` | Lowest low over the lookback (support) |
| `middle` | Midpoint of channel (trend bias) |
## Performance Profile
### Operation Count (Streaming Mode)
DCHANNEL uses two monotonic deques for $O(1)$ amortized sliding-window max/min:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (expire stale front, max deque) | 1 | 1 | 1 |
| CMP (remove dominated back, max deque) | ~1 avg | 1 | 1 |
| CMP (expire stale front, min deque) | 1 | 1 | 1 |
| CMP (remove dominated back, min deque) | ~1 avg | 1 | 1 |
| ADD (upper + lower) | 1 | 1 | 1 |
| MUL (× 0.5 for middle) | 1 | 3 | 3 |
| **Total (amortized)** | **~6** | — | **~8 cycles** |
Each element enters and exits each deque exactly once over the full series, so worst-case per-bar is $O(n)$ but amortized cost is $O(1)$. Memory: two deques of up to $n$ index entries + two circular buffers of $n$ values.
### Batch Mode (SIMD Analysis)
Monotonic deques are inherently sequential (deque state depends on insertion order). No SIMD parallelization across bars is possible:
| Optimization | Benefit |
| :--- | :--- |
| Deque operations | Sequential; amortized O(1) already optimal |
| Midpoint computation | Vectorizable in a post-pass with `Vector<double>` |
| Memory layout | Circular buffers are cache-friendly for sequential access |
## Resources
- **Donchian, R.** "High Finance in Copper." *Financial Analysts Journal*, 16(6), 1960. (Original channel concept)
+33
View File
@@ -107,6 +107,39 @@ function DECAYCHANNEL(high, low, period):
| `upper` | Decayed high (resistance that fades with time) |
| `lower` | Decayed low (support that fades with time) |
## Performance Profile
### Operation Count (Streaming Mode)
DECAYCHANNEL scans the circular buffer for Donchian bounds ($O(n)$) plus exponential decay computation:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (scan buffer for max, $n$ bars) | $n$ | 1 | $n$ |
| CMP (scan buffer for min, $n$ bars) | $n$ | 1 | $n$ |
| CMP (H ≥ currentMax, snap check) | 1 | 1 | 1 |
| CMP (L ≤ currentMin, snap check) | 1 | 1 | 1 |
| MUL (-λ × age) | 2 | 3 | 6 |
| EXP (e^{-λ·age}, two bands) | 2 | 25 | 50 |
| SUB (1 - exp result) | 2 | 1 | 2 |
| MUL + SUB (decay × distance) | 2 | 4 | 8 |
| ADD (midpoint) | 1 | 1 | 1 |
| MUL (× 0.5) | 1 | 3 | 3 |
| CMP (clamp to Donchian) | 2 | 1 | 2 |
| **Total** | **$2n + 14$** | — | **~$2n + 74$ cycles** |
For period 100: ~274 cycles/bar. The two EXP calls and the $O(n)$ Donchian scan dominate.
### Batch Mode (SIMD Analysis)
The Donchian scan is vectorizable for max/min reduction. The decay computation per bar depends on mutable age counters, limiting parallelism:
| Optimization | Benefit |
| :--- | :--- |
| Donchian max/min scan | Vectorizable with `Vector.Max` / `Vector.Min` reduction |
| EXP computation | Sequential (depends on age state) |
| Decay application + clamping | Sequential (depends on currentMax/Min state) |
## Resources
- **Rutherford, E.** "Radioactive Substances and their Radiations." Cambridge University Press, 1913. (Exponential decay / half-life mathematics)
+28
View File
@@ -86,6 +86,34 @@ function FCB(high, low, period):
| `upper` | Highest confirmed fractal high over lookback (structural resistance) |
| `lower` | Lowest confirmed fractal low over lookback (structural support) |
## Performance Profile
### Operation Count (Streaming Mode)
FCB combines 3-bar fractal detection ($O(1)$) with two monotonic deques for sliding-window max/min of fractal values:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (H[t-1] > H[t-2]) | 1 | 1 | 1 |
| CMP (H[t-1] > H[t]) | 1 | 1 | 1 |
| CMP (L[t-1] < L[t-2]) | 1 | 1 | 1 |
| CMP (L[t-1] < L[t]) | 1 | 1 | 1 |
| Deque ops (max, amortized) | ~2 | 1 | 2 |
| Deque ops (min, amortized) | ~2 | 1 | 2 |
| **Total (amortized)** | **~8** | — | **~8 cycles** |
The fractal detection requires retaining 3 bars of H and L history (6 values). Between fractals, only the deque expiry/push operations execute. Fractal confirmation adds one assignment per detected fractal.
### Batch Mode (SIMD Analysis)
Fractal detection involves comparisons that could theoretically be vectorized, but the conditional fractal-value tracking and deque operations are sequential:
| Optimization | Benefit |
| :--- | :--- |
| Fractal detection (4 comparisons) | Vectorizable with `Vector.GreaterThan` / `Vector.LessThan` |
| Deque max/min maintenance | Sequential (amortized O(1) already optimal) |
| Fractal value persistence | Sequential (conditional state update) |
## Resources
- **Williams, B.** *Trading Chaos*. Wiley, 1995. (Original fractal definition for markets)
+33
View File
@@ -123,6 +123,39 @@ function JBANDS(source, period, phase):
| `upper` | Adaptive upper envelope (snaps up, decays down) |
| `lower` | Adaptive lower envelope (snaps down, decays up) |
## Performance Profile
### Operation Count (Streaming Mode)
JBANDS is the most complex channel indicator, combining snap-and-decay bands, a two-stage volatility estimator, and a 2-pole JMA IIR filter:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB + ABS (local deviation, 2 distances) | 3 | 1 | 3 |
| CMP (max of 2 for dLocal) | 1 | 1 | 1 |
| SMA update (10-bar highD, running sum) | 3 | 1 | 3 |
| Partial sort (128-bar trimmed mean) | ~900 | 1 | ~900 |
| DIV (ratio = distance / dRef) | 2 | 15 | 30 |
| POW (ratio^Pexp) | 2 | 30 | 60 |
| SQRT (√d) | 2 | 20 | 40 |
| POW (sqrtDiv^√d for adapt) | 2 | 30 | 60 |
| MUL + SUB (snap-decay, 2 bands) | 4 | 3 | 12 |
| JMA IIR (3 recursion stages) | ~8 | 4 | 32 |
| **Total** | **~930** | — | **~1141 cycles** |
The 128-element trimmed mean (partial sort) dominates. In practice, the sort operates on a cache-friendly 1 KB buffer, making actual latency lower than raw cycle count suggests. The JMA IIR adds ~32 cycles per bar, comparable to a double-EMA.
### Batch Mode (SIMD Analysis)
The JMA IIR and snap-decay bands are recursive, preventing SIMD parallelization across bars. The trimmed mean sort is $O(n \log n)$ on a fixed 128-element buffer:
| Optimization | Benefit |
| :--- | :--- |
| Trimmed mean | Fixed 128 elements; fits in L1 cache; intrinsics-friendly sort |
| JMA 2-pole IIR | Sequential (3-stage recursion) |
| Snap-and-decay bands | Sequential (conditional state updates) |
| POW/SQRT computations | Hardware-accelerated; no vectorization opportunity |
## Resources
- **Jurik, M.** Jurik Research. (Proprietary JMA specification and band logic)
+42
View File
@@ -100,6 +100,48 @@ function KCHANNEL(source, high, low, close, period, multiplier):
| `upper` | EMA + scaled ATR (dynamic resistance) |
| `lower` | EMA - scaled ATR (dynamic support) |
## Performance Profile
### Operation Count (Streaming Mode)
KCHANNEL combines an EMA with warmup compensation (center), True Range computation, and Wilder's RMA with warmup compensation (ATR):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| FMA (EMA: α×source + (1-α)×prev) | 1 | 4 | 4 |
| FMA (weight accumulator update) | 1 | 4 | 4 |
| DIV (raw / weight for EMA) | 1 | 15 | 15 |
| SUB (H - L) | 1 | 1 | 1 |
| SUB + ABS (H - prevC, L - prevC) | 2 | 2 | 4 |
| CMP (max of 3 for TR) | 2 | 1 | 2 |
| FMA (RMA: prev×(n-1)/n + TR/n) | 1 | 4 | 4 |
| MUL (multiplier × ATR) | 1 | 3 | 3 |
| ADD/SUB (EMA ± width) | 2 | 1 | 2 |
| **Total (hot)** | **12** | — | **~39 cycles** |
During warmup (RMA compensator active):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (e × (1 - α)) | 1 | 3 | 3 |
| SUB (1 - e) | 1 | 1 | 1 |
| DIV (raw_rma / (1 - e)) | 1 | 15 | 15 |
| CMP (e > ε) | 1 | 1 | 1 |
| **Warmup overhead** | **4** | — | **~20 cycles** |
**Total during warmup:** ~59 cycles/bar; **Post-warmup:** ~39 cycles/bar.
### Batch Mode (SIMD Analysis)
All IIR recursions (EMA, RMA) are state-dependent, preventing SIMD parallelization across bars:
| Optimization | Benefit |
| :--- | :--- |
| FMA instructions | 3 hardware FMAs per bar |
| True Range computation | Vectorizable in a batch pre-pass |
| Band arithmetic | Vectorizable in a post-pass |
| No buffers | Zero allocation; all state fits in registers |
## Resources
- **Keltner, C.** *How to Make Money in Commodities*. 1960. (Original channel concept)
+40
View File
@@ -82,6 +82,46 @@ function MAENV(source, period, percentage, ma_type):
| `upper` | MA + fixed percentage (overbought threshold) |
| `lower` | MA - fixed percentage (oversold threshold) |
## Performance Profile
### Operation Count (Streaming Mode)
MAENV complexity depends on the MA type. Band arithmetic is identical for all three:
**SMA mode** (type = 0):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (oldest from running sum) | 1 | 1 | 1 |
| ADD (new to running sum) | 1 | 1 | 1 |
| DIV (sum / count for SMA) | 1 | 15 | 15 |
| MUL (middle × pct/100) | 1 | 3 | 3 |
| ADD/SUB (middle ± distance) | 2 | 1 | 2 |
| **Total (SMA, hot)** | **6** | — | **~22 cycles** |
**EMA mode** (type = 1):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| FMA (EMA update) | 1 | 4 | 4 |
| FMA (weight accumulator) | 1 | 4 | 4 |
| DIV (raw / weight) | 1 | 15 | 15 |
| MUL (middle × pct/100) | 1 | 3 | 3 |
| ADD/SUB (middle ± distance) | 2 | 1 | 2 |
| **Total (EMA, hot)** | **6** | — | **~28 cycles** |
**WMA mode** (type = 2): $O(n)$ weighted sum per bar, ~$4n + 20$ cycles.
### Batch Mode (SIMD Analysis)
SMA and EMA modes are sequential (running sum or IIR dependency). Band arithmetic is vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| Band arithmetic (middle × pct ± dist) | Vectorizable with `Vector<double>` in batch post-pass |
| SMA running sum / EMA recursion | Sequential |
| WMA weighted sum | Partially vectorizable with `Vector.Multiply` + reduction |
## Resources
- **Murphy, J.J.** *Technical Analysis of the Financial Markets*. New York Institute of Finance, 1999. (Moving average envelope fundamentals)
+26
View File
@@ -87,6 +87,32 @@ Each element is pushed to the deque exactly once and popped at most once (either
| $U_t - L_t$ contracting | Consolidation; range tightening |
| $U_t - L_t$ expanding | Volatility expansion; breakout potential |
## Performance Profile
### Operation Count (Streaming Mode)
MMCHANNEL uses two monotonic deques for $O(1)$ amortized sliding-window max/min with no midpoint calculation:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (expire stale front, max deque) | 1 | 1 | 1 |
| CMP (remove dominated back, max deque) | ~1 avg | 1 | 1 |
| CMP (expire stale front, min deque) | 1 | 1 | 1 |
| CMP (remove dominated back, min deque) | ~1 avg | 1 | 1 |
| **Total (amortized)** | **~4** | — | **~4 cycles** |
MMCHANNEL is the lightest channel indicator — no midpoint computation, no band arithmetic. Each element enters and exits each deque exactly once over the full series.
### Batch Mode (SIMD Analysis)
Monotonic deques are inherently sequential. No SIMD parallelization across bars is possible:
| Optimization | Benefit |
| :--- | :--- |
| Deque operations | Sequential; amortized O(1) already optimal |
| No midpoint/band math | Nothing to vectorize in a post-pass |
| Memory layout | Circular buffers are cache-friendly for sequential access |
## Resources
- Donchian, R. (1960). "High Finance in Copper." *Financial Analysts Journal*, 16(6).
+28
View File
@@ -108,6 +108,34 @@ function pchannel(high[], low[], period):
| $U_t - L_t$ contracting | Consolidation; range tightening |
| $U_t - L_t$ expanding | Volatility expansion |
## Performance Profile
### Operation Count (Streaming Mode)
PCHANNEL uses two monotonic deques for $O(1)$ amortized sliding-window max/min plus a midpoint:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (expire stale front, max deque) | 1 | 1 | 1 |
| CMP (remove dominated back, max deque) | ~1 avg | 1 | 1 |
| CMP (expire stale front, min deque) | 1 | 1 | 1 |
| CMP (remove dominated back, min deque) | ~1 avg | 1 | 1 |
| ADD (upper + lower) | 1 | 1 | 1 |
| MUL (× 0.5 for middle) | 1 | 3 | 3 |
| **Total (amortized)** | **~6** | — | **~8 cycles** |
Identical to DCHANNEL in cost. Each element enters and exits each deque exactly once over the full series, yielding $O(N)$ total work across $N$ bars regardless of period.
### Batch Mode (SIMD Analysis)
Monotonic deques are inherently sequential. No SIMD parallelization across bars is possible:
| Optimization | Benefit |
| :--- | :--- |
| Deque operations | Sequential; amortized O(1) already optimal |
| Midpoint computation | Vectorizable in a post-pass with `Vector<double>` |
| Memory layout | Two circular buffers + two deques; cache-friendly |
## Resources
- Donchian, R. (1960). "High Finance in Copper." *Financial Analysts Journal*.
+32
View File
@@ -135,6 +135,38 @@ function regchannel(source[], period, multiplier):
| Price at lower band | Overextended below trend |
| Band width expanding | Increasing residual dispersion; trend becoming noisy |
## Performance Profile
### Operation Count (Streaming Mode)
REGCHANNEL requires two $O(n)$ passes per bar: one for regression sums, one for residual standard deviation:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| ADD (sum_y accumulation, pass 1) | $n$ | 1 | $n$ |
| FMA (i × y for sum_xy, pass 1) | $n$ | 4 | $4n$ |
| MUL + DIV (slope, intercept) | 4 | ~9 | 36 |
| FMA (slope × i + intercept, pass 2) | $n$ | 4 | $4n$ |
| SUB (residual = y - predicted) | $n$ | 1 | $n$ |
| MUL (residual², pass 2) | $n$ | 3 | $3n$ |
| ADD (ssr accumulation, pass 2) | $n$ | 1 | $n$ |
| DIV (ssr / n) | 1 | 15 | 15 |
| SQRT (σ) | 1 | 20 | 20 |
| MUL + ADD/SUB (bands) | 3 | ~5 | 15 |
| **Total** | **~$7n + 9$** | — | **~$14n + 86$ cycles** |
For period 20: ~366 cycles/bar. The two window scans dominate. Index sums $\sum x$ and $\sum x^2$ are precomputed constants.
### Batch Mode (SIMD Analysis)
Both passes iterate over a contiguous ring buffer, making them prime candidates for SIMD vectorization:
| Operation | Scalar Ops | SIMD Ops (AVX-512) | Speedup |
| :--- | :---: | :---: | :---: |
| Pass 1: sum_y, sum_xy | $2n$ | $n/8$ | ~16× |
| Pass 2: residuals + squared sum | $4n$ | $n/2$ | ~8× |
| Slope/intercept/bands | 9 | 9 | 1× |
## Resources
- Raff, G. (1991). "Trading the Regression Channel." *Technical Analysis of Stocks & Commodities*.
+32
View File
@@ -138,6 +138,38 @@ function sdchannel(source[], period, multiplier):
| $\sigma \to 0$ | Perfect linear trend; bands collapse |
| Band width expanding | Increasing noise around the trend |
## Performance Profile
### Operation Count (Streaming Mode)
SDCHANNEL is algorithmically identical to REGCHANNEL — two $O(n)$ passes per bar:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| ADD (sum_y accumulation, pass 1) | $n$ | 1 | $n$ |
| FMA (i × y for sum_xy, pass 1) | $n$ | 4 | $4n$ |
| MUL + DIV (slope, intercept) | 4 | ~9 | 36 |
| FMA (slope × i + intercept, pass 2) | $n$ | 4 | $4n$ |
| SUB (residual = y - predicted) | $n$ | 1 | $n$ |
| MUL (residual², pass 2) | $n$ | 3 | $3n$ |
| ADD (ssr accumulation, pass 2) | $n$ | 1 | $n$ |
| DIV (ssr / n) | 1 | 15 | 15 |
| SQRT (σ) | 1 | 20 | 20 |
| MUL + ADD/SUB (bands) | 3 | ~5 | 15 |
| **Total** | **~$7n + 9$** | — | **~$14n + 86$ cycles** |
For period 20: ~366 cycles/bar. Identical performance characteristics to REGCHANNEL.
### Batch Mode (SIMD Analysis)
Both passes iterate over contiguous memory, enabling SIMD vectorization of the inner loops:
| Operation | Scalar Ops | SIMD Ops (AVX-512) | Speedup |
| :--- | :---: | :---: | :---: |
| Pass 1: sum_y, sum_xy | $2n$ | $n/8$ | ~16× |
| Pass 2: residuals + squared sum | $4n$ | $n/2$ | ~8× |
| Slope/intercept/bands | 9 | 9 | 1× |
## Resources
- Raff, G. (1991). "Trading the Regression Channel." *Technical Analysis of Stocks & Commodities*.
+42
View File
@@ -129,6 +129,48 @@ function starchannel(source[], high[], low[], close[], period, multiplier, atr_l
| Price at lower band | Overextended below SMA by ATR measure |
| Middle band slope positive | SMA trending upward |
## Performance Profile
### Operation Count (Streaming Mode)
STARCHANNEL combines an SMA running sum (center), True Range, and Wilder's RMA with warmup compensation — identical cost to ATRBANDS:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (oldest from SMA sum) | 1 | 1 | 1 |
| ADD (new to SMA sum) | 1 | 1 | 1 |
| DIV (SMA = sum / count) | 1 | 15 | 15 |
| SUB (H - L) | 1 | 1 | 1 |
| SUB + ABS (H - prevC, L - prevC) | 2 | 2 | 4 |
| CMP (max of 3 for TR) | 2 | 1 | 2 |
| FMA (RMA: prev×(n-1)/n + TR/n) | 1 | 4 | 4 |
| MUL (multiplier × ATR) | 1 | 3 | 3 |
| ADD/SUB (middle ± width) | 2 | 1 | 2 |
| **Total (hot)** | **12** | — | **~33 cycles** |
During warmup (RMA compensator active):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (e × (1 - α)) | 1 | 3 | 3 |
| SUB (1 - e) | 1 | 1 | 1 |
| DIV (raw_rma / (1 - e)) | 1 | 15 | 15 |
| CMP (e > ε) | 1 | 1 | 1 |
| **Warmup overhead** | **4** | — | **~20 cycles** |
**Total during warmup:** ~53 cycles/bar; **Post-warmup:** ~33 cycles/bar.
### Batch Mode (SIMD Analysis)
The SMA running sum and RMA recursion are sequential. True Range computation is independent per bar:
| Optimization | Benefit |
| :--- | :--- |
| True Range (3-way max) | Vectorizable with `Vector.Max` and `Vector.Abs` |
| RMA recursion | Sequential (IIR dependency) |
| SMA running sum | Sequential |
| Band arithmetic | Vectorizable in a post-pass |
## Resources
- Stoller, M. (1980s). Development of the Stoller Average Range Channel.
+36
View File
@@ -170,6 +170,42 @@ function stbands(high[], low[], close[], period, multiplier):
| Trend flip $-1 \to +1$ | Bullish reversal; price breached lower band |
| Band width contracting | ATR falling; volatility decreasing |
## Performance Profile
### Operation Count (Streaming Mode)
STBANDS computes True Range, an SMA of TR via running sum, basic band math from HL2, ratchet logic, and trend determination:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| SUB (H - L) | 1 | 1 | 1 |
| SUB + ABS (H - prevC, L - prevC) | 2 | 2 | 4 |
| CMP (max of 3 for TR) | 2 | 1 | 2 |
| SUB (oldest from TR sum) | 1 | 1 | 1 |
| ADD (new to TR sum) | 1 | 1 | 1 |
| DIV (TR sum / count for ATR) | 1 | 15 | 15 |
| ADD (H + L for HL2) | 1 | 1 | 1 |
| MUL (× 0.5 for HL2) | 1 | 3 | 3 |
| MUL (k × ATR) | 1 | 3 | 3 |
| ADD/SUB (HL2 ± k·ATR) | 2 | 1 | 2 |
| CMP (ratchet: upper tightens?) | 2 | 1 | 2 |
| CMP (ratchet: lower tightens?) | 2 | 1 | 2 |
| CMP (trend: close vs bands) | 2 | 1 | 2 |
| **Total (hot)** | **19** | — | **~39 cycles** |
The ratchet logic is pure comparisons with no expensive math. The DIV for ATR is the costliest single operation.
### Batch Mode (SIMD Analysis)
The ATR running sum and ratchet logic are both sequential (state-dependent). True Range and basic band computation are vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| True Range (3-way max) | Vectorizable with `Vector.Max` and `Vector.Abs` |
| HL2 + basic bands | Vectorizable in a batch pre-pass |
| ATR running sum | Sequential |
| Ratchet logic + trend | Sequential (conditional state) |
## Resources
- Seban, O. SuperTrend Indicator methodology.
+33
View File
@@ -129,6 +129,39 @@ function ttm_lrc(source[], period, deviations):
| $-2\sigma$ to $-1\sigma$ | ~13.5% | Oversold |
| Below $-2\sigma$ | ~2.5% | Extremely oversold relative to trend |
## Performance Profile
### Operation Count (Streaming Mode)
TTM_LRC extends REGCHANNEL with dual bands and $R^2$ computation. Two $O(n)$ passes plus additional statistics:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| ADD (sum_y accumulation, pass 1) | $n$ | 1 | $n$ |
| FMA (i × y for sum_xy, pass 1) | $n$ | 4 | $4n$ |
| MUL + DIV (slope, intercept, mean_y) | 5 | ~9 | 45 |
| FMA (slope × i + intercept, pass 2) | $n$ | 4 | $4n$ |
| SUB (residual, pass 2) | $n$ | 1 | $n$ |
| MUL (residual², pass 2) | $n$ | 3 | $3n$ |
| ADD (ssr accumulation, pass 2) | $n$ | 1 | $n$ |
| SUB + MUL + ADD (sst, pass 2) | $2n$ | 2 | $4n$ |
| DIV (ssr/n, sst check, R²) | 3 | 15 | 45 |
| SQRT (σ) | 1 | 20 | 20 |
| MUL + ADD/SUB (4 bands: ±1σ, ±kσ) | 6 | ~2 | 12 |
| **Total** | **~$9n + 15$** | — | **~$18n + 122$ cycles** |
For period 100: ~1922 cycles/bar. The longer default period (100 vs 20) makes the window scans significantly more expensive than REGCHANNEL.
### Batch Mode (SIMD Analysis)
Both passes iterate over contiguous ring buffer memory, enabling SIMD vectorization:
| Operation | Scalar Ops | SIMD Ops (AVX-512) | Speedup |
| :--- | :---: | :---: | :---: |
| Pass 1: sum_y, sum_xy | $2n$ | $n/8$ | ~16× |
| Pass 2: residuals + ssr + sst | $6n$ | $3n/4$ | ~8× |
| Slope/intercept/bands/R² | 15 | 15 | 1× |
## Resources
- Carter, J. (2005). *Mastering the Trade*. McGraw-Hill.
+31
View File
@@ -146,6 +146,37 @@ Standard deviation measures dispersion around the mean: $\sigma = \sqrt{E[(X - \
| Price at upper band | High-frequency component is large positive |
| Price at lower band | High-frequency component is large negative |
## Performance Profile
### Operation Count (Streaming Mode)
UBANDS combines an $O(1)$ USF IIR recursion (center line) with an $O(n)$ RMS scan (band width):
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL + ADD (USF coefficients, 4 terms) | 4 | 4 | 16 |
| ADD (USF: 2 feedback + 3 feedforward) | 5 | 1 | 5 |
| SUB (residual = source - USF) | 1 | 1 | 1 |
| MUL (residual² for RMS buffer) | 1 | 3 | 3 |
| ADD (sum of squared residuals, $n$) | $n$ | 1 | $n$ |
| DIV (sumSq / count) | 1 | 15 | 15 |
| SQRT (RMS) | 1 | 20 | 20 |
| MUL (k × RMS) | 1 | 3 | 3 |
| ADD/SUB (USF ± width) | 2 | 1 | 2 |
| **Total** | **~$n + 16$** | — | **~$n + 65$ cycles** |
For period 20: ~85 cycles/bar. The USF recursion is fast ($\sim$21 cycles); the RMS window scan at $O(n)$ dominates.
### Batch Mode (SIMD Analysis)
The USF is recursive (IIR dependency). The RMS scan over squared residuals is vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| USF 2-pole IIR | Sequential; 5 multiply-adds per bar |
| RMS accumulation (sum of r²) | Vectorizable with `Vector.Multiply` + horizontal sum |
| Band arithmetic | Vectorizable in a post-pass |
## Resources
- Ehlers, J. F. (2024). "Ultimate Bands." *Technical Analysis of Stocks & Commodities*.
+32
View File
@@ -160,6 +160,38 @@ function uchannel(close[], high[], low[], strPeriod, centerPeriod, multiplier):
| Band width contracting | Volatility compression |
| Price beyond upper | Extreme positive deviation from USF trend |
## Performance Profile
### Operation Count (Streaming Mode)
UCHANNEL runs two independent USF IIR recursions (one for close, one for True Range) plus True Range and band arithmetic — all $O(1)$:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| CMP (max(H, prevC) for TR) | 1 | 1 | 1 |
| CMP (min(L, prevC) for TR) | 1 | 1 | 1 |
| SUB (TH - TL for TR) | 1 | 1 | 1 |
| MUL + ADD (USF center, 4 terms) | 4 | 4 | 16 |
| ADD (USF center feedback, 5 terms) | 5 | 1 | 5 |
| MUL + ADD (USF STR, 4 terms) | 4 | 4 | 16 |
| ADD (USF STR feedback, 5 terms) | 5 | 1 | 5 |
| MUL (k × STR) | 1 | 3 | 3 |
| ADD/SUB (center ± width) | 2 | 1 | 2 |
| **Total (hot)** | **24** | — | **~50 cycles** |
No buffers, no window scans. All state fits in ~200 bytes (two USF 2-element histories + metadata). This is the fastest ATR-class channel indicator.
### Batch Mode (SIMD Analysis)
Both USF recursions are IIR-dependent, preventing SIMD parallelization across bars:
| Optimization | Benefit |
| :--- | :--- |
| USF IIR (2 instances) | Sequential; ~21 cycles each per bar |
| True Range computation | Vectorizable in a batch pre-pass |
| Band arithmetic | Vectorizable in a post-pass |
| No allocations | Zero heap allocation; all state in registers/stack |
## Resources
- Ehlers, J. F. (2024). "Ultimate Channel." *Technical Analysis of Stocks & Commodities*.
+32
View File
@@ -129,6 +129,38 @@ function vwapbands(source[], volume[], reset[], multiplier):
| $\sigma$ increasing | Volume-weighted dispersion growing |
| Bands expanding | Intraday volatility increasing |
## Performance Profile
### Operation Count (Streaming Mode)
VWAPBANDS maintains three cumulative running sums plus variance computation and dual band construction — all $O(1)$:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (price × vol for sum_pv) | 1 | 3 | 3 |
| MUL (price² × vol for sum_pv2) | 2 | 3 | 6 |
| ADD (3 running sums) | 3 | 1 | 3 |
| DIV (sum_pv / sum_vol for VWAP) | 1 | 15 | 15 |
| DIV (sum_pv2 / sum_vol for E[X²]) | 1 | 15 | 15 |
| MUL (VWAP² for variance) | 1 | 3 | 3 |
| SUB (E[X²] - VWAP²) | 1 | 1 | 1 |
| SQRT (σ) | 1 | 20 | 20 |
| MUL (k × σ, 2k × σ) | 2 | 3 | 6 |
| ADD/SUB (VWAP ± 1σ, ± 2σ, 4 bands) | 4 | 1 | 4 |
| **Total (hot)** | **17** | — | **~76 cycles** |
Session reset adds a CMP per bar. The two DIV operations and SQRT dominate. No buffers required — purely cumulative sums.
### Batch Mode (SIMD Analysis)
Cumulative sums are inherently sequential. Band arithmetic is vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| Running sum accumulation | Sequential (prefix sum dependency) |
| Variance → SQRT → bands | Vectorizable in a batch post-pass |
| Session reset detection | Sequential (comparison per bar) |
## Resources
- Berkowitz, S., Logue, D. & Noser, E. (1988). "The Total Cost of Transactions on the NYSE." *The Journal of Finance*, 43(1), 97112.
+32
View File
@@ -122,6 +122,38 @@ function vwapsd(source[], volume[], reset[], numDevs):
| Band width expanding | Intraday volume-weighted dispersion increasing |
| Band width near zero | Very tight price clustering around VWAP |
## Performance Profile
### Operation Count (Streaming Mode)
VWAPSD is slightly simpler than VWAPBANDS (one band pair instead of two), with identical VWAP and variance computation:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| MUL (price × vol for sum_pv) | 1 | 3 | 3 |
| MUL (price² × vol for sum_pv2) | 2 | 3 | 6 |
| ADD (3 running sums) | 3 | 1 | 3 |
| DIV (sum_pv / sum_vol for VWAP) | 1 | 15 | 15 |
| DIV (sum_pv2 / sum_vol for E[X²]) | 1 | 15 | 15 |
| MUL (VWAP² for variance) | 1 | 3 | 3 |
| SUB (E[X²] - VWAP²) | 1 | 1 | 1 |
| SQRT (σ) | 1 | 20 | 20 |
| MUL (k × σ) | 1 | 3 | 3 |
| ADD/SUB (VWAP ± k·σ) | 2 | 1 | 2 |
| **Total (hot)** | **14** | — | **~71 cycles** |
Saves ~5 cycles vs VWAPBANDS by emitting 2 bands instead of 4. Session reset adds one CMP per bar.
### Batch Mode (SIMD Analysis)
Cumulative sums are inherently sequential. Band arithmetic is vectorizable:
| Optimization | Benefit |
| :--- | :--- |
| Running sum accumulation | Sequential (prefix sum dependency) |
| Variance → SQRT → bands | Vectorizable in a batch post-pass |
| Session reset detection | Sequential (comparison per bar) |
## Resources
- Berkowitz, S., Logue, D. & Noser, E. (1988). "The Total Cost of Transactions on the NYSE." *The Journal of Finance*, 43(1), 97112.