ta_lib_in_rust/indicators/volume/mod.rs
1// Volume indicators module
2
3use polars::prelude::*;
4
5// Modules for volume indicators
6mod adl;
7mod cmf;
8mod eom;
9mod mfi;
10mod obv;
11mod pvt;
12
13// Re-export volume indicators
14pub use adl::calculate_adl;
15pub use cmf::calculate_cmf;
16pub use eom::calculate_eom;
17pub use mfi::calculate_mfi;
18pub use obv::calculate_obv;
19pub use pvt::calculate_pvt;
20
21/// Add volume-based indicators to a DataFrame
22///
23/// This function calculates and adds multiple volume-based indicators to the input DataFrame,
24/// which is useful for combining multiple indicators in a single call.
25///
26/// # Arguments
27///
28/// * `df` - DataFrame containing OHLCV data
29///
30/// # Returns
31///
32/// * `PolarsResult<DataFrame>` - DataFrame with added volume indicators
33///
34/// # Example
35///
36/// ```
37/// use polars::prelude::*;
38/// use ta_lib_in_rust::indicators::volume::add_volume_indicators;
39///
40/// // Create or load a DataFrame with OHLCV data
41/// let df = DataFrame::default(); // Replace with actual data
42///
43/// // Add volume indicators
44/// let df_with_indicators = add_volume_indicators(&df).unwrap();
45/// ```
46pub fn add_volume_indicators(df: &DataFrame) -> PolarsResult<DataFrame> {
47 let mut result_df = df.clone();
48
49 // Calculate On Balance Volume (OBV)
50 let obv = calculate_obv(df)?;
51 result_df.with_column(obv)?;
52
53 // Calculate Chaikin Money Flow (CMF) with default period of 20
54 let cmf = calculate_cmf(df, 20)?;
55 result_df.with_column(cmf)?;
56
57 // Calculate Money Flow Index (MFI) with default period of 14
58 let mfi = calculate_mfi(df, 14)?;
59 result_df.with_column(mfi)?;
60
61 Ok(result_df)
62}