I am trying to create code that would allow my black scholes model to choose between 2 formulas all within one function. I got a syntax error and I am not sure if the order in which I am trying to do this will work. The function needs to output a delta and a Price for Binary call and non dividend european call/put. any tips are appreciated!
def Pricing_library(S, K, T, r, sigma, Product_type, Call_Put):
# S=Spot, K=Strike, T=Maturity, r=rate, sigma=volatility #Product_type=European or Binary #Call/Put =
D1 = (1.0/ (sigma * m.sqrt(T))
* ( m.log(float(S)/float(K))
+(r+sigma**2/2.0) * T ))
D2 = D1 - sigma * m.sqrt(T)
if Call_Put == 'Call':
Delta = norm.cdf(D1)
else:
Delta = norm.cdf(D1)-1
Vanilla European Option Pricer =
if Call_Put == 'Call':
Price = norm.cdf(D1)*S - norm.cdf(D2)*(K*m.exp(-r*T))
else: Price = (K * m.exp(-r * T) * norm.cdf(-D2) - S * norm.cdf(-D1))
Binary Option Pricer = m.exp(-r * T) * norm.cdf(D2)
if Product_type == 'Vanilla':
Price = Vanilla European Option Pricer
else: Price = Binary Option Pricer
return Price, Delta
Aucun commentaire:
Enregistrer un commentaire