Commodity Channel Index
Calculate the Commodity Channel Index (CCI) for a given price series.
The Commodity Channel Index is an oscillator that measures the current price level relative to an average price level over a specified period.
The formula is as follows:
\[\text{CCI} = (\text{Typical Price} - \operatorname{SMA}(\text{Typical Price})) / (\text{constant} \cdot \text{Mean Deviation})\]Also known as: CCI, cyclical trend indicator.
Commodity Channel Index in Python
get_commodity_channel_index is part of the Technicals module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_commodity_channel_index as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(tickers=["AAPL", "MSFT"])
toolkit.technicals.get_commodity_channel_index()
Which returns:
| Date | AAPL | MSFT | Benchmark |
|---|---|---|---|
| 2026-06-18 | -29.8087 | -96.1785 | 0.3891 |
| 2026-06-22 | -18.6411 | -97.7637 | 4.5369 |
| 2026-06-23 | -28.0495 | -75.0122 | -75.9764 |
| 2026-06-24 | -31.5076 | -70.1223 | -67.2592 |
| 2026-06-25 | -146.597 | -87.7738 | -56.5227 |
| 2026-06-26 | -101.005 | -42.5782 | -105.047 |
| 2026-06-29 | -67.6738 | -31.457 | -11.134 |
| 2026-06-30 | -42.7183 | -21.1814 | 50.4596 |
| 2026-07-01 | 11.4352 | 12.9724 | 53.1052 |
| 2026-07-02 | 102.962 | 33.0344 | 43.6351 |
Parameters
get_commodity_channel_index accepts the following parameters:
- period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
- close_column (str, optional): The column in the historical data that represents the closing prices. Defaults to “Adj Close”.
- window (int, optional): The number of periods for calculating the CCI. Defaults to 14.
- constant (float, optional): Constant multiplier used in the CCI calculation. Defaults to 0.015.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the indicator values. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.