2026-03-23 23:34:28 +05:30
|
|
|
use crate::validation;
|
|
|
|
|
use numpy::{IntoPyArray, PyArray1, PyReadonlyArray1};
|
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
2026-03-30 12:45:52 +05:30
|
|
|
/// On Balance Volume: cumulates volume * sign(close - prev_close).
|
2026-03-23 23:34:28 +05:30
|
|
|
#[pyfunction]
|
|
|
|
|
pub fn obv<'py>(
|
|
|
|
|
py: Python<'py>,
|
|
|
|
|
close: PyReadonlyArray1<'py, f64>,
|
|
|
|
|
volume: PyReadonlyArray1<'py, f64>,
|
|
|
|
|
) -> PyResult<Bound<'py, PyArray1<f64>>> {
|
|
|
|
|
let closes = close.as_slice()?;
|
|
|
|
|
let vols = volume.as_slice()?;
|
|
|
|
|
let n = closes.len();
|
|
|
|
|
validation::validate_equal_length(&[(n, "close"), (vols.len(), "volume")])?;
|
2026-03-30 12:45:52 +05:30
|
|
|
let result = ferro_ta_core::volume::obv(closes, vols);
|
2026-03-23 23:34:28 +05:30
|
|
|
Ok(result.into_pyarray(py))
|
|
|
|
|
}
|