I am attempting to come up with an algorithm to iterate through every possible path of a trinomial tree and am having difficulties coming up with one. Is there any literature on this or has anyone else written something similar?

To be specific I am trying to calculate the P&L of stock trades from node 0 to every possible path end.

I am aware the total number of paths that end at a given point is given by Pascal's tetrahedron but I do not know how to come up with all the paths for an arbitrary (n-step) tree. So I need the 1,-1,1,-1,0 sequence which in this case would end on the middle node of a 5 step tree.

Yea that looks like what I want I will extend it to loop through every possible ending point. I am not familiar with Python and can't seem to figure out what the statement path+[1] does. I am trying to implement this in c++ and it I am unsure how your code would do anything else besides add an element to an array with a 1 in it until there are 5 and then stop. Thanks again.
–
user2183336Apr 9 '13 at 18:16

@user2183336 That Python notation is the side-effect free way of appending an element. Ie, it returns a new array without modifying the original. Again, the key point to my example is that this is a depth-first search; I recursively descend each possible path. The array notation I used in Python was just for convenience; the DFS is how I actually solved the problem.
–
chrisaycockApr 9 '13 at 18:21

To convert an index to base 3 (actually to an array with the base 3 digits, each one selecting a move up/mid/down) you only need to alternate a modulo-3 (remainder) operator and integer division by 3.
Or were you asking for something else?