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

Function solve_min_vol

crates/openquant/src/cla.rs:499–515  ·  view source on GitHub ↗
(cov: &DMatrix<f64>, bounds: &[(f64, f64)])

Source from the content-addressed store, hash-verified

497}
498
499fn solve_min_vol(cov: &DMatrix<f64>, bounds: &[(f64, f64)]) -> Result<Vec<f64>, ClaError> {
500 check_bounds_feasible(bounds)?;
501 let n = cov.nrows();
502 if n == 0 {
503 return Err(ClaError::NoData);
504 }
505 let inv = cov.clone().try_inverse().ok_or(ClaError::NoData)?;
506 let ones = DVector::from_element(n, 1.0);
507 let num = &inv * &ones;
508 let denom = (ones.transpose() * &inv * &ones)[(0, 0)];
509 if denom.abs() < 1e-12 {
510 return Err(ClaError::NoData);
511 }
512 let mut w: Vec<f64> = num.iter().map(|v| v / denom).collect();
513 project_to_bounds(&mut w, bounds)?;
514 Ok(w)
515}
516
517fn solve_max_sharpe(
518 cov: &DMatrix<f64>,

Callers 1

allocateMethod · 0.70

Calls 2

check_bounds_feasibleFunction · 0.70
project_to_boundsFunction · 0.70

Tested by

no test coverage detected