The minimizing problem is the following : $$ \underset{w}{\operatorname{argmin}} \sum_{i=1}^{n}\left[w_{i}\times (\frac{Vw}{\sigma})_{i} - b_{i}\right]^{2}$$ with $V$ a $n\times n$ matrix (covariance matrix) which depends on the vector $w$ of size $n$, $\sigma$ is a scalar which is equal to $\sigma = \sqrt{w^\top Vw}$.
For $i=1,\ldots,n$, the quantity $w_{i}\times\left(\frac{Vw}{\sigma}\right)_{i}$ has a meaning in finance and I want the vector to be as close as possible to the target vector $b$. That's why I am minimizing this function.
I have a function that uses scipy.minimize to solve this problem and it returns the optimal weights $\tilde{w}=(w_{i})$ of a portfolio of 500+ stocks. However, some of these weights are very low and I would like the weights $w_{j}$ that are under a certain thresold $\rm thr$ to be set to 0.
One way to have this would be to run my function, then manually set such weights to 0 with if conditions, and finally rescale the weights so the sum equals one. The problem with this method is that the final vector $w$ will not be the optimal vector $\tilde{w}$ anymore.
Do you know any way to minimize a function while having such conditions ?