MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive



i am new to mathematica, i have written a monte carlo simulation for an
option, I wanted to compile the function, but i just get errors concerning
the Random[NormalDistribution[0,1]] function, could anybody help, thats the

MCCall=Compile[{{S, K, T, r, div, sig},{M, _Integer},{ N, _Integer}}],
Module[{dt, nudt, sigsdt, lns, sumct, i, j, lnst, st, ct},
dt = T/N;
nudt = (r - div - 0.5*sig^2)*dt;
sigsdt = sig*Sqrt[dt];
lns = Log[S];
sumct = 0;
i = 1;
j = 1;
a = {};
For[i = 1, i < M,
lnst = lns;
For[j = 1, j < N,
lnst = lnst + nudt + sigsdt*Random[NormalDistribution[0, 1]]; j++];
st = Exp[lnst];
ct = Max[0, (st - K)];
sumct = sumct + ct;
a = Append[a, sumct/(i*Exp[-r*T])]; i++];

TIA John

  • Prev by Date: Re: padding numbers in front of uniquely generatd names
  • Next by Date: Re: Removing brakets of a list
  • Previous by thread: Re: Fractal Geometry--> Levy Flights
  • Next by thread: Re: Compile