Add Python wrappers for get_bdates_from_col_hv and get_period_indices_hv functions

This commit is contained in:
Palash Tyagi 2025-04-06 05:14:00 +01:00
parent d897965dd2
commit 48fe8db61e
2 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,3 @@
/// Python wrapper for [`crate::utils::qdf`]. /// Python wrapper for [`crate::utils::qdf`].
pub mod qdf; pub mod qdf;

View File

@ -1,11 +1,13 @@
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3_polars::PyDataFrame; use pyo3_polars::{PyDataFrame, PySeries};
/// Python wrapper for [`crate::panel`] module. /// Python wrapper for [`crate::panel`] module.
#[allow(deprecated)] #[allow(deprecated)]
#[pymodule] #[pymodule]
pub fn panel(_py: Python, m: &PyModule) -> PyResult<()> { pub fn panel(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(historic_vol, m)?)?; m.add_function(wrap_pyfunction!(historic_vol, m)?)?;
m.add_function(wrap_pyfunction!(get_bdates_from_col_hv, m)?)?;
m.add_function(wrap_pyfunction!(get_period_indices_hv, m)?)?;
Ok(()) Ok(())
} }
@ -44,3 +46,18 @@ pub fn historic_vol(
.unwrap(), .unwrap(),
)) ))
} }
#[pyfunction]
pub fn get_bdates_from_col_hv(dfw: PyDataFrame, est_freq: &str) -> PyResult<PySeries> {
Ok(PySeries(
crate::panel::historic_vol::get_bdates_from_col_hv(&dfw.into(), est_freq)
.unwrap()
.into(),
))
}
#[pyfunction]
pub fn get_period_indices_hv(dfw: PyDataFrame, est_freq: &str) -> PyResult<Vec<usize>> {
Ok(crate::panel::historic_vol::get_period_indices_hv(&dfw.into(), est_freq).unwrap())
}