This script constructs a recombining tree for pricing vanilla European and American options and (optionally) outputs the tree in a format suitable for plotting with graphviz
. The code is written for clarity. New payoff functions can be easily added. For a detailed explanation and more examples, see this blog post.
Example: