MathGroup Archive 2011

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

Search the Archive

generic binomial/trinomial tree

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116808] generic binomial/trinomial tree
  • From: DC <b.gatessucks at gmail.com>
  • Date: Tue, 1 Mar 2011 05:21:03 -0500 (EST)

Hi, I'm playing around trying to build a generic tree :

TreeStep[slice_, parameters_] := Map[(# parameters) &, slice, {-1}]

TreeBuilder[s0_, parameters_, nSteps_]:=NestList[TreeStep[#,parameters] 
&, s0, nSteps]


In[29]:= TreeBuilder[{50.}, {1.05, 1./1.05}, 2]
Out[29]= {{50.}, {{52.5, 47.619}}, {{{55.125, 50.}, {50., 45.3515}}}}


If now I specialize to recombining trees :

RecombiningTreeStep[slice_, parameters_] :=
  Reverse[Union[Flatten[Map[# parameters &, slice, {-1}]]]]

TreeBuilder[s0_, parameters_, nSteps_] :=
  NestList[RecombiningTreeStep[#, parameters] &, s0, nSteps]


In[40]:= TreeBuilder[{50.}, {1.05, 1./1.05}, 2]
Out[40]= {{50.}, {52.5, 47.619}, {55.125, 50., 50., 45.3515}}

I have the problem that Union does not distinguish between the two 50.s 
in the last slice.

1. Any suggestions ?
2. I can use
Union[Flatten[Map[# parameters &, slice, 
{-1}]],SameTest->(Abs[#1-#2]<0.001 &)]

This solves the problem but then I cannot compile the function (very 
slow as it is) :

cRecombiningTreeStep =
  Compile[{{slice, _Real, 1}, {parameters, _Real, 1}, {eps, _Real}},
   Reverse[Union[Flatten[Map[# parameters &, slice, {-1}]]],
    SameTest -> (Abs[#1 - #2] < eps &)]]

Any suggestions ?

Thanks.
-Francesco


  • Prev by Date: Re: problem with"Re" syntax
  • Next by Date: Re: Problem exporting to LaTex
  • Previous by thread: Re: problem with"Re" syntax
  • Next by thread: Re: Problem exporting to LaTex