I am trying to use the following code in jupyter notebook to vary the inputs of a blackscholes prices using the tkslider. However, the calculate button doesn't seem to be working - I just get a GUI window that shows me the 3 slides and a calculate button that doesn't print the blackscholes price.
import numpy as np
from tkinter import *
def blackscholes(F,K,T,sigma,Type="p"):
d1 = (np.log(F/K)+((sigma**2)/2)*T)/(sigma*np.sqrt(T))
d2 = d1-sigma*np.sqrt(T)
try:
if Type=="p":
price = F*norm.cdf(d1,0,1)-K*norm.cdf(d2,0,1)
elif Type=="r":
price = K*norm.cdf(-d2,0,1)-F*norm.cdf(-d1,0,1)
return price
except:
print("rrr")
window = Tk()
def calculate_values(Strike):
F = Fscale.get()
sigma=sigmascale.get()
T = Tscale.get()
l.configure(text=blackscholes(F,Strike,T,sigma,"p"))
l=Label(window,text='')
Fscale=Scale(window,from_=1,to=1000,orient=HORIZONTAL,label="F")
Fscale.pack()
sigmascale=Scale(window,from_=1,to=1000,orient=HORIZONTAL,label="sigma")
sigmascale.pack()
Tscale=Scale(window,from_=1,to=100,orient=HORIZONTAL,label="T")
Tscale.pack()
blackscholes_button=Button(window, text='Calculate',command=lambda: calculate_values(Strike=10))
blackscholes_button.pack()
window.mainloop()