Skip to content

MaximumSharpeRatioPortfolioOptimizer

QuantConnect.Algorithm.Framework.Portfolio.MaximumSharpeRatioPortfolioOptimizer

MaximumSharpeRatioPortfolioOptimizer(
    lower: float = -1,
    upper: float = 1,
    risk_free_rate: float = 0.0,
)

Bases: Object, IPortfolioOptimizer

Provides an implementation of a portfolio optimizer that maximizes the portfolio Sharpe Ratio. The interval of weights in optimization method can be changed based on the long-short algorithm. The default model uses flat risk free rate and weight for an individual security range from -1 to 1.

Initialize a new instance of MaximumSharpeRatioPortfolioOptimizer

Parameters:

Name Type Description Default
lower float

Lower constraint

-1
upper float

Upper constraint

1
risk_free_rate float
0.0

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