Binomial Model Part 3
Solution
First, we have to modify the widget creation function to return a new column for the second option.
#We can expand this to allow for combinations of options too!
widget_box.close()
#Update the widget box
def create_widgets():
#Create the two vertical boxes
simulation_parameters_box = create_simulation_parameters_box()
option_parameters_box1 = create_option_parameters_box()
option_parameters_box2 = create_option_parameters_box()
#Put them together with a horizontal box
return HBox([simulation_parameters_box, option_parameters_box1, option_parameters_box2])
widget_box = create_widgets()
display(widget_box)
After this, we can also modify the actual valuation formula to include both options.
widget_box.close()
def valuation(S, sigma, rf, T, T_increment, X1, O1, Side1,
X2, O2, Side2):
#Set t_increment based on the qualitative choice
if T_increment == "Trading Day":
T_increment = 1/252
elif T_increment == "Month":
T_increment = 1/12
elif T_increment == "Quarter":
T_increment = 1/4
elif T_increment == "Year":
T_increment = 1
else:
assert False
node_levels = create_nodes(S, T, sigma, T_increment)
#Put in the strike price, and chose the option formula based on the input
if O1 == "Call":
opt_formula1 = call_value
elif O1 == "Put":
opt_formula1 = put_value
if O2 == "Call":
opt_formula2 = call_value
elif O2 == "Put":
opt_formula2 = put_value
opt_values1 = backward_induction(node_levels, X1, sigma, rf, T_increment, opt_formula1)
opt_values2 = backward_induction(node_levels, X2, sigma, rf, T_increment, opt_formula2)
if Side1 == "Long":
pass
elif Side1 == "Short":
opt_values1 = [-x for x in opt_values1]
else:
assert False
if Side2 == "Long":
pass
elif Side2 == "Short":
opt_values2 = [-x for x in opt_values2]
else:
assert False
opt_values = [x+y for x,y in zip(opt_values1, opt_values2)]
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("Option Combination Values")
draw_binary_tree(node_levels, pos_dictionary,opt_labels)
widget_box = create_widgets()
output_object = interactive_output(valuation,{"S":widget_box.children[0].children[0],
"sigma":widget_box.children[0].children[1],
"rf":widget_box.children[0].children[2],
"T":widget_box.children[0].children[3],
"T_increment":widget_box.children[0].children[4],
"X1": widget_box.children[1].children[0],
"O1": widget_box.children[1].children[1],
"Side1": widget_box.children[1].children[2],
"X2": widget_box.children[2].children[0],
"O2": widget_box.children[2].children[1],
"Side2": widget_box.children[2].children[2]})
display(VBox([widget_box, output_object]))