Main Page > Articles > Money Flow Index > Money Flow Index (MFI): A Volume-Weighted RSI for Sophisticated Traders

Money Flow Index (MFI): A Volume-Weighted RSI for Sophisticated Traders

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

Introduction to the Money Flow Index (MFI)

The Money Flow Index (MFI) is a momentum indicator that measures the flow of money into and out of a security over a specified period. It is related to the Relative Strength Index (RSI), but incorporates volume, making it a volume-weighted RSI. The MFI is used to identify overbought and oversold conditions, as well as to spot divergences that may signal a trend reversal.

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

The Mathematical Formulation of MFI

The MFI calculation involves several steps:

  1. Typical Price: First, calculate the typical price for each period:

    Typical Price = (High + Low + Close) / 3
    
  2. Raw Money Flow: Then, calculate the raw money flow:

    Raw Money Flow = Typical Price * Volume
    
  3. Positive and Negative Money Flow: Separate the money flow into positive and negative money flow. Positive money flow is the sum of raw money flow for periods where the typical price is higher than the previous period's typical price. Negative money flow is the sum of raw money flow for periods where the typical price is lower.

  4. Money Flow Ratio and MFI: Finally, calculate the money flow ratio and the MFI:

    Money Flow Ratio = Positive Money Flow / Negative Money Flow
    MFI = 100 - (100 / (1 + Money Flow Ratio))
    

Implementing MFI with NumPy

NumPy's array operations are well-suited for the efficient calculation of the MFI. Here is a Python function that demonstrates this:

python
import numpy as np

def calculate_mfi(high, low, close, volume, n=14):
    typical_price = (high + low + close) / 3
    raw_money_flow = typical_price * volume
    
    positive_money_flow = np.zeros_like(raw_money_flow)
    negative_money_flow = np.zeros_like(raw_money_flow)
    
    for i in range(1, len(typical_price)):
        if typical_price[i] > typical_price[i-1]:
            positive_money_flow[i] = raw_money_flow[i]
        else:
            negative_money_flow[i] = raw_money_flow[i]
            
    mfi = np.zeros_like(close, dtype=float)
    for i in range(n - 1, len(close)):
        sum_positive_mf = np.sum(positive_money_flow[i - n + 1:i + 1])
        sum_negative_mf = np.sum(negative_money_flow[i - n + 1:i + 1])
        
        if sum_negative_mf == 0:
            mfi[i] = 100
        else:
            money_flow_ratio = sum_positive_mf / sum_negative_mf
            mfi[i] = 100 - (100 / (1 + money_flow_ratio))
            
    return mfi

Statistical Analysis of MFI with SciPy

We can use SciPy to analyze the distribution of MFI values. For example, we can create a histogram of the MFI data and fit a probability distribution to it using the fit function from scipy.stats. This can help in understanding the statistical properties of the MFI and in identifying extreme values.

python
from scipy.stats import norm

# Assuming 'mfi_data' is a NumPy array of MFI values
mu, std = norm.fit(mfi_data)

Sample Data and MFI Calculation

Let's consider the following data for a stock:

DayHighLowCloseVolumeMFI (n=3)
110299101100000.00
2103100102120000.00
310410110311000100.00
41031001011300065.79
5102991001500045.45

Actionable Trading Examples

  1. Overbought/Oversold Levels: The MFI is typically interpreted as overbought when it is above 80 and oversold when it is below 20. These levels can signal potential reversals. A move from above 80 back below it can be a sell signal, while a move from below 20 back above it can be a buy signal.

  2. Divergences: As with the RSI, divergences between the MFI and the price can be effective signals. A bearish divergence occurs when the price makes a new high, but the MFI fails to make a new high. A bullish divergence occurs when the price makes a new low, but the MFI makes a higher low.

Conclusion

The Money Flow Index is a valuable indicator that combines price and volume to provide a more comprehensive picture of market momentum. By using NumPy for efficient calculation and SciPy for statistical analysis, traders can develop a deeper understanding of the MFI and incorporate it into their quantitative trading strategies. This data-driven approach can lead to more robust and profitable trading systems.