I want to simulate a jump-diffusion process with compound Poisson jumps and a deterministic jump frequency function $\lambda(t)$.
The function should follow the following stochastic differential equation:
$$dS_t = \mu S_tdt+\sigma S_tdW_t+dJ$$
While $dJ = z$ with probability $d\lambda_t$ and $dJ = 0$ with probability $1-d\lambda_t$ and $z\sim N(0,1)$
According to Glasermann's book, I can simulate directly from this expression $$S(t_i+1)=S(t_i)e^{(\mu-1/2\sigma^2)(t_{i+1}-t_i)+\sigma[W(t_{i+1})-W(t_i)]}\prod_{N(t_i)+1}^{N(t_{i+1})}J_j$$
However this is giving me weird results, so something must be wrong in either my understanding or my code.
S0 = 100
sigma = 0.2
mu=0.05
n = 1000
T=20
dt=1
m=dt*T
alpha=0.5
beta=m/2
KA=50
lambda <- function(t) return(KA/(1+exp(-alpha*(t-beta))))
S <- matrix(NA, nrow = n, ncol = m)
S[,1]=S0
for (i in 1:n){
for(t in 1:(m-1)){
nJ=rpois(1,(integrate(lambda,lower= t, upper= t+dt)$value)) # number of jumps in (t+dt-t)
if(nJ!=0){
M<-vector(mode="double", length = nJ)
M[]=rnorm(nJ, mean = 0, sd = 1) #vector with jump size for each jump time
}
S[i,t+1]=S[i,t]*exp((mu-1/2*sigma^2)*(dt)+sigma*sqrt(dt)*rnorm(1, mean = 0, sd = 1))*prod(M)
}
}
plot(S[1,])
Also, I don't understand why jumps are multiplicative and not additive. I'd really appreciate your help, as I am obviously not an expert on financial mathematics.