Question: Implementing a binomial tree in python. I'm trying to create a function that returns a binomial tree (2d list) of simulated stock price movements. I

Implementing a binomial tree in python. I'm trying to create a function that returns a binomial tree (2d list) of simulated stock price movements.

I cannot use built-in function numpy. However, I can use helper function called zeros, which makes a 2d matrix with n rows and n columns.

build_binomial_stock_price_tree(s, sigma, rf, div, T, n) this function takes 6 inputs.

s = current stock price

rf = (annulized rish free rate of return)

div = (annualized divided rate ; assume contiouns dividends rate )

T = time to maturity , n = number of discrete time periods to use in the tree.

I have another helper function that calculates factor u & d, hence up -state = u * previous price , down-state = u* previous price

This is what i have so far "

def build_binomial_stock_price_tree(s, sigma, rf, div, T, n): """ builds and returns a binomail tree of simulated stock price movements """ u , d = get_binomial_factors(sigma, rf, div, n * T) binomial_up = zeros(n+1) for r in range( n+ 1): for c in range( r + 1): binomial_up[r][c] = s * (d ** c) * (u**(r-c)) return binomial_up

However, its giving me ouput looks like [[ 100.00, 0.00,] [ 127.12, 85.21,]]

Instead, i should expect to see an output looks like :

[[100, 124.60767305873807], [0.0, 83.5270211411272]]

Can someone plz help me with this function ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!