Skip to content

MinimumVariancePortfolioOptimizer

QuantConnect.Algorithm.Framework.Portfolio.MinimumVariancePortfolioOptimizer

MinimumVariancePortfolioOptimizer(
    lower: float = -1,
    upper: float = 1,
    target_return: float = 0.02,
)

Bases: Object, IPortfolioOptimizer

Provides an implementation of a minimum variance portfolio optimizer that calculate the optimal weights with the weight range from -1 to 1 and minimize the portfolio variance with a target return of 2%

Initialize a new instance of MinimumVariancePortfolioOptimizer

Parameters:

Name Type Description Default
lower float

Lower bound

-1
upper float

Upper bound

1
target_return float

Target return

0.02

get_boundary_conditions

get_boundary_conditions(
    size: int,
) -> Iterable[LinearConstraint]

Boundary constraints on weights: lw ≤ w ≤ up

This codeEntityType is protected.

Parameters:

Name Type Description Default
size int

number of variables

required

Returns:

Type Description
Iterable[LinearConstraint]

enumeration of linear constaraint objects.

get_budget_constraint

get_budget_constraint(size: int) -> Any

Sum of all weight is one: 1^T w = 1 / Σw = 1

This codeEntityType is protected.

Parameters:

Name Type Description Default
size int

number of variables

required

Returns:

Type Description
Any

linear constaraint object.

optimize

optimize(
    historical_returns: List[float],
    expected_returns: List[float] = None,
    covariance: List[float] = None,
) -> List[float]

Perform portfolio optimization for a provided matrix of historical returns and an array of expected returns

Parameters:

Name Type Description Default
historical_returns List[float]

Matrix of annualized historical returns where each column represents a security and each row returns for the given date/time (size: K x N).

required
expected_returns List[float]

Array of double with the portfolio annualized expected returns (size: K x 1).

None
covariance List[float]

Multi-dimensional array of double with the portfolio covariance of annualized returns (size: K x K).

None

Returns:

Type Description
List[float]

Array of double with the portfolio weights (size: K x 1).