@pond-ts/financial API Reference
    Preparing search index...

    Function commodityChannelIndex

    • Commodity Channel Index (Donald Lambert, 1980) — how far the typical price sits from its own average, measured in mean absolute deviations:

      tp  = (high + low + close) / 3
      cci = (tp − SMA(tp, period)) / (0.015 · meanAbsDev(tp, period))

      Appends one column; undefined for the first period − 1 rows.

      It is a z-score with two substitutions, and both are deliberate on Lambert's part: the spread is the mean absolute deviation rather than the standard deviation (less sensitive to a single outlier bar), and the whole thing is divided by 0.015 so that a "normal" excursion lands inside ±100 — for a normal distribution the mean absolute deviation is about 0.8σ, so 0.015 puts roughly 70–80% of readings in that band. The constant is part of the definition, not a knob.

      Reads high, low and close, each named by an option defaulting to its DEFAULT_OHLCV column — the atr shape. For the plain standard-deviation form over a single column, zScore is the study; CCI is not it.

      TA-Lib's CCI, matched bar-for-bar — the oracle asserts identical null masks and agreement to 3.6e-12 at period 20 and 1.5e-11 at period 5 (TA-Lib accumulates its deviation sum incrementally; ours re-walks the window, so the two differ only in float summation order).

      The period 20 default is ChartIQ's, and it is not universal: Lambert's original recommends a length near a third of the instrument's cycle, TA-Lib defaults to 14, StockCharts publishes 20. Nothing here depends on the choice — it is a bar count like every other period in the package — but a comparison against another vendor's chart should check which length that chart used before calling a difference a bug.

      • Unbounded, unlike the other momentum oscillators here: ±100 is a conventional band, not a limit, and readings beyond ±300 happen. Do not scale a chart axis as if it were 0..100.
      • A window with zero mean absolute deviation (every typical price in it identical) → undefined. This is a deliberate delta from TA-Lib, which returns 0 there. 0 is also what CCI reports for a price sitting exactly on its average, so TA-Lib's answer conflates "no dispersion to measure against" with "no deviation from the average"; the rsi flat-window precedent applies. No guard is written for it: the window ends on the bar being reported, so a zero deviation forces a zero numerator, and the case is 0/0 — an explicit branch would be code no test could distinguish from its absence.
      • Scale- and shift-invariant: numerator and denominator are both homogeneous of degree one in price, and both are unchanged by adding a constant to every price. Pinned by property tests.
      • A leading gap shifts the start; an interior gap costs the period windows containing it, after which CCI recovers — the window rule, with no recursion to carry the hole forward. A bar missing any one of its three prices has no typical price, so one missing high costs the same as a missing close.
      • Cost. The mean absolute deviation is the package's one super-linear kernel — O(N · period); see rollingMeanAbsDevValues, which documents both the measurement and the O(N log period) order-statistic form that would replace it if a very long period ever asked.

      Type Parameters

      • S extends SeriesSchema
      • const Output extends string = "cci"

      Parameters

      Returns TimeSeries<
          readonly [S[0], ValueColumnsForSchema<S>, OptionalNumberColumn<Output>],
      >