mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-08-20 09:40:00 +00:00
Refactor historic_vol.rs to use dateutils for date retrieval functions
This commit is contained in:
parent
cf5177d36a
commit
5ae4d30560
@ -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<f64> {
|
||||
// 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<f64> {
|
||||
weights /= weights.sum();
|
||||
weights
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
fn expo_std(x: &Array1<f64>, w: &Array1<f64>, 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<f64>, w: &Array1<f64>, 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<f64>, remove_zeros: bool) -> f64 {
|
||||
let filtered_x = if remove_zeros {
|
||||
x.iter()
|
||||
@ -62,7 +58,6 @@ fn flat_std(x: &Array1<f64>, 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) = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user