Covariance of random sums How can I compute
$$cov(\sum^N a_k,\sum^{N'}a_k)$$
where $N$, $N'$ are random dependent variables and $a_k$ iid random variables , as a function of (but not necessarily)  cov(N,N'), $var(N)$, $var(N')$, $var(a_k)$ and all of their expectation value ?
$N$ and  $N'$ are bounded and positive.
My best shot :
\begin{equation}
\begin{split}
    cov(X,Y)&=cov(\sum^Na_k,\sum^{N'}a_k)\\
    &=cov(\sum\mathbb{1}_{k<N}a_k,\sum\mathbb{1}_{k<N'}a_k)\\
    &=cov(\sum\mathbb{1}_{k<N}a_k,\sum\mathbb{1}_{k<N'}a_k)\\
    &=\sum\sum cov(\mathbb{1}_{k<N}a_k,\mathbb{1}_{k'<N'}a_{k'})\\
    &=\sum\sum \mathbb{1}_{k<N\cap k'<N'}cov(a_k,a_{k'})\\
    &=\sum \mathbb{1}_{k<\min(N,N')}var (a_k)\\
    &=\min(N,N')var(a)
\end{split}
\end{equation}
Feels wrong, is the 4th step right ? I use bilinearity on infinite sums, moreover if $N$ and $N'$ were constants the same method would have worked so...
Thank you

Law of total covariance (wiki) helps here. What you found is when $N$ and $N'$ are given:
$$\operatorname{cov}(X,Y|N,N')=\operatorname{var}(a)\min(N,N')$$
$$\mathbb E[X|N,N']=N\mathbb E[a], \ \ E[Y|N,N']=N'\mathbb E[a]$$
Plugging in gives us:
$$\operatorname{cov}(X,Y)=\operatorname{var}(a)\mathbb E[\min(N,N')]+\mathbb E[a]^2\operatorname{cov}(N,N')$$
I'm not sure how you can simplify the expected value of the minimum.
