Systemicalpha

Kaufman's Adaptive Moving Average

systemic:core-kamaIndicatorsfunction1 cr

Inputs

NameTypeDescription
WindowintegerThe **window** parameter (often denoted as $N$) controls how many periods are used to calculate the Efficiency Ratio (ER). This is the *memory* of KAMA's trend detection.
Slow PeriodintegerThe **slow period** defines the *maximum smoothing* KAMA can apply—the equivalent of a long EMA when markets are choppy and directionless.
Fast PeriodintegerThe **fast period** defines the *minimum smoothing* KAMA can apply—the equivalent of a short, highly responsive EMA when markets are trending strongly.
PricefloatarrayThe **price data** input is a time series of numerical values representing the asset's price history—typically closing prices, though any consistent price type (open, high, low, or a custom calculation) can be used.

Outputs

NameTypeDescription
KAMAfloatarrayThe **KAMA output** is a time series of the same length as the input price data, representing the adaptive moving average at each point in time.

At a Glance

KAMAt=KAMAt−1+SC2×(Pricet−KAMAt−1)\text{KAMA}_t = \text{KAMA}_{t-1} + SC^2 \times (\text{Price}_t - \text{KAMA}_{t-1})

where SC=ER×(αfast−αslow)+αslowSC = ER \times (\alpha_{fast} - \alpha_{slow}) + \alpha_{slow}

KAMA is a moving average that thinks. When markets trend strongly, it hugs price tightly. When markets chop sideways, it smooths aggressively to filter noise. This adaptive behavior—controlled by the Efficiency Ratio—makes KAMA one of the most sophisticated trend-following tools available.


The Problem KAMA Solves

Traditional moving averages force you into an uncomfortable trade-off:

flowchart LR
    subgraph Problem["The Moving Average Dilemma"]
        direction TB
        Fast["🏃 Fast MA<br/>Responsive to trends<br/>But noisy in ranges"]
        Slow["🐢 Slow MA<br/>Smooth in ranges<br/>But lags in trends"]
    end
    Fast <--> |"Pick your poison"| Slow

Fast moving averages (like a 10-period EMA) react quickly to price changes—great during trends, but they generate whipsaws during sideways markets.

Slow moving averages (like a 50-period SMA) filter out noise beautifully—but by the time they signal a trend, you've missed half the move.

KAMA's solution: Don't choose. Let the market tell you when to be fast and when to be slow.


The Mathematics of Adaptation

Understanding KAMA requires grasping three interconnected concepts: the Efficiency Ratio, the Smoothing Constant, and the recursive update formula.

Step 1: The Efficiency Ratio (ER)

The Efficiency Ratio measures how efficiently price has moved from point A to point B. Think of it as asking: "Of all the price movement that occurred, how much was directional versus noise?"

ER=∣Pricet−Pricet−N∣∑i=1N∣Pricet−i+1−Pricet−i∣ER = \frac{|\text{Price}_t - \text{Price}_{t-N}|}{\sum_{i=1}^{N} |\text{Price}_{t-i+1} - \text{Price}_{t-i}|}

Numerator (Change): The absolute net price change over the window—how far price actually traveled.

Denominator (Volatility): The sum of all absolute period-to-period changes—the total "path length" price took.

ER ValueMarket ConditionInterpretation
ER = 1Perfect trendPrice moved in one direction only—no retracements
ER = 0Pure noisePrice ended exactly where it started despite movement
ER ≈ 0.5MixedSome trend, some noise—typical market behavior

Why absolute values? Direction doesn't matter when measuring efficiency. A 10-point drop is equally "directional" as a 10-point rise.

Step 2: The Smoothing Constant (SC)

The Smoothing Constant translates the Efficiency Ratio into an actionable smoothing factor. It interpolates between a "fast" and "slow" exponential moving average based on ER:

SC=ER×(αfast−αslow)+αslowSC = ER \times (\alpha_{fast} - \alpha_{slow}) + \alpha_{slow}

where the EMA smoothing factors are:

αfast=2Fast Period+1andαslow=2Slow Period+1\alpha_{fast} = \frac{2}{\text{Fast Period} + 1} \quad \text{and} \quad \alpha_{slow} = \frac{2}{\text{Slow Period} + 1}

With default parameters (Fast = 2, Slow = 30):

  • αfast=23≈0.667\alpha_{fast} = \frac{2}{3} \approx 0.667
  • αslow=231≈0.065\alpha_{slow} = \frac{2}{31} \approx 0.065

The squaring trick: KAMA actually uses SC2SC^2 in the final formula. This amplifies the difference between trending and ranging markets—when ER is low, SC2SC^2 becomes very small, making KAMA nearly flat.

Step 3: The KAMA Update

The final KAMA value is computed recursively:

KAMAt=KAMAt−1+SC2×(Pricet−KAMAt−1)\text{KAMA}_t = \text{KAMA}_{t-1} + SC^2 \times (\text{Price}_t - \text{KAMA}_{t-1})

This is the same structure as an EMA, but with a dynamic smoothing factor SC2SC^2 instead of a fixed one.

flowchart TD
    A[Price Data Series] --> B[Calculate Change]
    A --> C[Calculate Volatility]
    B --> D["Efficiency Ratio (ER)"]
    C --> D
    D --> E[Apply Fast/Slow SC]
    E --> F["Smoothing Constant (SC)"]
    F --> G["Square SC → SC²"]
    G --> H[Recursive KAMA Update]
    H --> I[KAMA Output Series]

How KAMA Adapts: A Visual Guide

The relationship between the Efficiency Ratio and KAMA's behavior is the heart of the indicator:

flowchart LR
    subgraph ER["Efficiency Ratio Spectrum"]
        direction TB
        ER0["ER → 0<br/>Choppy/Noisy<br/>Market"]
        ER1["ER → 1<br/>Strong Trend<br/>Market"]
    end
    
    subgraph SC["Smoothing Response"]
        direction TB
        SC0["SC → Slowest<br/>30-period EMA<br/>More Smoothing"]
        SC1["SC → Fastest<br/>2-period EMA<br/>Less Smoothing"]
    end
    
    ER0 -.-> SC0
    ER1 -.-> SC1

Interpreting KAMA Signals

Trend Direction

The simplest use: KAMA slope indicates trend.

KAMA BehaviorSignalConfidence
Rising with steep slopeBullish trendHigh (ER is high)
Falling with steep slopeBearish trendHigh (ER is high)
Nearly flatNo clear trendMarket is ranging

Price-KAMA Crossovers

When price crosses above or below KAMA, it often signals a trend change. However, KAMA's adaptive nature means crossovers in trending markets are more significant than crossovers during chop.

sequenceDiagram
    participant Price
    participant KAMA
    participant Trader
    
    Note over Price,KAMA: Ranging Market (Low ER)
    Price->>KAMA: Multiple crossovers
    KAMA-->>Trader: ⚠️ Filter these signals
    
    Note over Price,KAMA: Trending Market (High ER)
    Price->>KAMA: Decisive crossover
    KAMA->>Trader: ✅ Act on this signal

Dual-KAMA Strategy

A powerful approach uses two KAMA lines with different responsiveness:

  • Faster KAMA: Lower fast period (e.g., KAMA with Fast = 2)
  • Slower KAMA: Higher fast period (e.g., KAMA with Fast = 5)

When the faster KAMA crosses above the slower KAMA, it signals potential trend acceleration—and vice versa.


Practical Applications

1. Cryptocurrency Volatility Regime Detection

Cryptocurrencies like Bitcoin are notorious for alternating between explosive trends and grinding consolidation. KAMA's Efficiency Ratio provides a real-time volatility regime detector.

The Insight: When ER stays above 0.6 for extended periods, the market is in a trending regime—ideal for momentum strategies. When ER hovers below 0.3, mean-reversion or range-trading strategies become more appropriate.

System Design Idea:

  1. Connect a cryptocurrency price feed to KAMA
  2. Use a separate module to track ER over time (you can approximate this by observing how quickly KAMA responds to price)
  3. When KAMA closely tracks price (high ER regime), tilt toward trend-following
  4. When KAMA moves slowly despite price swings (low ER regime), tilt toward range-trading

This approach lets you adapt your strategy to market conditions, much like how KAMA adapts its own smoothing.

2. Multi-Timeframe Trend Confirmation

A classic problem: short-term signals that contradict the larger trend lead to losses. KAMA on multiple timeframes provides a solution.

Implementation:

  • Apply KAMA to daily data for the "macro" trend direction
  • Apply KAMA to hourly data for entry timing
  • Only take signals when both timeframes agree

For example, if daily KAMA is rising and price pulls back to hourly KAMA during a consolidation (low hourly ER), a bounce off hourly KAMA becomes a high-probability long entry.

3. Dynamic Position Sizing Based on Trend Quality

Most position sizing methods use fixed percentages or volatility adjustments (like ATR). KAMA introduces a more nuanced approach: scale position size with trend quality.

The Concept:

  • When KAMA is responsive (high ER), trends are clean—increase position size
  • When KAMA is sluggish (low ER), markets are noisy—reduce position size

This isn't just risk management; it's opportunity sizing. You're betting bigger when conditions favor directional trades and smaller when they don't.


Advantages Over Other Moving Averages

FeatureSMAEMAKAMA
Lag in trendsHighMediumLow (adaptive)
Noise filtering in rangesLowLowHigh (adaptive)
Parameter sensitivityHighMediumLower (self-adjusting)
ComplexitySimpleSimpleModerate

KAMA's self-adjusting nature means less parameter tuning. While you still choose the window, fast period, and slow period, KAMA's adaptive logic reduces the impact of suboptimal choices.


Limitations and Considerations

Lag still exists. KAMA reduces lag compared to slow moving averages, but it cannot eliminate it entirely. In extremely fast markets—like crypto flash crashes—even KAMA will trail.

Not a crystal ball. KAMA tells you what the market has been doing, not what it will do. High ER today doesn't guarantee trend continuation tomorrow.

The squaring effect. Because SC is squared, KAMA can become very unresponsive during choppy periods. This is usually desirable, but in some cases you may miss the start of a new trend.

Initial value matters. The first KAMA value is typically set as a simple average of the first N prices. In backtesting, be aware of this "warm-up" period.


References and Further Reading


Glossary

TermDefinition
Efficiency Ratio (ER)A measure of directional movement relative to total movement; ranges from 0 to 1
Smoothing Constant (SC)The adaptive factor that controls KAMA's responsiveness
Fast PeriodThe shortest EMA period used when ER = 1 (maximum responsiveness)
Slow PeriodThe longest EMA period used when ER = 0 (maximum smoothing)
Window (N)The lookback period for calculating the Efficiency Ratio
CrossoverWhen price moves from one side of KAMA to the other
WhipsawA false signal where price crosses a moving average but quickly reverses

Data Alignment and Timeframe Considerations

When using KAMA in Systemic, understanding how data is aligned is essential for accurate calculations.

Single Input Simplicity: KAMA only requires price data, so there's no multi-series alignment to worry about—unlike indicators that combine price with volume.

Constant Parameters: The Window, Fast Period, and Slow Period are all constant values—not dynamic series. This means they don't participate in time-series alignment and remain fixed throughout the calculation.


Missing Data

A closed-market or missing-data bar (null) is never fabricated — not padded with the last available value, not echoed as a raw price, not frozen. The Efficiency Ratio and the recursive KAMA update both run over the observed bars only ("window-bar ER" = window observed bars, weekends bridged), then the result is placed back at the original grid slots:

  • Gaps are bridged, not broken: a Friday-to-Monday transition is evaluated as adjacent observed bars — the recursive KAMA state carries across the gap — the closed-weekend slot itself is null, never a repeated or interpolated value.
  • Warm-up (first window − 1 observed bars) is null, not the raw price echoed back and not a partial-window ER.
  • All bars missing returns every slot null, no crash.
  • Live execution returns exactly one datapoint — the newest bar's value, or null when that bar itself is missing or still in warm-up.

Indicator Profile

quadrantChart
    title KAMA Indicator Profile
    x-axis Low Popularity --> High Popularity
    y-axis Low Reliability --> High Reliability
    quadrant-1 High potential  
    quadrant-2 Established leaders
    quadrant-3 Niche tools
    quadrant-4 Popular but risky
    KAMA - Stocks: [0.55, 0.80]
    KAMA - Crypto: [0.50, 0.75]
DimensionStocksCryptoNotes
Popularity5.5/105.0/10Less known than SMA/EMA; favored by systematic traders
Reliability8.0/107.5/10Self-adjusting reduces false signals; crypto volatility tests limits
Complexity6.5/106.5/10Requires understanding of ER and smoothing mechanics
Versatility8.0/108.0/10Works across timeframes and asset classes
Recent Interest6.0/106.5/10Growing adoption in algo trading; well-suited for crypto regime detection

This documentation is for educational purposes only and does not constitute investment advice. Markets involve risk, and past performance does not guarantee future results. Always conduct your own research and consult with qualified professionals before making investment decisions.

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5