Add logging for historic volatility calculations and implement utility to get min/max real dates

This commit is contained in:
Palash Tyagi
2025-03-15 00:03:09 +00:00
parent 421178a5bb
commit 71f9f4a674
3 changed files with 46 additions and 3 deletions

View File

@@ -131,9 +131,15 @@ fn freq_period_calc(
);
}
println!("Calculating historic volatility with the following parameters:");
println!("lback_periods: {:?}, lback_method: {:?}, half_life: {:?}, remove_zeros: {:?}, nan_tolerance: {:?}, period: {:?}", lback_periods, lback_method, half_life, remove_zeros, nan_tolerance, period);
let mut new_df = dfw.clone();
for col_name in dfw.get_column_names() {
if col_name == "real_date" {
continue;
}
let series = dfw.column(col_name)?;
let values: Array1<f64> = series
.f64()?
@@ -174,7 +180,7 @@ fn freq_period_calc(
}
_ => return Err("Invalid lookback method.".into()),
};
println!("Successfully calculated result_series for column: {:?}", col_name);
new_df.with_column(result_series)?;
}
@@ -298,9 +304,14 @@ pub fn historic_vol(
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")?;
let (dfw_start_date, dfw_end_date) =
crate::utils::misc::get_min_max_real_dates(&dfw, "real_date")?;
println!("Successfully got min and max real dates.");
let (start_date, end_date) = (
NaiveDate::parse_from_str(&start, "%Y-%m-%d").unwrap_or_else(|_| dfw_start_date),
NaiveDate::parse_from_str(&end, "%Y-%m-%d").unwrap_or_else(|_| dfw_end_date),
);
println!("Successfully parsed start and end dates.");
dfw = dfw
@@ -327,6 +338,8 @@ pub fn historic_vol(
_ => return Err("Invalid frequency specified.".into()),
};
println!("Successfully got period.");
let dfw = match est_freq.as_str() {
"D" => freq_daily_calc(
&dfw,

View File