I'm trying to implement a pricing method for exotic options based on binomial tree's. The problem i'm having is that i'm not being able to generate all the paths of the tree. I have the following code in python that generates the tree but haven't been able to extract all the paths from it.
import numpy as np
risk_free = 0.1
spot = 50
volatility = 0.4
T = 3/12
steps = 3
dt = T/steps
Up = np.exp(volatility*np.sqrt(dt))
Down = 1 / Up
p = (np.exp(risk_free*dt)-Down)/(Up-Down)
q = 1-p
dpowers = Down ** np.arange(steps,-1,-1)
upowers = Up ** np.arange(0,steps+1)
# steps + 1 because at the end we have steps + 1 prices
W = spot*dpowers*upowers
# backward valuation
for i in np.arange(steps, 0,-1):
Si = spot*dpowers[(steps-i+1):steps+1]*upowers[0:i]
W = np.vstack((np.append(np.repeat(0,steps-i+1),Si),W))
Tree = W.T
Tree
? Because the paths I get when running your code look reasonable. Have a look at some of my old code for a working implementation of binomial tree's and the Longstaff Schwarz method. $\endgroup$Tree
is correct thats part of the code i have for american options, and yeah would like to extract all the paths from objectTree
. as noob2 mentions the 2^N paths and associate each path to all the nodes in the tree $\endgroup$