added py-bindings for panel/hist_vol

This commit is contained in:
Palash Tyagi 2024-11-22 17:16:36 +00:00
parent 8f3ffa6298
commit 6599f265b6
3 changed files with 53 additions and 0 deletions

3
src/panel/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod historic_vol;

View File

@ -5,6 +5,9 @@ pub mod qdf;
/// Python API for [`crate::download`]. /// Python API for [`crate::download`].
pub mod download; pub mod download;
/// Python API for [`crate::panel`].
pub mod panel;
use pyo3::{prelude::*, wrap_pymodule}; use pyo3::{prelude::*, wrap_pymodule};
// use pyo3_polars::PyDataFrame; // use pyo3_polars::PyDataFrame;
@ -13,5 +16,6 @@ use pyo3::{prelude::*, wrap_pymodule};
pub fn msyrs(_py: Python, m: &PyModule) -> PyResult<()> { pub fn msyrs(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pymodule!(qdf::qdf))?; m.add_wrapped(wrap_pymodule!(qdf::qdf))?;
m.add_wrapped(wrap_pymodule!(download::download))?; m.add_wrapped(wrap_pymodule!(download::download))?;
m.add_wrapped(wrap_pymodule!(panel::panel))?;
Ok(()) Ok(())
} }

46
src/py/panel.rs Normal file
View File

@ -0,0 +1,46 @@
use pyo3::prelude::*;
use pyo3_polars::PyDataFrame;
/// Python wrapper for [`crate::panel`] module.
#[allow(deprecated)]
#[pymodule]
pub fn panel(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(historic_vol, m)?)?;
Ok(())
}
/// Python wrapper for calculating historic volatility.
/// See [`crate::panel::historic_vol`] for full documentation.
#[pyfunction]
pub fn historic_vol(
df: PyDataFrame,
xcat: String,
cids: Option<Vec<String>>,
lback_periods: Option<usize>,
lback_method: Option<String>,
half_life: Option<f64>,
start: Option<String>,
end: Option<String>,
est_freq: Option<String>,
remove_zeros: Option<bool>,
postfix: Option<String>,
nan_tolerance: Option<f64>,
) -> PyResult<PyDataFrame> {
Ok(PyDataFrame(
crate::panel::historic_vol::historic_vol(
df.into(),
xcat,
cids,
lback_periods,
lback_method,
half_life,
start,
end,
est_freq,
remove_zeros,
postfix,
nan_tolerance,
)
.unwrap(),
))
}