def black_scholes(t,S,K,T,sigma,r,q,option_type=None): d1=d_1(t,S,K,T,sigma,r,q) d2=d1-sigma*math.sqrt(T-t) call_price=S*math.exp(-q*(T-t))*cum_dist_normal(d1)-K*math.exp(-r*(T-t))*cum_dist_normal(d2) put_price=K*math.exp(-r*(T-t))*cum_dist_normal(-d2)-S*math.exp(-q*(T-t))*cum_dist_normal(-d1) if option_type is None: print "No option type indicated, assuming CALL." #log.warning("No option type indicated, assuming CALL.") return call_price elif option_type.upper()=="CALL": return call_price elif option_type.upper()=="PUT": return put_price
def rho_BS_put(t,S,K,T,sigma,r,q): d1=d_1(t,S,K,T,sigma,r,q) d2=d1-sigma*math.sqrt(T-t) return -K*(T-t)*math.exp(-r*(T-t))*cum_dist_normal(-d2)
def theta_BS_put(t,S,K,T,sigma,r,q): d1=d_1(t,S,K,T,sigma,r,q) d2=d1-sigma*math.sqrt(T-t) return -0.5*S*sigma*math.exp(-q*(T-t))*math.exp(-0.5*d1*d1)/math.sqrt(2*math.pi*(T-t))- \ q*S*math.exp(-q*(T-t))*cum_dist_normal(-d1) + r*K*math.exp(-r*(T-t))*cum_dist_normal(-d2)
def delta_BS_put(t,S,K,T,sigma,r,q): d1=d_1(t,S,K,T,sigma,r,q) return -math.exp(-q*(T-t))*cum_dist_normal(-d1)
def delta_BS_call(t,S,K,T,sigma,r,q): d1=d_1(t,S,K,T,sigma,r,q) return math.exp(-q*(T-t))*cum_dist_normal(d1)