Skip to main content

Module portfolio

Module portfolio 

Source
Expand description

Portfolio optimization engine (Rust/nalgebra port, quantwave-a465).

Rust port of the Python-first v1 shipped at quantwave-py/python/quantwave/portfolio.py (p2k0.5, PR #21). That module is the numerical SPEC: sample/EWMA/Ledoit-Wolf covariance estimators; min-variance / max-Sharpe (closed-form) / risk-parity (Spinu fixed-point) / HRP (hand-rolled single-linkage) optimizers; capped-simplex projection for box+budget constraints. This module mirrors that algorithmically, operating on nalgebra DMatrix<f64> / DVector<f64> instead of numpy arrays, so it can be embedded in the core engine and driven from Rust callers (backtests, live sizing) without a Python round-trip. PyO3 bindings in quantwave-py expose it to Python as quantwave._portfolio (see that crate for the numpy <-> nalgebra bridge).

§Conventions

  • Returns matrices are (rows = time, cols = assets).
  • Every optimizer returns a weights vector that sums to 1.0.
  • Degenerate inputs (singular covariance, a single asset, NaN returns) return PortfolioError rather than panicking or returning NaN weights (workspace lint: unwrap_used/expect_used = warn, panic = deny).

Enums§

HrpInputKind
Interpretation of the input matrix passed to hrp.
PortfolioConstraint
Directional constraint applied to portfolio weights during projection.
PortfolioError
Errors from the portfolio-optimization engine.

Functions§

apply_bounds_and_budget
Project raw weights onto the box-constrained, budget=1 feasible set.
ewma_cov
Exponentially-weighted covariance matrix (RiskMetrics-style).
hrp
Hierarchical Risk Parity (Lopez de Prado) portfolio weights.
ledoit_wolf_cov
Ledoit-Wolf shrinkage covariance estimator (shrinkage target: identity-scaled).
max_sharpe
Maximum-Sharpe (tangency) portfolio weights.
min_variance
Minimum-variance portfolio weights.
risk_parity
Equal risk-contribution (“risk parity”) portfolio weights.
sample_cov
Sample covariance matrix of asset returns: np.cov(returns, rowvar=False, ddof=1).

Type Aliases§

Bounds
Per-asset (low, high) weight bounds.