# Calculate control variate for monte carlo simulation

For an exercise I need to calculate $\mathbb{E}[X]$ with a Monte Carlo simulation. I need to use control variate $Y$ with $\text{Var}(Y)=2$ and $\text{Cov}(X,Y)=1$.

I am asked to give the optimale choice for $\theta$ in the following formula:

$Z_{\theta}=X+\theta(\mathbb{E}[Y]-Y)$ by making the variance of the stochast $Z_{\theta}$ as small as possible.

I assume you start by rewriting $\text{Var}(Z_{\theta})$, this is what I did:

$\text{Var}(X+\theta(\mathbb{E}[Y]-Y))$

$=\text{Var}(X)+\text{Var}(\theta(\mathbb{E}[Y]-Y)) + 2\text{Cov}(X,\theta(\mathbb{E}[Y]-Y))$

$= \text{Var}(X) +\theta^2\text{Var}(\mathbb{E}[Y]-Y) +2\theta \text{Cov}(X,\mathbb{E}[Y]) -2\theta\text{Cov}(X,Y)$

$= \text{Var}(X) +\theta^2\text{Var}(\mathbb{E}[Y]) +\theta^2\text{Var}(Y) -\theta^2\text{Cov}(\mathbb{E}[Y], Y) +2\theta \text{Cov}(X,\mathbb{E}[Y]) -2\theta\text{Cov}(X,Y)$

Since I can't rewrite the formula any further, I inserted the variables. This gave:

$= \text{Var}(X) +\theta^2\text{Var}(\mathbb{E}[Y]) +2 \theta^2 -\theta^2\text{Cov}(\mathbb{E}[Y], Y) +2\theta \text{Cov}(X,\mathbb{E}[Y]) -2\theta$

I don't know however how to go on from here, without the value of $\mathbb{E}[X]$. Am I doing something wrong?

The first objective is to minimize the variance by choosing a proper control variate.

First note that an expectation value is just a constant, so the covariance between an expectation value and a random variable is zero:

$$\text{Cov}\left(\mathbb{E}[Y], X\right) = 0$$

Similarly for the variance of an expectation value, $\text{Var}(\mathbb{E}[Y])=0$. The variance of $Z_{{\theta}}$ is therefore given by

$$\text{Var}(\mathbb{E}[Z_{{\theta}}]) = \text{Var}(\mathbb{E}[X])+2\theta^2 - 2\theta$$

You don't need to know what this variance is. What you are interested in is picking a $\theta$ such that this variance is as low as possible. Put differently, you want to minimize this variance which is accomplished by setting the derivative with respect to $\theta$ equal to zero. The derivative is given by

$$\frac{d\text{Var}(\mathbb{E}[Z_{\theta}])}{d\theta} = 4\theta -2$$

Setting this to zero gives $\theta = \frac{1}{2}$.

So now you have determined the optimal $\theta$. Next, you need to run a Monte Carlo simulation and simulate $X$ and $Y$ consistently. From these simulations you can estimate $\mathbb{E}[Y]$ using the sample mean of $Y$ (or, better, the true mean if you happen to know this analytically). With this expectation you can construct the variable $Z_{\theta}$ with $\theta = 1/2$ for each of your $N$ simulations.

Finally, you compute the sample mean of $Z_{\theta}$, which is an estimate of the expectation value of $X$.