MathGroup Archive 2004

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

Search the Archive

Re: Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48353] Re: Compile
  • From: "John" <john34 at sepei.com>
  • Date: Tue, 25 May 2004 07:17:23 -0400 (EDT)
  • References: <200405220704.DAA08873@smc.vnet.net> <c8pu67$kqv$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Andrzej,

Thanx a lot for you guidance,in particular for mentioning the post
concerning random, I think i ll have to dig deeper into mathematica
programming.

Greetings John

"Andrzej Kozlowski" <akoz at mimuw.edu.pl> schrieb im Newsbeitrag
news:c8pu67$kqv$1 at smc.vnet.net...
> I wonder how you managed to get an error about
> Random[NormalDistribution[0,1]], since there  are errors in you code
> that should stop you ever getting to that point. First of all you have
> the a right square bracket in the wrong place, I mean the last one
> below:
>
> > MCCall=Compile[{{S, K, T, r, div, sig},{M, _Integer},{ N, _Integer}}]
>
> secondly, the syntax {S, K, T, r, div, sig} is quite wrong (look at the
> help for Compile), thirdly you need to load the
> Statistics`NormalDistribution` package, fourthly, in any case your
> function is very unlikely to compile well, if at all, so that it will
> probably be no faster than without compiling. You will do much better
> to re-write your code in a functional way, using Nest instead of For
> (For is very inefficient in Mathematica), that alone will give you a
> substantial speed up. Finally, you might want to have a look at my
> posting with the subject  "strange problems with Random" , otherwise
> you might be surprised that your answers turn out not to be very
> accurate.
>
> Andrzej Kozlowski
>
>
> On 22 May 2004, at 16:04, John wrote:
>
> > 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
> >
>



  • References:
    • Compile
      • From: "John" <john34@sepei.com>
  • Prev by Date: Re: Uniform design
  • Next by Date: Re: optimally picking one element from each list
  • Previous by thread: Re: Compile
  • Next by thread: Eigensystem: different solution in V5.0 and V4.1 ??