mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-09 06:27:45 +00:00
61 lines
2.7 KiB
Markdown
61 lines
2.7 KiB
Markdown
# TEMA: Triple Exponential Moving Average
|
|
|
|
> "Patrick Mulloy looked at the lag of an EMA and took it personally. TEMA is what happens when you apply algebra to impatience."
|
|
|
|
The Triple Exponential Moving Average (TEMA) is a lag-reducing filter that combines a single, double, and triple EMA. Unlike a simple triple smoothing (which would be incredibly slow), TEMA uses a weighted combination of the three to cancel out the lag, resulting in an indicator that hugs price action tighter than a spandex cycling short.
|
|
|
|
## Historical Context
|
|
|
|
Introduced by Patrick Mulloy in *Technical Analysis of Stocks & Commodities* (Jan 1994), "Smoothing Data With Less Lag." Mulloy's goal was to replace the standard moving averages in MACD and other indicators to reduce the delay in signal generation.
|
|
|
|
## Architecture & Physics
|
|
|
|
TEMA is not just "EMA applied three times." That would be $EMA(EMA(EMA(x)))$. TEMA is a composite:
|
|
$$ TEMA = 3 \cdot EMA_1 - 3 \cdot EMA_2 + EMA_3 $$
|
|
|
|
This formula effectively projects the trend forward to compensate for the delay inherent in smoothing.
|
|
|
|
### Convergence Speed
|
|
|
|
Because of the aggressive weighting, TEMA converges (warms up) faster than a standard EMA. While an EMA takes $\approx 3.45(N+1)$ steps to converge to 99.9%, TEMA stabilizes quicker due to the subtraction terms canceling out the initial error.
|
|
|
|
## Mathematical Foundation
|
|
|
|
### 1. The Cascade
|
|
|
|
$$ EMA_1 = EMA(Price) $$
|
|
$$ EMA_2 = EMA(EMA_1) $$
|
|
$$ EMA_3 = EMA(EMA_2) $$
|
|
|
|
### 2. The Combination
|
|
|
|
$$ TEMA = (3 \times EMA_1) - (3 \times EMA_2) + EMA_3 $$
|
|
|
|
## Performance Profile
|
|
|
|
| Metric | Score | Notes |
|
|
| :--- | :--- | :--- |
|
|
| **Throughput** | 9 | High; O(1) calculation with 3 EMA steps. |
|
|
| **Allocations** | 0 | Zero-allocation in hot paths. |
|
|
| **Complexity** | O(1) | Constant time regardless of period. |
|
|
| **Accuracy** | 10 | Matches TA-Lib exactly. |
|
|
| **Timeliness** | 10 | Extremely low lag; nearly zero-lag tracking. |
|
|
| **Overshoot** | 8 | Significant overshoot on sharp reversals. |
|
|
| **Smoothness** | 6 | Less smooth than SMA/EMA due to high responsiveness. |
|
|
|
|
## Validation
|
|
|
|
| Library | Status | Notes |
|
|
| :--- | :--- | :--- |
|
|
| **QuanTAlib** | ✅ | Validated. |
|
|
| **TA-Lib** | ✅ | Matches `TA_TEMA` exactly. |
|
|
| **Skender** | ✅ | Matches `GetTema` exactly. |
|
|
| **Tulip** | ✅ | Matches `tema` exactly. |
|
|
| **Ooples** | ❌ | Diverges significantly due to initialization logic. |
|
|
|
|
### Common Pitfalls
|
|
|
|
1. **Overshoot**: TEMA is so responsive it can overshoot price turns, creating a "whiplash" effect in volatile markets.
|
|
2. **Noise**: By reducing lag, TEMA sacrifices some noise suppression. It is "nervous" compared to an SMA.
|
|
3. **Identity Crisis**: Often confused with T3 (Tillson). T3 is a generalized version; TEMA is specifically T3 with $v=1$.
|