polars-ta 0.1.0

Polars Series interface for technical indicators — native Polars integration, aligned with ta-lib
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use polars_core::prelude::*;
use polars_ta_core::oscillator::aroonosc as aroonosc_core;

fn series_to_f64(s: &Series) -> PolarsResult<Vec<f64>> {
    Ok(s.cast(&DataType::Float64)?
        .f64()?
        .into_iter()
        .map(|v| v.unwrap_or(f64::NAN))
        .collect())
}

/// Aroon Oscillator (Aroon Up − Aroon Down). Output length = `n - period`.
pub fn aroonosc_series(high: &Series, low: &Series, period: usize) -> PolarsResult<Series> {
    let h = series_to_f64(high)?;
    let l = series_to_f64(low)?;
    let result = aroonosc_core(&h, &l, period);
    Ok(Float64Chunked::from_vec("aroonosc".into(), result).into_series())
}