ta_lib_in_rust/indicators/oscillators/
mod.rs

1// Oscillators module
2
3use polars::prelude::*;
4
5// Module declarations
6pub mod dpo;
7pub mod macd;
8pub mod ppo;
9pub mod rsi;
10pub mod stoch_rsi;
11pub mod stochastic;
12pub mod trix;
13pub mod ultimate_oscillator;
14pub mod williams_r;
15
16// Re-export functions
17pub use dpo::calculate_dpo;
18pub use macd::calculate_macd;
19pub use ppo::calculate_ppo;
20pub use rsi::calculate_rsi;
21pub use stoch_rsi::calculate_stoch_rsi;
22pub use stochastic::calculate_stochastic;
23pub use trix::calculate_trix;
24pub use ultimate_oscillator::calculate_ultimate_oscillator;
25pub use williams_r::calculate_williams_r;
26
27/// Add oscillator indicators to a DataFrame
28///
29/// # Arguments
30///
31/// * `df` - DataFrame containing OHLCV data
32///
33/// # Returns
34///
35/// * `PolarsResult<DataFrame>` - DataFrame with added oscillator indicators
36///
37/// # Example
38///
39/// ```
40/// use polars::prelude::*;
41/// use ta_lib_in_rust::indicators::oscillators::add_oscillator_indicators;
42///
43/// // Create or load a DataFrame with OHLCV data
44/// let df = DataFrame::default(); // Replace with actual data
45///
46/// // Add oscillator indicators
47/// let df_with_indicators = add_oscillator_indicators(&df).unwrap();
48/// ```
49pub fn add_oscillator_indicators(df: &DataFrame) -> PolarsResult<DataFrame> {
50    let mut result_df = df.clone();
51
52    // RSI
53    let rsi_14 = calculate_rsi(df, 14, "close")?;
54    result_df.with_column(rsi_14)?;
55
56    // MACD
57    let (macd, macd_signal) = calculate_macd(df, 12, 26, 9, "close")?;
58    result_df.with_column(macd)?;
59    result_df.with_column(macd_signal)?;
60
61    // Williams %R
62    let williams_r_14 = calculate_williams_r(df, 14)?;
63    result_df.with_column(williams_r_14)?;
64
65    // Stochastic Oscillator
66    let (stoch_k, stoch_d) = calculate_stochastic(df, 14, 3, 3)?;
67    result_df.with_column(stoch_k)?;
68    result_df.with_column(stoch_d)?;
69
70    Ok(result_df)
71}