Main Page > Articles > Money Flow Index > Quantitative Analysis of Chaikin Money Flow (CMF) using NumPy and SciPy

Quantitative Analysis of Chaikin Money Flow (CMF) using NumPy and SciPy

From TradingHabits, the trading encyclopedia · 5 min read · February 28, 2026
The Black Book of Day Trading Strategies
Free Book

The Black Book of Day Trading Strategies

1,000 complete strategies · 31 chapters · Full trade plans

The Chaikin Money Flow (CMF), developed by Marc Chaikin, is a volume-weighted average of accumulation and distribution over a set period. The CMF indicator oscillates around a zero line, with positive values indicating buying pressure and negative values indicating selling pressure. It is a valuable tool for assessing the strength of a trend and identifying potential reversals.

This article will guide you through the calculation of CMF, its implementation using NumPy for efficiency, and how to apply SciPy for a more in-depth statistical analysis of the CMF signal.

The Mathematical Formulation of CMF

The CMF calculation involves three steps:

  1. Money Flow Multiplier: This is calculated for each period:

    Money Flow Multiplier = [(Close - Low) - (High - Close)] / (High - Low)
    
  2. Money Flow Volume: This is the Money Flow Multiplier multiplied by the period's volume:

    Money Flow Volume = Money Flow Multiplier * Volume
    
  3. Chaikin Money Flow: This is the sum of Money Flow Volume over a specified period (typically 20 or 21 days) divided by the sum of volume over the same period:

    CMF = Sum(Money Flow Volume for n periods) / Sum(Volume for n periods)
    

Implementing CMF with NumPy

NumPy's array operations are ideal for calculating the CMF efficiently. Below is a Python function that demonstrates this:

python
import numpy as np

def calculate_cmf(high, low, close, volume, n=20):
    mf_multiplier = ((close - low) - (high - close)) / (high - low)
    mf_volume = mf_multiplier * volume
    cmf = np.zeros_like(close, dtype=float)
    for i in range(n - 1, len(close)):
        cmf[i] = np.sum(mf_volume[i - n + 1:i + 1]) / np.sum(volume[i - n + 1:i + 1])
    return cmf

Statistical Analysis of CMF with SciPy

We can use SciPy to analyze the CMF series. For example, we can test for the normality of the CMF distribution using the shapiro test from scipy.stats. This can help in determining if the CMF values follow a normal distribution, which can be useful for certain statistical models.

python
from scipy.stats import shapiro

# Assuming 'cmf_data' is a NumPy array of CMF values
stat, p_value = shapiro(cmf_data)

A low p-value would suggest that the CMF data is not normally distributed.

Sample Data and CMF Calculation

Consider the following data for a stock:

DayHighLowCloseVolumeCMF (n=3)
110299101100000.00
2103100102120000.00
3104101103110000.61
4103100101130000.03
51029910015000-0.33

Actionable Trading Examples

  1. Trend Strength: A CMF value consistently above a certain positive threshold (e.g., +0.05) can indicate strong buying pressure, supporting a long position in an uptrend. Conversely, a CMF value consistently below a negative threshold (e.g., -0.05) suggests strong selling pressure.

  2. Zero-Line Crossovers: A crossover of the CMF line above the zero line can be a bullish signal, while a crossover below the zero line can be a bearish signal. These signals are often used in conjunction with other indicators for confirmation.

Conclusion

The Chaikin Money Flow is a sophisticated indicator that provides valuable insights into the flow of money in and out of a security. By using NumPy for efficient calculation and SciPy for statistical analysis, traders can develop a deeper understanding of the CMF signal and integrate it into their quantitative trading strategies. This approach allows for the development of more robust and data-driven trading systems.