Hull MA
Install and import
npm install fintech-algorithmsimport { calculateHullMa } from "fintech-algorithms/technical-indicators/trend-smoothing/hull-ma";Signature
calculateHullMa(values, window)Hull moving average: a weighted combination of two WMAs de-lagged against each other, then re-smoothed over sqrt(window). Far more responsive than an SMA of the same length, at the cost of overshoot.
Parameters
| Name | Type | Notes |
|---|---|---|
values | (number | null)[] | Observation series in chronological order, oldest first. nulls: propagate |
window | number | Base window; the internal halved window and the sqrt(window) smoothing window derive from it. min: 1 · integer: true |
Returns
(number | null)[] · length same-as-input
Smoothed series, null during the combined warm-up of all three stages.
Warm-up
The first window + ceil(sqrt(window)) - 2 positions are null. Warm-up positions are null rather than a partial result, so a consumer never mistakes an incomplete window for a real value.
Errors
- When window < 1 or is not an integer — throws RangeError
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[10, 13, 12, 15, 14, 18]Showing 6 of 10 elements.
5Call
calculateHullMa(values, window)Returns
object with 6 fields: halfLength, rootLength, shortWma, longWma, rawHull, hullMa
{
"halfLength": 2,
"rootLength": 2,
"shortWma": [null, 12, 12.333333333333334, 14, 14.333333333333334, 16.666666666666668],
"longWma": [null, null, null, null, 13.466666666666667, 15.2],
"rawHull": [null, null, null, null, 15.200000000000001, 18.133333333333336],
"hullMa": [null, null, null, null, null, 17.15555555555556]
}Diagrams
Calculation flow
Hull MA calculation flow
flowchart TD
A["Validated ordered source x(t)"] --> B["Short WMA: h = floor(n / 2)"]
A --> C["Long WMA: n observations"]
B --> D{"Both WMAs ready?"}
C --> D
D -- "No" --> E["Emit aligned null raw value"]
D -- "Yes" --> F["Raw Hull: R(t) = 2 × short − long"]
F --> G["Collect r = floor(sqrt(n)) consecutive raw values"]
G --> H{"Final WMA window ready?"}
H -- "No" --> I["Emit aligned null HMA"]
H -- "Yes" --> J["HMA(t) = WMA(r) of raw Hull"]
J --> K["Publish components, lengths, policy, and provenance"]
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Primary definition
- Independent confirmations
- Canonical decisions
- Independent derivations
- Historical-example evidence gate
- Non-claims