I need to simulate a compound Poisson Process in R, however I am not clear with the algorithm to generate it. I have conceptual gaps.
I know by definition that: A compound Poisson process is the process: $$Z_t=\sum_{i=0}^{N_t}X_i$$ where $X_i$ are i.i.d random variables with a specific distribution. In my case I consider Weibull random variables with shape parameter $\tau$ and scale parameter $k$.
According to my self-study I know that $N_t$ should be a Poisson Process. Also, I know according to the theory that, the interarrival times of a Poisson process follows a exponential distribution with parameter $\lambda$. With these facts, my algorithm proposed is the next one.
i)$t=0$ and generate a random number that follows a Poisson distribution with parameter $\lambda t$
ii) Generate $n$ Weibull random variables $X_i$, $i=0,...,n$, with $X_0=0$
iii)Generate $n$ interarrival times ($E_i$) exponential random variables with rate $lambda$.
iv) Generate the vector $T=(0,E_1,E_1+E_2,....,E_1+E_2+...+E_n)$, in this way I would get the arrival times.
v) Now, for every $t\in T$ I can generate the Variable $Z_t=\displaystyle\sum_{i=0}^{N_t} X_i$
vi) $t=t+1$ and start again.
but, I am confused. First, If I generate at the beginning the Poisson random number, according this algorithm for every step I would get different $X_i$ that is not that I want, because I need the same $X_i$ (in the context that I am study it represents random losses)
Also, If I follow this algorithm, I think that for every step I would get different interarrival times and also this is not desired.
I have seen some algorithms on internet deffining a tmax and then generate the poisson random number, but I am very confused.
The lambda of the interarrival times is the same of the Poisson random variable? I am not clear with it too.
arrivaltimes <- c (0); # Array of arrival times
cumtime <- rexp (1, lambda_arr ); # Time of next arrival
level <- c (0); # Level of the compound Poisson process
while ( cumtime < maxtime )
{
arrivaltimes <- c( arrivaltimes , cumtime );
# Draw a new jump from the Weibull dsitribution distribution
# and add it to the level .
oldLevel <- level [ length ( level )];
newLevel <- oldLevel + rweibull(1 ,scale = scale_loss,shape=shape_loss);
level <- c(level , newLevel );
# Draw a new interarrival time and add it
# to the cumulative arrival time
cumtime <- cumtime + rexp (1, lambda_arr );
}
S<-arrivaltimes
Z<-level# level is the vector that is the sum of random loss(Weibull)