skfolio.utils.stats.minimize_relative_weight_deviation#

skfolio.utils.stats.minimize_relative_weight_deviation(weights, min_weights, max_weights, solver='CLARABEL', solver_params=None)[source]#

Apply weight constraints to an initial array of weights by minimizing the relative weight deviation of the final weights from the initial weights.

\[\begin{split}\begin{cases} \begin{aligned} &\min_{w} & & \Vert \frac{w - w_{init}}{w_{init}} \Vert_{2}^{2} \\ &\text{s.t.} & & \sum_{i=1}^{N} w_{i} = 1 \\ & & & w_{min} \leq w_i \leq w_{max}, \quad \forall i \end{aligned} \end{cases}\end{split}\]
Parameters:
weightsndarray of shape (n_assets,)

Initial weights.

min_weightsndarray of shape (n_assets,)

Minimum assets weights (weights lower bounds).

max_weightsndarray of shape (n_assets,)

Maximum assets weights (weights upper bounds).

solverstr, default=”CLARABEL”

The solver to use. The default is “CLARABEL” which is written in Rust and has better numerical stability and performance than ECOS and SCS. For more details about available solvers, check the CVXPY documentation: https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver

solver_paramsdict, optional

Solver parameters. For example, solver_params=dict(verbose=True). The default (None) is to use the CVXPY default. For more details about solver arguments, check the CVXPY documentation: https://www.cvxpy.org/tutorial/advanced/index.html#setting-solver-options