From 8a9b6bc88f8650dd4ea991297693080e247d3084 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Tue, 8 Apr 2025 22:37:53 +0100 Subject: [PATCH] Add linear_composite function to panel module with appropriate signature --- src/_py/panel.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/_py/panel.rs b/src/_py/panel.rs index a332677..493a933 100644 --- a/src/_py/panel.rs +++ b/src/_py/panel.rs @@ -8,6 +8,7 @@ pub fn panel(_py: Python, m: &PyModule) -> PyResult<()> { 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)?)?; + m.add_function(wrap_pyfunction!(linear_composite, m)?)?; Ok(()) } @@ -56,8 +57,60 @@ pub fn get_bdates_from_col_hv(dfw: PyDataFrame, est_freq: &str) -> PyResult PyResult> { Ok(crate::panel::historic_vol::get_period_indices_hv(&dfw.into(), est_freq).unwrap()) } + +#[pyfunction(signature = ( + df, + xcats, + cids, + weights = None, + signs = None, + weight_xcats = None, + normalize_weights = false, + start = None, + end = None, + blacklist = None, + complete_xcats = false, + complete_cids = false, + new_xcat = None, + new_cid = None +))] +pub fn linear_composite( + df: PyDataFrame, + xcats: Vec, + cids: Vec, + weights: Option>, + signs: Option>, + weight_xcats: Option>, + normalize_weights: bool, + start: Option, + end: Option, + blacklist: Option>>, + complete_xcats: bool, + complete_cids: bool, + new_xcat: Option, + new_cid: Option, +) -> PyResult { + Ok(PyDataFrame( + crate::panel::linear_composite::linear_composite( + &df.into(), + xcats, + cids, + weights, + signs, + weight_xcats, + normalize_weights, + start, + end, + blacklist, + complete_xcats, + complete_cids, + new_xcat, + new_cid, + ) + .unwrap(), + )) +}