0
在R,我模擬變量以下維納過程。R:矩陣誤差
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
是一個真實的,例如, 0.23 ret
是一個真正的太
錯誤似乎是在該行: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)
你怎麼想,我們重現這個錯誤? – Arun 2013-03-08 14:33:08
我們需要重現的例子。 – 2013-03-08 14:34:53
@Henri相當肯定是'dz','ivol','dt'或'ret'是走出來是矢量,而不是單一的價值在你的計算。 – 2013-03-08 14:36:54