mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 21:48:03 +00:00
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:
@@ -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*.
|
||||
|
||||
Reference in New Issue
Block a user