def test_prices(self): S = 100.0 for flag in ['c','p']: for K in numpy.linspace(20,200,10): for r in numpy.linspace(0,0.2,10): for sigma in numpy.linspace(0.1,0.5,10): for t in numpy.linspace(0.01,2,10): for i in range(5): val1 = black_scholes(flag, S, K, t, r, sigma) val2 = python_black_scholes(flag, S, K, t, r, sigma) results_match = abs(val1-val2)<epsilon if not results_match: print 'price mismatch:', flag, val1, val2 self.assertTrue(results_match)
from vollib.helper.numerical_greeks import theta as numerical_theta from vollib.helper.numerical_greeks import rho as numerical_rho from vollib.helper.numerical_greeks import gamma as numerical_gamma # analytical greeks from vollib.black_scholes.greeks.analytical import gamma as agamma from vollib.black_scholes.greeks.analytical import delta as adelta from vollib.black_scholes.greeks.analytical import vega as avega from vollib.black_scholes.greeks.analytical import rho as arho from vollib.black_scholes.greeks.analytical import theta as atheta # ----------------------------------------------------------------------------- # FUNCTIONS - NUMERICAL GREEK CALCULATION f = lambda flag, S, K, t, r, sigma, b: python_black_scholes(flag, S, K, t, r, sigma) def delta(flag, S, K, t, r, sigma): """Return Black-Scholes delta of an option. :param S: underlying asset price :type S: float :param K: strike price :type K: float :param sigma: annualized standard deviation, or volatility :type sigma: float :param t: time to expiration in years :type t: float :param r: risk-free interest rate
from vollib.helper.numerical_greeks import vega as numerical_vega from vollib.helper.numerical_greeks import theta as numerical_theta from vollib.helper.numerical_greeks import rho as numerical_rho from vollib.helper.numerical_greeks import gamma as numerical_gamma # analytical greeks from vollib.black_scholes.greeks.analytical import gamma as agamma from vollib.black_scholes.greeks.analytical import delta as adelta from vollib.black_scholes.greeks.analytical import vega as avega from vollib.black_scholes.greeks.analytical import rho as arho from vollib.black_scholes.greeks.analytical import theta as atheta # ----------------------------------------------------------------------------- # FUNCTIONS - NUMERICAL GREEK CALCULATION f = lambda flag, S, K, t, r, sigma, b: python_black_scholes( flag, S, K, t, r, sigma) def delta(flag, S, K, t, r, sigma): """Return Black-Scholes delta of an option. :param S: underlying asset price :type S: float :param K: strike price :type K: float :param sigma: annualized standard deviation, or volatility :type sigma: float :param t: time to expiration in years :type t: float :param r: risk-free interest rate :type r: float