Kaufman Adaptive Moving Average (KAMA)
Install and import
npm install fintech-algorithmsimport { calculateKama } from "fintech-algorithms/technical-indicators/trend-smoothing/kama";Signature
calculateKama(values, efficiencyPeriod, fastPeriod, slowPeriod)Kaufman adaptive moving average. The smoothing constant moves between a fast and a slow bound according to an efficiency ratio — directional travel divided by total travel — so the average tightens in a trend and loosens in noise.
Parameters
| Name | Type | Notes |
|---|---|---|
values | (number | null)[] | Observation series in chronological order, oldest first. nulls: propagate |
efficiencyPeriod | number | Lookback over which the efficiency ratio is measured. min: 1 · integer: true |
fastPeriod | number | Period defining the fast bound of the smoothing constant; reached when the series is perfectly directional. min: 1 · integer: true |
slowPeriod | number | Period defining the slow bound; reached when the series is pure noise. min: 1 · integer: true |
Returns
Record<string, (number | null)[]> · length same-as-input
Parallel series: efficiencyRatio, blendedAlpha, smoothingConstant and kama, so the adaptation itself is inspectable rather than hidden inside the result.
Warm-up
The first efficiencyPeriod positions are null. The efficiency ratio needs a full lookback before the constant is defined.
Errors
- When any period is < 1, is not an integer, or fastPeriod ≥ slowPeriod — 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
[100, 101, 102, 103, 104, 103]Showing 6 of 16 elements.
10230Call
calculateKama(values, efficiencyPeriod, fastPeriod, slowPeriod)Returns
object with 4 fields: efficiencyRatio, blendedAlpha, smoothingConstant, kama
{
"efficiencyRatio": [null, null, null, null, null, null],
"blendedAlpha": [null, null, null, null, null, null],
"smoothingConstant": [null, null, null, null, null, null],
"kama": [null, null, null, null, null, null]
}Diagrams
Calculation flow
KAMA calculation flow
flowchart LR
A["Validated, ordered prices"] --> B{"At least E + 1 observations?"}
B -- "No" --> C["Return not ready"]
B -- "Yes" --> D["Change: absolute E-bar displacement"]
D --> E["Path length: sum of absolute one-bar moves"]
E --> F{"Path length is zero?"}
F -- "Yes" --> G["Efficiency ratio = 1"]
F -- "No" --> H["Efficiency ratio = change / path"]
G --> I["Blend fast and slow alpha"]
H --> I
I --> J["Square alpha to obtain SC"]
J --> K["Update from previous KAMA toward current price"]
K --> L["Publish ER, SC, and KAMA"]
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
- Smarter Trading: Improving Performance in Changing Markets — Perry J. Kaufman; McGraw-Hill Professional
- Adaptive Techniques — Perry J. Kaufman; Wiley
- TradingView official KAMA documentation — TradingView
- TA-Lib official KAMA function page — TA-Lib project
- TA-Lib pinned KAMA C implementation — TA-Lib project
- QuantConnect LEAN pinned KAMA implementation — QuantConnect
- QuantConnect LEAN pinned Efficiency Ratio implementation — QuantConnect
- Tulip Indicators pinned KAMA implementation — Tulip Charts / Tulip Indicators
- Canonical package calculations — The Fintech Builder
- Playground scenario dataset — The Fintech Builder
- Historical-example evidence gate