QuadraticOptimizer

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

Bases: object

Class used for optimizing quadratic problems.

Methods

get_optimal_weights(P, q, upper_constraints, …)

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

classmethod get_optimal_weights(P: numpy.ndarray = None, q: numpy.ndarray = None, upper_constraints: Union[Sequence, float] = None) → numpy.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