> *Julius von Hann deserves credit for the window that bears his name—even if autocomplete keeps trying to change it to 'Hamming.' The zero-edge weights aren't a bug; they're the whole point.*
HANMA is a Finite Impulse Response (FIR) filter that applies a Hanning (Hann) window to price data. The Hanning window is a pure raised cosine with edge weights of exactly zero, which provides excellent side lobe suppression while maintaining a narrower main lobe than Hamming. It's particularly effective when you want to eliminate boundary discontinuities entirely.
## Historical Context
Julius von Hann, an Austrian meteorologist, developed this window function in the late 19th century for smoothing meteorological data. The window was later adopted by signal processing engineers and became one of the most widely used window functions in spectral analysis.
The Hanning window is sometimes called "Hann" to avoid confusion with Hamming (a different window with different coefficients). The key distinction: Hanning uses 0.5/0.5 coefficients producing edge weights of exactly zero, while Hamming uses 0.54/0.46 coefficients producing edge weights of 0.08.
In trading applications, HANMA provides smooth output with no boundary artifacts. The zero edge weights mean the first and last samples in the window contribute nothing—a property that eliminates discontinuities when the window slides across the data.
## Architecture & Physics
HANMA is a weighted moving average where weights follow the Hanning function:
* **Center weight of 1.0**: Maximum weight at window center
* **First side lobe at -32 dB**: Good side lobe suppression (vs -13 dB for rectangular/SMA)
* **Narrower main lobe than Hamming**: Better frequency resolution
* **Zero phase distortion**: Symmetric filter means no group delay asymmetry
The 0.5 coefficient on both terms creates a pure raised cosine that touches zero at both endpoints. This is mathematically equivalent to $\sin^2(\pi i / (N-1))$.
### The Compute Challenge
Like other FIR filters, naive implementations recalculate weights on every tick. QuanTAlib precomputes the weight vector $\mathbf{W}$ upon initialization. Runtime becomes a dot product of the price buffer and weight vector.
Choose HANMA when you need zero-edge weights to eliminate boundary discontinuities. Choose HAMMA (Hamming) when you need better side lobe suppression but can tolerate small edge weights.
## Validation
QuanTAlib validates HANMA against its mathematical definition and internal consistency checks.
| Library | Status | Notes |
| :--- | :--- | :--- |
| **QuanTAlib** | ✅ | Validated against math definition. |
| **TA-Lib** | ❌ | Not included in standard C distribution. |
| **Skender** | ❌ | Not included. |
| **Tulip** | ❌ | Not included. |
| **Ooples** | ❌ | Not included. |
## Common Pitfalls
1.**Confusing Hanning and Hamming**: Hanning uses 0.5 coefficient with edge weights of exactly 0.0. Hamming uses 0.54/0.46 with edge weights of 0.08. They're different windows with different properties.
2.**Zero Edge Weights**: The edge weights being exactly zero means the first and last prices in the window are ignored completely. This is intentional—it eliminates boundary discontinuities.
3.**Lag Acceptance**: HANMA has inherent lag of approximately $(L-1)/2$ bars. This is the price of symmetric smoothing. If you need faster response, consider asymmetric windows like ALMA.
4.**Cold Start**: HANMA requires a full window ($L$) to be mathematically valid. First $L-1$ bars are convergence noise.
5.**Small Periods**: With very small periods (e.g., 3), the window shape degenerates. A period of 3 produces weights [0, 1, 0]—essentially just the middle value. Consider period >= 5 for meaningful Hanning characteristics.
6.**Side Lobe Trade-off**: The -32 dB first side lobe is worse than Hamming's -43 dB, but the narrower main lobe provides better frequency resolution. Choose based on whether you prioritize frequency resolution or side lobe suppression.