# Homework about compound random variable

this is an homework but i really tried hard before surrender, and i think that or I'm very close to the end or I'm as far as possibile.. That's the text:

Let $X_1, X_2, ..., X_n$ be independent and identically distributed random variables. And N is a nonnegative integer valued random variable (indipendent to any $X_i$).

Let $Z = \Sigma_{i=1}^NX_i$ calculate $Cov(N,Z)$.

What I have done:

I know that $Cov(N,Z) = E[NZ] -E[N]E[Z]$

What i've done is try to get $E[NZ] = E[\Sigma_{i=1}^N X_i N] =$

$= \Sigma_{n=0}^{\infty} E[\Sigma_{i=1}^N X_i N | N=n] P(N=n)$ =

$= \Sigma_{n=0}^{\infty} E[n\Sigma_{i=1}^n X_i]P(N=n) =$

$= \Sigma_{n=0}^{\infty} n E[\Sigma_{i=1}^n X_i]P(N=n) =$

As $X_i$ is iid with any other $X_j$ i use only $X_1$

$=\Sigma_{n=0}^{\infty} nE[\Sigma_{i=1}^n X_1]P(N=n) =$

$=\Sigma_{n=0}^{\infty} n^2 X_1 P(N=n) = X_1\Sigma_{n=0}^{\infty} n^2 P(N=n)$

I know that $\Sigma_{n=0}^{\infty} n P(N=n) = E[N]$ but what about $=\Sigma_{n=0}^{\infty} n^2 P(N=n)$.

Thank you

-
$E[N^2]=\sum_{n=0}^{\infty} n^2 P(N=n)$. By the way, your end result for $E[NZ]$ should contain $E[X_1]$ not just $X_1$. – Raskolnikov Oct 22 '11 at 10:04
O was just THAT simple! How stupid I am.. Thank you!!! – Fabio F. Oct 22 '11 at 10:26
+1 for showing your work. // As @Raskolnikov said, $E[\sum\limits_{i=1}^nX_i]=nE[X_1]$ and not $nX_1$. – Did Oct 22 '11 at 10:27
Also see the law of total covariance on the wiki. – Sasha Oct 22 '11 at 14:06

$Cov(N,Z) = E[NZ] -E[N].E[Z]$
$= E[N.E[Z|N]] - E[N].E[E[Z|N]]$
$= E[N^2.E[X_1]] - E[N].E[N.E[X_1]]$
$= (E[N^2]- E[N]^2 ). E[X_1]$
$= Var(N) E[X_1]$