Let $n \in \Bbb N,M \geq 0$ be constants,$( \Omega,\mathcal A,P)$ be a probability space, $Y : \Omega \to \{0,1,\dots ,n\}$ a random variable and $X_1,\dots, X_n : [-M,M]$ random variables with: (i) $Y,X_1,\dots, X_n$ are stochastically independent, (ii) $E(X_1) = E(X_i) \text{for} i = 1,\dots,n$. Show that $$S(\omega) := \sum _{i=1}^{Y(\omega)} X_i(\omega)$$ is a square-integrable random variable in $L^2(\Omega,\mathcal A, P)$
Attempt: To show that $( S(\omega) : = \sum_{i=1}^{Y(\omega)} X_i(\omega) )$ is a square-integrable random variable in $( L^2(\Omega, \mathcal{A}, \mathbb{P}) )$, we need to check that the expected value of the square of $( S(\omega) )$ is finite, i.e. $( \mathbb{E}[S^2] < \infty )$.
Expected value of $ S(\omega) $: $ \mathbb{E}[S] = \mathbb{E}\left[\sum_{i=1}^{Y} X_i\right]. $
Since $ Y $ and the $ X_i $ are stochastically independent, we can exchange the sum for the expected value: $ \mathbb{E}[S] = \mathbb{E}\left[\sum_{i=1}^{Y} X_i\right] = \mathbb{E}[Y] \cdot \mathbb{E}[X_1] $
To show that $ S $ is square-integrable, we consider $ \mathbb{E}[S^2] :$
$$ S^2 = \left(\sum_{i=1}^{Y} X_i\right)^2 = \sum_{i=1}^{Y} X_i^2 + 2 \sum_{1 \leq i < j \leq Y} X_i X_j$$
Expected value of $S^2$: Due to stochastic independence, the following applies:
$$ \Bbb E [S^2] = \Bbb E \left[\left(\sum_{i=1}^{Y} X_i\right)^2\right] = \Bbb E \left[ \sum_{i=1}^{Y} X_i^2\right] + 2 \Bbb E \left[ \sum_{1 \leq i < j \leq Y} X_i X_j \right]$$
Now we use the fact that $X_i $ are stochastically independent and identically distributed: $$ \mathbb{E}[S^2] = \mathbb{E}[Y] \mathbb{E}[X_1^2] + 2 \mathbb{E}\left[\binom{Y}{2}\right] \mathbb{E}[X_1]^2$$ $$ \mathbb{E}\left[\binom{Y}{2}\right] = \frac{1}{2} \mathbb{E}[Y(Y-1)] $$.
To ensure that $ \mathbb{E}[S^2] $ is finite, $ \mathbb{E}[X_1^2] $ and $ \mathbb{E}[Y^2] $ must be finite: $$ \mathbb{E}[S^2] = \mathbb{E}[Y] \mathbb{E}[X_1^2] + \mathbb{E}[Y(Y-1)] \mathbb{E}[X_1]^2. $$ Since $ \mathbb{E}[X_1^2] < \infty (\text{because} X_1 $ is square-integrable) and $\mathbb{E}[Y^2] < \infty $ (because $ Y$ is a random variable and is assumed to be in a finite range), it follows that $ \mathbb{E}[S^2] < \infty $.
We have thus shown that $ S(\omega) $ is a square-integrable random variable in $ L^2(\Omega, \mathcal{A}, \mathbb{P}) $.