-
Option Payoffs 4
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
-
Binomial Model 8
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
Lecture2.7
-
Lecture2.8
-
-
Black-Scholes 6
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
Lecture3.6
-
-
Monte Carlo Simulations 3
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Binomial Trees 3
Solution
#Begin switching to setting variables like this to make it cleaner
sigma = .08
rf = .04
T_increment = 1/4
strike_price = 100
#Compute the next level in the binary tree
def backward_induction_node_level(level, sigma, rf, T_increment):
p_up = compute_up_probability(rf, T_increment, sigma)
p_down = 1-p_up
next_level = []
for i in range(len(level)-1):
value = p_up * level[i+1] + p_down * level[i]
value = value / np.exp(rf * T_increment)
next_level.append(value)
next_level = np.array(next_level).round(2)
return next_level
next_level = backward_induction_node_level(opt_values[-1], sigma, rf, T_increment)
print(next_level)
We can update the function from before to now include the next level….
def backward_induction(node_levels, strike_price, sigma, rf, T_increment):
opt_values = []
#The expiration level has values based on the derivative formula
level = node_levels[-1]
level = np.array(level)
level = np.where(level-strike_price < 0, 0, level-strike_price).round(2)
opt_values.append(level)
#Go through each level in reverse order after the expiration level
#Start with just one level down
for level in node_levels[::-1][1:2]:
opt_values.append(backward_induction_node_level(opt_values[-1], sigma, rf, T_increment))
for level in node_levels[::-1][2:]:
opt_values.append(["?" for x in level])
#Reverse the order of the list
opt_values = opt_values[::-1]
return opt_values
node_levels = create_nodes(100, 4, .08, 1/4)
opt_values = backward_induction(node_levels, strike_price, sigma, rf, T_increment)
print(opt_values)
And we might also want to put the stock price tree above the option price tree to compare.
sigma = .08
rf = .04
T_increment = 1/4
T = 4
strike_price = 100
price0 = 100
node_levels = create_nodes(price0, T, sigma, T_increment)
opt_values = backward_induction(node_levels, 100, sigma, rf, T_increment)
node_levels = convert_nodes_to_labels(node_levels)
opt_labels = convert_nodes_to_labels_TEMP(opt_values)
pos_dictionary = create_node_positions(node_levels)
plt.rcParams["figure.figsize"] = (10,5)
print("Stock Values")
draw_binary_tree(node_levels, pos_dictionary,node_levels)
print("Call Option Values")
draw_binary_tree(node_levels, pos_dictionary,opt_labels)
To finalize this, let's extend it so that every single level is taken care of.
#Finalize it to be all levels
def backward_induction(node_levels, strike_price, sigma, rf, T_increment):
opt_values = []
level = node_levels[-1]
level = np.array(level)
level = np.where(level-strike_price < 0, 0, level-strike_price).round(2)
opt_values.append(level)
for level in node_levels[::-1][1:]:
opt_values.append(backward_induction_node_level(opt_values[-1], sigma, rf, T_increment))
opt_values = opt_values[::-1]
return opt_values
node_levels = create_nodes(price0, T, sigma, T_increment)
opt_values = backward_induction(node_levels, strike_price, sigma, rf, T_increment)
print(opt_values)
And then show the two binary trees.
node_levels = create_nodes(price0, T, sigma, T_increment)
opt_values = backward_induction(node_levels, 100, sigma, rf, T_increment)
node_levels = convert_nodes_to_labels(node_levels)
opt_labels = convert_nodes_to_labels(opt_values)
pos_dictionary = create_node_positions(node_levels)
print("Stock Values")
draw_binary_tree(node_levels, pos_dictionary,node_levels)
print("Call Option Values")
draw_binary_tree(node_levels, pos_dictionary,opt_labels)
And this can easily be extended to a monthly example....
sigma = .08
rf = .04
T_increment = 1/12
T = 12
strike_price = 100
price0 = 100
plt.rcParams["figure.figsize"] = (15,10)
node_levels = create_nodes(price0, T, sigma, T_increment)
opt_values = backward_induction(node_levels, 100, sigma, rf, T_increment)
node_levels = convert_nodes_to_labels(node_levels)
opt_labels = convert_nodes_to_labels(opt_values)
pos_dictionary = create_node_positions(node_levels)
print("Stock Values")
draw_binary_tree(node_levels, pos_dictionary,node_levels)
print("Call Option Values")
draw_binary_tree(node_levels, pos_dictionary,opt_labels)
Prev
Binomial Trees 2
Next
Binomial Trees 4