Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Traversing a binomial tree help
Message
 
À
21/02/2006 15:44:03
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01097850
Message ID:
01098761
Vues:
12
Thanks, the results are not what I want. But the concept is clear...

>>Hi All,
>>
>>I have a binomial tree structure. I want to get all the possible paths in this tree, I have been searching for an elegant way to do this. I'll explain with an example:
>>
>>A person starts with disability state 0, the following year he can get disabled and reaches state 1 or he stays active in the same state 0 (so there are two states in year 1 (2^time)). The following year 2 he can get disabled for the first time 0->1, or he stays active 0->0, or he gets better 1->0, or he disables more 1->2 (so 2^2 possibilities). And so on....
>>
>>I want to make a function that returns a array of strings of all possible paths given a specific duration, so :
>>
>>for year 0 : "0"
>>for year 1:  "01"
>>          :  "00"
>>for year 2:  "000"
>>             "001"
>>             "012"
>>             "010"
>>for year n: 2^n possibilities
>>
>>
>>I have been trying to make a readable code for this, but with no success. Any ideas?
>>
>>Thanks beforehand.
>
>
Do Y1 With 0, ""
>
>*******************************
>Procedure Y1(tnY, cPrev)
>	If tnY>3    && here I've put it to 3, but you may go with as many years as... (*)
>		Return
>	Endif
>	?
>	? "Year ",tnY
>	Local i, nLen, aC[tnY+1]
>	nLen=tnY+1
>	aC=cPrev
>	For i=0 To tnY
>		aC[i+1] = aC[i+1] + Transform(i)
>		? aC[i+1] At tnY*3
>		Do Y1 With tnY+1, aC[i+1]
>	Endfor
>
>Endproc
>
>
>(*) as many years as you got the patience. Note that the size of this isn't 2**n, it's in the order of (n+1)! (i.e n+1 factorial). More precisely, for year 0 there's 1, for 1 there's 2, for year 3 there's 6, for 4 - 24.... etc, so we have sigma(0 to n, (n+1)!) possible strings here. It can easily get out of hand. 1+2+6+24+120+720+5040+40320+... you figure it out- if you run it for a period of 20 years (as these disabilities don't just vanish over a year or two, people can live decades with them), you may create a huge table, in which you may never use more than a minuscule percentage of records.
>
>In other words, do you really need this table?
Zakaria al Azhar
My blog on Actuaris.net
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform