From 5ae4d30560f28acad370f7456873cf6e8d85f886 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Thu, 10 Apr 2025 20:51:36 +0100 Subject: [PATCH] Refactor historic_vol.rs to use dateutils for date retrieval functions --- src/panel/historic_vol.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/panel/historic_vol.rs b/src/panel/historic_vol.rs index c650146..e8c427d 100644 --- a/src/panel/historic_vol.rs +++ b/src/panel/historic_vol.rs @@ -1,4 +1,4 @@ -use crate::utils::misc::*; +use crate::utils::dateutils::{get_bdates_from_col, get_min_max_real_dates}; use crate::utils::qdf::pivots::*; use crate::utils::qdf::reduce_df::*; use chrono::NaiveDate; @@ -10,12 +10,10 @@ use polars::series::Series; // Series struct /// Returns the annualization factor for 252 trading days. /// (SQRT(252)) -#[allow(dead_code)] fn annualization_factor() -> f64 { 252f64.sqrt() } -#[allow(dead_code)] fn expo_weights(lback_periods: usize, half_life: f64) -> Array1 { // Calculates exponential series weights for finite horizon, normalized to 1. let decf = 2f64.powf(-1.0 / half_life); @@ -27,7 +25,6 @@ fn expo_weights(lback_periods: usize, half_life: f64) -> Array1 { weights /= weights.sum(); weights } -#[allow(dead_code)] fn expo_std(x: &Array1, w: &Array1, remove_zeros: bool) -> f64 { assert_eq!(x.len(), w.len(), "weights and window must have same length"); let (filtered_x, filtered_w) = if remove_zeros { @@ -49,7 +46,6 @@ fn expo_std(x: &Array1, w: &Array1, remove_zeros: bool) -> f64 { .fold(0.0, |acc, &x_val, &w_val| acc + w_val * x_val.abs()) } -#[allow(dead_code)] fn flat_std(x: &Array1, remove_zeros: bool) -> f64 { let filtered_x = if remove_zeros { x.iter() @@ -62,7 +58,6 @@ fn flat_std(x: &Array1, remove_zeros: bool) -> f64 { filtered_x.mapv(f64::abs).mean().unwrap_or(0.0) } -#[allow(unused_variables)] fn freq_daily_calc( dfw: &DataFrame, lback_periods: usize, @@ -128,7 +123,6 @@ fn freq_daily_calc( Ok(new_df) } -#[allow(unused_variables)] fn freq_period_calc( dfw: &DataFrame, @@ -265,7 +259,6 @@ fn get_period_indices( /// - `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, xcat: String, @@ -324,8 +317,7 @@ pub fn historic_vol( println!("Successfully got nan_tolerance."); - let (dfw_start_date, dfw_end_date) = - crate::utils::misc::get_min_max_real_dates(&dfw, "real_date")?; + let (dfw_start_date, dfw_end_date) = get_min_max_real_dates(&dfw, "real_date")?; println!("Successfully got min and max real dates."); let (start_date, end_date) = (