Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simulateJump=function(mu_,ss_,lambda_,mu2_,sigma_,TotalTime,delta)
{
Sn=0
times <- c(0)
while(Sn <= TotalTime)
{
n <- length(times)
u <- runif(1)
expon <- -log(u)/lambda_
Sn <- times[n]+expon
times <- c(times, Sn)
}
times=times[-length(times)]
t=seq(from=0,to=TotalTime,by=delta)
#the last time is beyond TotalTime, so i delete from the vector times
indicator=seq(from=0,to=0,length=length(t)) # if there are jumps or not between two times
jumpSize=seq(from=0,to=0,length=length(t)) # stores the size of the jump
for(m in 2:length(times))
{
for(k in 2: length(t))
{
if( t[k-1]<=times[m] && times[m]<=t[k])
{
indicator[k]=1
jumpSize[k]=rnorm(1,mean=mu2_,sd=sigma_)
}
}
}
stock=seq(from=0,to=0,length=length(t))
stock[1]=10
for(i in 2:length(t))
{
stock[i]=stock[i-1]+(mu_)*delta+ss_*sqrt(delta)*rnorm(1)+jumpSize[i]*indicator[i]
}
final=cbind(t,stock,jumpSize,indicator)
return(final)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.