HammingMovingAverage — Hamming Moving Average
תוכן זה אינו זמין עדיין בשפה שלך.
A cosine-tapered weighted average. The Hamming window drops the weight at both edges, so a bar enters and leaves the average gently instead of falling off a cliff — less edge ringing than a WMA or SMA of the same length.
Signature
HammingMovingAverage(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Window. Default 20, bounds 1–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ w_i = 0.54 - 0.46\cos!\left(\frac{2\pi i}{n-1}\right), \quad \text{HMA}_{\text{Hamming}} = \frac{\sum_i w_i C_i}{\sum_i w_i} $$
Warmup
period bars; during the lead-in the window is built over the bars available.
Reading the value
ham.valueham.crossed_above(other)Example
class HammingBaseline(Strategy): """A smooth, symmetric baseline with soft window edges.""" trade = Symbol() sizing = FixedCapital()
def execute(self): ham = HammingMovingAverage(20, on=self.trade) if self.trade.close > ham.value and self.trade.is_flat: self.buy(self.trade, reason="Above Hamming MA") if self.trade.close < ham.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Below Hamming MA")Notes
- The Hamming window from signal processing, applied as price weights.
- Symmetric like
TRIMA, so it lags by roughly half the window — not a low-lag average, and not related to Hull’sHMAdespite the name collision. - Proven by an assert-via-trade run on SPY daily (matched a strategy-side cosine-weight reference to 1e-3 on every bar; zero alarm trades).