Compile
- To: mathgroup at smc.vnet.net
- Subject: [mg48302] Compile
- From: "John" <john34 at sepei.com>
- Date: Sat, 22 May 2004 03:04:35 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi, 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 code: 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++]; sumct/(M*Exp[-r*T])]]; TIA John
- Follow-Ups:
- Re: Compile
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Compile