# Martingale and mean squared error

In preparation for a course I am doing later in the semester I have been trying to brush up on my knowledge about martingales. But I am struggling with the following problem:

Let $X,Y_1,Y_2,Y_3,\ldots$ be any sequence of random variables, with $\mathbb{E}[|X|]<\infty$. Suppose we wish to predict $X$ based on $Y_1,\ldots,Y_n$, using $W_n=g_n(Y_1,\ldots,Y_n)$ for some $g_n:\mathbb{R}^n\rightarrow\mathbb{R}$.

(a) Which $W_n$ minimizes the mean squared error, $\mathbb{E}[(X-W_n)^2]$? Hint: You could prove first that $\mathbb{E}[(X-W_n)^2]=\mathbb{E}[(X-Z_n)^2]+\mathbb{E}[(Z_n-W_n)^2]$, where $Z_n=\mathbb{E}[X|Y_1,\ldots Y_n]$.

(b) Show that $\{Z_n,n\geq 1\}$ is a martingale.

What I have done so far: With (a) I am really struggling I don't really understand the hint and how to proceed.

For part (b) I know that a stochastic process $\{Z_n,n\geq 1\}$ is said to be a martingale process if for all $n$:

(i) $\mathbb{E}[|Z_n|]<\infty$, and

(ii) $\mathbb{E}[Z_{n+1}|Z_1,\ldots,Z_n]=Z_n.$

For part (ii) I can write \begin{align} \mathbb{E}[Z_{n+1}|Z_1,\ldots,Z_n] &= \mathbb{E}[\mathbb{E}[X|Y_1,\ldots Y_{n+1}]|Z_1,\ldots,Z_n] \\ &= \mathbb{E}[\mathbb{E}[X|Y_1,\ldots Y_{n+1},Z_1,\ldots,Z_n]|Z_1,\ldots,Z_n] \\ &= \mathbb{E}[X|Z_1,\ldots Z_n] \\ &= \mathbb{E}[X|Y_1,\ldots Y_n] \\ &= Z_n. \end{align} Here I made use of the tower property. Is this part correct? How do I go about showing part (i)? Any help would be much appreciated.

(a) The hints gives $$\mathbb E[(X-W_n)^2]\geqslant \mathbb E[(X-Z_n)^2],$$ and the equality is reached if and only if $\mathbb E[(Z_n-W_n)^2]=0$.
(b) (i) If $X$ is an integrable random variable, using Jensen's inequality, $|\mathbb E[X\mid\mathcal G]|\leqslant \mathbb E[|X|\mid\mathcal G]$ for any $\sigma$-algebra $\mathcal G$. Since $\mathbb E[\mathbb E[|X|\mid\mathcal G]]=\mathbb E|X|$, $E[X\mid\mathcal G]$ is integrable.