MCPcopy Create free account
hub / github.com/Open-Quant/openquant / inverse_variance_weights

Function inverse_variance_weights

crates/openquant/src/hcaa.rs:353–367  ·  view source on GitHub ↗
(cov: &DMatrix<f64>, indices: &[usize])

Source from the content-addressed store, hash-verified

351}
352
353fn inverse_variance_weights(cov: &DMatrix<f64>, indices: &[usize]) -> Result<Vec<f64>, HcaaError> {
354 let mut inv_diag: Vec<f64> = Vec::with_capacity(indices.len());
355 for &i in indices {
356 let v = cov[(i, i)];
357 if v <= 0.0 {
358 return Err(HcaaError::NoData);
359 }
360 inv_diag.push(1.0 / v);
361 }
362 let sum: f64 = inv_diag.iter().sum();
363 if sum <= 0.0 {
364 return Err(HcaaError::NoData);
365 }
366 Ok(inv_diag.into_iter().map(|x| x / sum).collect())
367}
368
369fn cluster_variance(cov: &DMatrix<f64>, indices: &[usize]) -> Result<f64, HcaaError> {
370 let w = inverse_variance_weights(cov, indices)?;

Callers 4

cluster_varianceFunction · 0.70
cluster_sharpeFunction · 0.70

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected