# Constrained mean variance optimization

I have some numbers $X={x_1,x_2,...,x_n}$. I add some small numbers to them and get $Y={y_1,y_2,...,y_n}$ where $y_i=x_i+\epsilon_i$. How can I find $Z={z_1,z_2,...,z_n}$ to minimize $\sum_{i=1}^n(z_i-y_i)^2$ such that $\hat{\text{mean}}(Z)=\hat{\text{mean}}(X)$ and $\hat{\text{var}}(Z)=\hat{\text{var}}(X)$. I have solved it for the simple case of $\hat{\text{mean}}(X)=0$ and $\hat{\text{var}}(X)=1$. However, the computation is too long for the general case. I wonder if there exist more statistical (hopefully shorter) version of the solution.

Regards

PS: $x_i\in R$

• why not just set $z_i = x_i$ and then $\sum_{i=1}^n(z_i-x_i)^2=0$? – Glen_b -Reinstate Monica May 26 '13 at 8:37
• And if that's not a suitable answer ... you might ponder what essential piece of information you omitted. – Glen_b -Reinstate Monica May 26 '13 at 8:59
• Thank you for reply. It was a bad mistake. I edited the question. – remo May 26 '13 at 11:53

Here is how:

• Define:

$$y^*_i=\frac{y_i-\hat{\text{mean}}(X)}{\sqrt{\hat{\text{var}}(X)}}$$

• solving your minimization problem for the $z^*_i$'s yields:

$$z^*_i=\frac{y_i-\hat{\text{mean}}(y)}{\sqrt{\hat{\text{var}}(y)}}$$

• transform your $z_i^*$'s back:

$$z_i=z_i^*\sqrt{\hat{\text{var}}(X)}+\hat{\text{mean}}(X)$$

putting it back together

$$z_i=(y_i-\hat{\text{mean}}(y))\frac{\sqrt{\hat{\text{var}}(x)}}{\sqrt{\hat{\text{var}}(y)}}+\hat{\text{mean}}(x)$$

• Thank you for your help. It is the correct answer for the problem. However, I wonder if I change the objective function to Minimize $\sum_{i=1}^n ((z_i-y_i)/y_i)^2$, can I use the same solution? – remo May 26 '13 at 12:12
• I'm not sure the formulation you propose is the same as mine. Wouldn't dividing by $y_i$ be problematic when $y_i\approx 0$? – user603 May 26 '13 at 12:15
• I add an exception for the case of $y_i=0$. I really need the solution. for the last problem, it took me about two days (!) to solve it (using lagrangian method). I don't want another two days for the similar case if there exist a simpler one. I hope you can help me. – remo May 26 '13 at 12:20
• Anyway. If as you wrote in your question, you have already solved it for mean(x)=0 and var(x)=1; just use the third part of my answer to see that you have then solved it for any values of mean(x) and var(x)! – user603 May 26 '13 at 12:25