MathGroup Archive 2001

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

Search the Archive

Re: Trinomialtree

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30969] Re: Trinomialtree
  • From: Albert Retey <albert.retey at visualanalysis.com>
  • Date: Fri, 28 Sep 2001 03:55:24 -0400 (EDT)
  • Organization: Visual Analysis AG
  • References: <9ougit$159$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Yannis.Paraskevopoulos at ubsw.com wrote:
> 
> Hi all,
> 
> I have been having problem executing the following code. Could you
> please tell me what am I doing wrong?
> 
> Best regards and thanks in advance
> 
> ============Mathematica Code===============================================
> 
> TrinomialTree[AmEurFlag_Symbol,CallPutFlag_Symbol,S_,X_,T_,r_,b_,v_,n_]: =
>   Module[{OptionValue,dt,pu,pd,pm,u,d,Df,z},
>     dt=T/n;
>     u=Exp[v*Sqrt[2*dt]];
>     d=Exp[-v*Sqrt[2*dt]];
>     pu=((Exp[b*dt/2]-Exp[-v*Sqrt[dt/2]])/(Exp[v*Sqrt[dt/2]]-
>                 Exp[-v*Sqrt[dt/2]]))^2;
>     pd=((Exp[v*dt/2]-Exp[b*Sqrt[dt/2]])/(Exp[v*Sqrt[dt/2]]-
>                 Exp[-v*Sqrt[dt/2]]))^2;
>     pm=1-pu-pd;
>     Which[CallPutFlag=c,z==1,CallPutFlag=p,z==-1];
>     OptionValue=
>       Table[Max[0,z*(S*u^Max[i-n,0]*d^Max[n*2-n-i,0]-X)],{i,0,2*n}];
>     Which[AmEurFlag=e,OptionValue=Table[(pu*OtoptionValue[[i+2]]
>                 +pm*OptionValue[[i+1]]+pd*OptionValue[[i]])*Df,{j,n-1,
>             0,-1},{i,0,j*2}],AmEurFlag=a,
>       OptionValue=
>         Table[Max[(z*(S*u^Max[i-j,0]*d^Max[j*2-j-i,0]-X)),(pu*
>                     OptionValue[[i+1]]+pd*OptionValue[[i]])*Df],{j,n-1,
>             0,-1},{i,0,j*2}]];
>     OptionValue
>     ]
Hi,

I did'nt try your code, but there is an obvious mistake in it, you want
to use == (Equal) or even better === (SameQ) instead of = (Set) wherever
you are comparing things and set where you want to set a symbol to a
certain value (In your code it's just the other way 'round). 

Oh, and don't blame Mathematica if this code turns out to be rather
slow, there is plenty room to improve it...

Hope this helps

Albert
--
Visual Analysis AG       Internet: www.visualanalysis.com
Neumarkter Str. 87       Telefon: 089 / 431 981 36        
D-81673 Muenchen         Telefax: 089 / 431 981 1


  • Prev by Date: Re: Export table problem
  • Next by Date: Re: Hessian calculation
  • Previous by thread: Trinomialtree
  • Next by thread: Help! FindRoot output to list...