mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 13:58:04 +00:00
75 lines
3.3 KiB
Markdown
75 lines
3.3 KiB
Markdown
# AroonOsc: Aroon Oscillator
|
|
|
|
> Tushar Chande's Aroon system is a dual-line argument. The Oscillator is the verdict.
|
|
|
|
The Aroon Oscillator condenses the struggle between the "Aroon Up" and "Aroon Down" lines into a single, normalized value. It quantifies not just the existence of a trend, but its freshness. It answers the question: "Are we making new highs faster than we are making new lows?"
|
|
|
|
## The 1995 Standard
|
|
|
|
Introduced by Tushar Chande in *The New Technical Trader* (1995), the Aroon system was a departure from price-based momentum. It focused on *time*. While RSI asks "how much did price move?", Aroon asks "how long has it been since the last extreme?". The Oscillator is simply the arithmetic difference between the two, providing a zero-centered metric for trend bias.
|
|
|
|
## Architecture & Physics
|
|
|
|
The physics of Aroon are temporal, not spatial. It measures the decay of "recency."
|
|
|
|
1. **Time Measurement**: We count the bars since the highest high and lowest low within the period.
|
|
2. **Normalization**: These counts are converted to a 0-100 scale (100 = happened right now, 0 = happened `Period` bars ago).
|
|
3. **Differential**: The Oscillator is `Up - Down`.
|
|
|
|
### The Drift Resistance
|
|
|
|
Unlike recursive indicators (EMA, RSI) which accumulate floating-point errors over time, Aroon is stateless in the long term. Its value depends *only* on the data within the lookback window. This makes it mathematically robust and immune to "poisoning" from bad data in the distant past.
|
|
|
|
### Zero-Allocation Design
|
|
|
|
The implementation avoids the naive approach of scanning the entire window on every update. Instead, it maintains a circular buffer (`RingBuffer`) of the last `Period + 1` highs and lows.
|
|
|
|
- **Hot Path**: The `Update` method uses stack-based logic.
|
|
- **Memory**: Fixed footprint (two ring buffers of size `Period + 1`).
|
|
- **Allocations**: Zero heap allocations during streaming updates.
|
|
|
|
## Mathematical Foundation
|
|
|
|
The math is purely arithmetic.
|
|
|
|
### 1. Aroon Up
|
|
|
|
$$
|
|
\text{AroonUp} = \frac{\text{Period} - \text{Days Since High}}{\text{Period}} \times 100
|
|
$$
|
|
|
|
### 2. Aroon Down
|
|
|
|
$$
|
|
\text{AroonDown} = \frac{\text{Period} - \text{Days Since Low}}{\text{Period}} \times 100
|
|
$$
|
|
|
|
### 3. The Oscillator
|
|
|
|
$$
|
|
\text{AroonOsc} = \text{AroonUp} - \text{AroonDown}
|
|
$$
|
|
|
|
## Performance Profile
|
|
|
|
The algorithm is $O(N)$ where $N$ is the period, as we must scan the window for extremes. However, for typical periods (14-25), this is negligible.
|
|
|
|
| Metric | Complexity | Notes |
|
|
| :--- | :--- | :--- |
|
|
| **Throughput** | ~10ns / bar | Dependent on Period length |
|
|
| **Allocations** | 0 bytes | Hot path is allocation-free |
|
|
| **Complexity** | O(Period) | Linear scan of the lookback window |
|
|
| **Precision** | `double` | Standard floating-point precision |
|
|
|
|
## Validation
|
|
|
|
We validate against **TA-Lib** and **Tushar Chande's original examples**.
|
|
|
|
- **Consistency**: Matches TA-Lib outputs exactly.
|
|
- **Edge Cases**: Handles flat markets (where high/low are unchanged) correctly by prioritizing the *most recent* extreme.
|
|
|
|
### Common Pitfalls
|
|
|
|
- **Lag**: Because it looks back `Period` bars, it will not signal a reversal until the previous extreme "ages out" or is superseded. It is a lagging indicator of trend changes.
|
|
- **Flatlining**: In strong trends, the oscillator can peg at +100 or -100 for extended periods. This is a feature, not a bug—it indicates a "fresh" extreme on every bar.
|