<a id="skfolio-utils-stats-minimize-relative-weight-deviation"></a>

# skfolio.utils.stats.minimize_relative_weight_deviation

<a id="skfolio.utils.stats.minimize_relative_weight_deviation"></a>

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

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

$$
\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}

$$

* **Parameters:**
  **weights** *ndarray of shape (n_assets,)*
  : Strictly positive initial weights summing to one.

  **min_weights** *ndarray of shape (n_assets,)*
  : Minimum assets weights (weights lower bounds).

  **max_weights** *ndarray of shape (n_assets,)*
  : Maximum assets weights (weights upper bounds).

  **solver** *str, 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](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver)

  **solver_params** *dict, 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](https://www.cvxpy.org/tutorial/advanced/index.html#setting-solver-options)

