QuadraticOptimizer#

class qf_lib.portfolio_construction.optimizers.quadratic_optimizer.QuadraticOptimizer[source]#

Bases: object

Class used for optimizing quadratic problems.

classmethod get_optimal_weights(P: ndarray = None, q: ndarray = None, upper_constraints: Sequence | float = None) ndarray[source]#

Solves the problem defined by matrix h, vector f and constraints.

Parameters:
  • P – a square matrix from the quadratic formula

  • q – a vector (can be empty) from the quadratic formula

  • upper_constraints – vector of upper limits of weights (if it’s a single value, the constraint will be the same for each weight). Example: 0.5 means that max allocation of some asset can be 50%.

Returns:

best weights for the given problem. Sum of all weights is equal 1.

Return type:

weights