Skip to main content

MeanVarianceOptimizer

Struct MeanVarianceOptimizer 

Source
pub struct MeanVarianceOptimizer;
Expand description

Mean-variance portfolio optimizer using gradient descent.

Implementations§

Source§

impl MeanVarianceOptimizer

Source

pub fn portfolio_return(weights: &[f64], returns: &[f64]) -> f64

Compute expected portfolio return: dot product of weights and returns.

Source

pub fn portfolio_variance(weights: &[f64], cov: &[Vec<f64>]) -> f64

Compute portfolio variance: w^T Σ w.

Source

pub fn portfolio_volatility(weights: &[f64], cov: &[Vec<f64>]) -> f64

Compute portfolio volatility: sqrt(w^T Σ w).

Source

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.

Source

pub fn apply_constraints( weights: &mut Vec<f64>, constraints: &[OptimizationConstraint], )

Apply constraints to a weight vector (projection onto constraint set).

Source

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).

Source

pub fn minimize_variance( returns: &[f64], cov: &[Vec<f64>], target_return: f64, constraints: &[OptimizationConstraint], ) -> OptimizationResult

Minimize portfolio variance subject to a target return.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.