pub struct MeanVarianceOptimizer;Expand description
Mean-variance portfolio optimizer using gradient descent.
Implementations§
Source§impl MeanVarianceOptimizer
impl MeanVarianceOptimizer
Sourcepub fn portfolio_return(weights: &[f64], returns: &[f64]) -> f64
pub fn portfolio_return(weights: &[f64], returns: &[f64]) -> f64
Compute expected portfolio return: dot product of weights and returns.
Sourcepub fn portfolio_variance(weights: &[f64], cov: &[Vec<f64>]) -> f64
pub fn portfolio_variance(weights: &[f64], cov: &[Vec<f64>]) -> f64
Compute portfolio variance: w^T Σ w.
Sourcepub fn portfolio_volatility(weights: &[f64], cov: &[Vec<f64>]) -> f64
pub fn portfolio_volatility(weights: &[f64], cov: &[Vec<f64>]) -> f64
Compute portfolio volatility: sqrt(w^T Σ w).
Sourcepub fn gradient_step(
weights: &mut Vec<f64>,
returns: &[f64],
cov: &[Vec<f64>],
target_return: f64,
lr: f64,
)
pub fn gradient_step( weights: &mut Vec<f64>, returns: &[f64], cov: &[Vec<f64>], target_return: f64, lr: f64, )
Perform one gradient step minimizing variance subject to a target return.
Uses the gradient of Var(w) - lambda * (Return(w) - target) and projects
onto the unit simplex afterwards.
Sourcepub fn apply_constraints(
weights: &mut Vec<f64>,
constraints: &[OptimizationConstraint],
)
pub fn apply_constraints( weights: &mut Vec<f64>, constraints: &[OptimizationConstraint], )
Apply constraints to a weight vector (projection onto constraint set).
Sourcepub fn maximize_sharpe(
returns: &[f64],
cov: &[Vec<f64>],
rf_rate: f64,
constraints: &[OptimizationConstraint],
) -> OptimizationResult
pub fn maximize_sharpe( returns: &[f64], cov: &[Vec<f64>], rf_rate: f64, constraints: &[OptimizationConstraint], ) -> OptimizationResult
Maximize Sharpe ratio via gradient ascent.
Iterates gradient ascent on the Sharpe ratio objective:
(Return(w) - rf) / Volatility(w).
Sourcepub fn minimize_variance(
returns: &[f64],
cov: &[Vec<f64>],
target_return: f64,
constraints: &[OptimizationConstraint],
) -> OptimizationResult
pub fn minimize_variance( returns: &[f64], cov: &[Vec<f64>], target_return: f64, constraints: &[OptimizationConstraint], ) -> OptimizationResult
Minimize portfolio variance subject to a target return.
Sourcepub fn efficient_frontier(
returns: &[f64],
cov: &[Vec<f64>],
n_points: usize,
rf_rate: f64,
) -> Vec<EfficientFrontierPoint>
pub fn efficient_frontier( returns: &[f64], cov: &[Vec<f64>], n_points: usize, rf_rate: f64, ) -> Vec<EfficientFrontierPoint>
Generate the efficient frontier by sweeping target returns.
Produces n_points EfficientFrontierPoint values spanning the range
from the minimum expected return to the maximum expected return.