pub fn calculate_cmf(df: &DataFrame, window: usize) -> PolarsResult<Series>
Expand description
Calculates the Chaikin Money Flow (CMF) indicator
The Chaikin Money Flow measures the amount of Money Flow Volume over a specific period. It’s particularly useful for intraday trading as it helps identify buying and selling pressure.
§Arguments
df
- DataFrame containing OHLCV data with “high”, “low”, “close”, and “volume” columnswindow
- Lookback period for calculating the CMF (typically 20 or 21)
§Returns
PolarsResult<Series>
- Series containing CMF values named “cmf_{window}”
§Formula
- Calculate Money Flow Multiplier: ((close - low) - (high - close)) / (high - low)
- Calculate Money Flow Volume: Money Flow Multiplier * volume
- Sum Money Flow Volume over the period and divide by sum of Volume over the period
§Example
use polars::prelude::*;
use ta_lib_in_rust::indicators::volume::calculate_cmf;
// Create or load a DataFrame with OHLCV data
let df = DataFrame::default(); // Replace with actual data
// Calculate CMF with period 20
let cmf = calculate_cmf(&df, 20).unwrap();