Suppose I have some dataset $X = \{x_1, x_2, \ldots, x_n\}$ which has a mean $\bar{X}$ and a standard deviation $\sigma_X$. Now, suppose that I want to trim the tails of the dataset such that the new average is $\bar{X}_d$ with new standard deviation $\sigma_{X_d}$. In other words, I want to remove the tail points in the dataset such that the new average of $X$ is approximately $\bar{X}_d$ with a new standard deviation of approximately $\sigma_{X_d}$.
Is there a way to formulate some (convex) optimization problem to accomplish this? Basically, the optimization objective might be to find the threshold value $x_i$ which seperates the dataset. I was thinking of this kind of formulation:
$$\min \|\bar{X} - \bar{X}_d\|+ \|\sigma_{X}^2 - \sigma_{X_d}^2\|$$
But not sure how to formulate this with optimization variables.