def div_rho_BS(S, K, r, d, v, T, p): if T <= 0: return 0 else: if p == "call": return K * T * exp(-r * T) * norm_cdf(d_j(2, S, K, r, d, v, T)) elif p == "put": return -K * T * exp(-r * T) * norm_cdf(-d_j(2, S, K, r, d, v, T))
def div_delta_BS(S, K, r, d, v, T, p): if T <= 0: if p == "call": return max(0, S - K) / max(0.0001, S - K) elif p == "put": return -max(0, K - S) / max(0.00001, K - S) else: if p == "call": return norm_cdf(d_j(1, S, K, r, d, v, T)) elif p == "put": return -norm_cdf(-d_j(1, S, K, r, d, v, T))
def div_theta_BS(S, K, r, d, v, T, p): if T <= 0: return 0 else: if p == "call": return (S * v * norm_pdf(d_j(1, S, K, r, d, v, T))) / ( 2 * T**0.5) - r * K * exp(-r * T) * norm_cdf( d_j(2, S, K, r, v, T)) elif p == "put": return -(S * v * norm_pdf(d_j(1, S, K, r, d, v, T))) / ( 2 * T**0.5) + r * K * exp( -r * T) * norm_cdf(-d_j(2, S, K, r, d, v, T))
def div_price_BS(S, K, r, d, v, T, p): if T <= 0: if p == "call": return max(0, S - K) elif p == "put": return max(0, K - S) else: if p == "call": return S * exp(-d * T) * norm_cdf(d_j( 1, S, K, r, d, v, T)) - K * exp(-r * T) * norm_cdf( d_j(2, S, K, r, d, v, T)) elif p == "put": return -S * exp( -d * T) * norm_cdf(-d_j(1, S, K, r, d, v, T)) + K * exp( -r * T) * norm_cdf(-d_j(2, S, K, r, d, v, T))
def vanilla_put_prices(S, K, r, v, T): return -S * norm_cdf(-d_j(1, S, K, r, v, T)) + \ K*exp(-r*T) * norm_cdf(-d_j(2, S, K, r, v, T))
def vanilla_call_prices(S, K, r, v, T): return S * norm_cdf(d_j(1, S, K, r, v, T)) - \ K*exp(-r*T) * norm_cdf(d_j(2, S, K, r, v, T))