So that's more Maple related question but I'll give it a try. Assume we have portfolio $$S_N=X_1+\dots+X_N$$ Where $X\sim Poi(5)$ and $N\sim Bin(60,1/2)$. We want to study the distribution of $S_N$. One way to do this is to use the PGF of $X$ and $N$. Then the PGF of $S_N$ is given by $$P_{S_N}(t)=P_N(P_X(t))$$ And to get the distribution of $S_N$ we just need to expand the $P_{S_N}(t)$ in Taylor series. Now - since I'm new to using Maple I struggled with this a bit but eventually end up with a decent plot of this distribution.
My next problem is to generate a sample of size $50$ from that distribution. I've read the documentation of $Sample$ function but it didn't help at all. In $R$ for example the task is trvial since I have the array of the probabilities from the Taylor expansion I just type $Sample(Array,50)$ and that's it. Is there an analogous way to do that in Maple?
By integrating out the binomial random variable in the joint distribution, we obtain the marginal of the sum: $$P(S_N=m)=P\bigg(\sum_{n=1}^NX_n=m\bigg)=\sum_{k=0}^MP\bigg(\sum_{n=1}^kX_n=m\bigg|N=k\bigg)P(N=k)$$ The sum of $k$ Poisson distributed , independent random variables with same parameter $\theta$ is Poisson with parameter $\theta k$. So $$P(S_N=m)=\sum_{k=0}^M\frac{(\theta k)^me^{-\theta k}}{m!}P(N=k)=\sum_{k=0}^M\frac{(\theta k)^me^{-\theta k}}{m!}\binom{M}{k}p^k(1-p)^{M-k}$$ To generate a sample from this one, generate a binomial RV $k$ and then generate $k$ Poisson distributed RVs and then sum them.