# First two moments of a quadratic form in which the vector and matrix are random (though independent)

$\DeclareMathOperator\tr{\mathrm{tr}}$Let $x$ be a standard normal $p$-variate random variable, which is independent of a symmetric positive definite random matrix $Y$. I would like to compute the mean and variance of the quadratic form $x^TYx$.

If $Y$ were not a random variable, then we could argue that the fact that quadratic forms are diagonalizable means that without the loss of generality we can assume that $Y$ is a diagonal matrix. And an entry-by-entry computation shows that the mean will be $\tr(Y)$ with variance $2 \tr(Y)$.

But if $Y$ is a random variable, I'm not sure it's so easy since though the mean is still $\tr(\mathbb{E}[Y])$, the variance of each entry now depends on $Y$ in a more complicated way, and since diagonalizing changes the diagonal entries in non-trivial ways, is it no longer possible to relate the variance to the trace of $Y$ or a related expression?

$$\DeclareMathOperator\E{\mathbb E} \DeclareMathOperator\tr{\mathrm{tr}} \DeclareMathOperator\Cov{\mathrm{Cov}} \DeclareMathOperator\Var{\mathrm{Var}}$$ Using trace rotation and the commutivity of linear operators: \begin{align} \E[x^T Y x] &= \E[\tr(x^T Y x)] \\&= \E[\tr(Y x x^T)] \\&= \tr(\E[Y x x^T]) \\&= \tr(\E[Y] \E[x x^T]) \\&= \tr(\E[Y]) .\end{align}
This Wikipedia page or this math.SE answer tell us, slightly disagreeing with what you said, that for normal $$x$$ and symmetric $$Y$$ $$\Var[x^T Y x \mid Y] = 2 \tr(Y Y).$$ Then via the law of total variance, for random $$Y$$ we have \begin{align} \Var(x^T Y x) &= \E_Y \Var_x(x^T Y x \mid Y) + \Var_Y( \E_x[x^T Y x \mid Y] ) \\&= \E[ 2 \tr( Y^2 ) ] + \Var( \tr(Y \E[x x^T])) \\&= 2 \tr(\E[ Y^2 ]) + \Var(\tr(Y)) .\end{align}