In R, I'm simulating variable following a Wiener process.
mcsim <- function(drift, dt, spot, spotdate, nap, maturity, sim)
{
for(n in 1:sim)
{
for(i in 1:maturity)
{
dz = rnorm(1, mean=0, sd=1);
ivol = findnap(spot[i,n], spotdate[i], nap)
ret = (drift-(ivol^2)/2)*dt+ivol*sqrt(dt)*dz;
spot[i+1,n] = spot[i,n]*exp(ret);
#display counter
cat(n/sim, "% of 100% \r");
#flush.console()
}
}
return(spot);
}
ivol
is a real, e.g. 0.23
ret
is a real too
the error seems to be in the line : spot[i+1,n] = spot[i,n]*exp(ret);
>Error in FR : le nombre d'objets à remplacer n'est pas multiple de la taille du remplacement
>Error in EN : the number of objects that must be replaced is not a multiple of the size of the replacement. (sorry for the rough translation)