From 421178a5bba96764128854fac2c0341f55ca079c Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:49:11 +0000 Subject: [PATCH] wip: hist vol --- src/panel/historic_vol.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/panel/historic_vol.rs b/src/panel/historic_vol.rs index d89dcef..8b2baa2 100644 --- a/src/panel/historic_vol.rs +++ b/src/panel/historic_vol.rs @@ -249,7 +249,7 @@ fn get_period_indices( /// - `remove_zeros`: Whether to remove zero values from the calculation. Defaults to False. /// - `postfix`: A string to append to XCAT of the result series. /// - `nan_tolerance`: The maximum proportion of NaN values allowed in the calculation. -/// +/// #[allow(unused_variables)] pub fn historic_vol( df: polars::prelude::DataFrame, @@ -269,19 +269,40 @@ pub fn historic_vol( println!("xcat: {:?},\ncids: {:?},\nlback_periods: {:?},lback_method: {:?},\nhalf_life: {:?},\nstart: {:?},\nend: {:?},\nest_freq: {:?},\nremove_zeros: {:?},\npostfix: {:?},\nnan_tolerance: {:?}", xcat, cids, lback_periods,lback_method, half_life, start, end, est_freq, remove_zeros, postfix, nan_tolerance); let mut dfw = pivot_dataframe_by_ticker(df.clone(), Some("value".to_string()))?; + println!("Successfully pivoted the DataFrame."); + let lback_periods = lback_periods.unwrap_or(20); let lback_method = lback_method.unwrap_or("ma".to_string()); let half_life = half_life; + + println!("Successfully got lback_periods, lback_method, and half_life."); + let start = start.unwrap_or(dfw.column("real_date")?.date()?.min().unwrap().to_string()); let end = end.unwrap_or(dfw.column("real_date")?.date()?.max().unwrap().to_string()); + + println!("Successfully got start and end dates."); + let est_freq = est_freq.unwrap_or("D".to_string()); + + println!("Successfully got est_freq."); + let remove_zeros = remove_zeros.unwrap_or(false); + + println!("Successfully got remove_zeros."); + let postfix = postfix.unwrap_or("_HISTVOL".to_string()); + + println!("Successfully got postfix."); + let nan_tolerance = nan_tolerance.unwrap_or(0.25); + println!("Successfully got nan_tolerance."); + let start_date = NaiveDate::parse_from_str(&start, "%Y-%m-%d")?; let end_date = NaiveDate::parse_from_str(&end, "%Y-%m-%d")?; + println!("Successfully parsed start and end dates."); + dfw = dfw .lazy() .filter( @@ -298,6 +319,8 @@ pub fn historic_vol( ) .collect()?; + println!("Successfully filtered the DataFrame."); + let period = match est_freq.as_str() { "W" => "weekly", "M" => "monthly",