def test_numerical_theta(self): S = 49 K = 50 sigma = .2 r = .05 t = 0.3846 flag = 'p' c_put = c_numerical.theta(flag, S, K, t, r, sigma) py_put = py_numerical.theta(flag, S, K, t, r, sigma) self.assertTrue(almost_equal(c_put, py_put)) flag = 'c' c_call = c_numerical.theta(flag, S, K, t, r, sigma) py_call = py_numerical.theta(flag, S, K, t, r, sigma) self.assertTrue(almost_equal(c_call, py_call))
def test_analytical_vega(self): S = 49 K = 50 sigma = .2 r = .05 t = 0.3846 flag = 'p' c_put = c_analytical.vega(flag, S, K, t, r, sigma) py_put = py_analytical.vega(flag, S, K, t, r, sigma) self.assertTrue(almost_equal(c_put, py_put)) flag = 'c' c_call = c_analytical.vega(flag, S, K, t, r, sigma) py_call = py_analytical.vega(flag, S, K, t, r, sigma) self.assertTrue(almost_equal(c_call, py_call))
def test_analytical_vega(self): F = 100 K = 90 sigma = .2 r = .02 t = .5 flag = 'p' c_put = c_analytical.vega(flag, F, K, t, r, sigma) py_put = py_analytical.vega(flag, F, K, t, r, sigma) self.assertTrue(almost_equal(c_put, py_put)) flag = 'c' c_call = c_analytical.vega(flag, F, K, t, r, sigma) py_call = py_analytical.vega(flag, F, K, t, r, sigma) self.assertTrue(almost_equal(c_call, py_call))
def test_numerical_theta(self): F = 100 K = 90 sigma = .2 r = .02 t = .5 flag = 'p' c_put = c_numerical.theta(flag, F, K, t, r, sigma) py_put = py_numerical.theta(flag, F, K, t, r, sigma) self.assertTrue(almost_equal(c_put, py_put)) flag = 'c' c_call = c_numerical.theta(flag, F, K, t, r, sigma) py_call = py_numerical.theta(flag, F, K, t, r, sigma) self.assertTrue(almost_equal(c_call, py_call))
def test_numerical_rho(self): S = 49 K = 50 sigma = .2 r = .05 t = 0.3846 q = 0.2 flag = 'p' c_put = c_numerical.rho(flag, S, K, t, r, sigma, q) py_put = py_numerical.rho(flag, S, K, t, r, sigma, q) self.assertTrue(almost_equal(c_put, py_put)) flag = 'c' c_call = c_numerical.rho(flag, S, K, t, r, sigma, q) py_call = py_numerical.rho(flag, S, K, t, r, sigma, q) self.assertTrue(almost_equal(c_call, py_call))
def test_black_call(self): F = 100 K = 90 sigma = .2 r = .02 t = .5 flag = 'c' c_price = c_black(flag, F, K, t, r, sigma) py_price = py_black(flag, F, K, t, r, sigma) self.assertTrue(almost_equal(c_price, py_price))
def test_black_scholes_call(self): S = 100 K = 90 r = .01 t = .5 sigma = .2 flag = 'c' c_price = c_black_scholes(flag, S, K, t, r, sigma) py_price = py_black_scholes(flag, S, K, t, r, sigma) self.assertTrue(almost_equal(c_price, py_price))
def test_black_call(self): S = 100 K = 95 r = .01 q = .05 t = .5 sigma = .2 flag = 'c' c_price = c_black_scholes_merton(flag, S, K, t, r, sigma, q) py_price = py_black_scholes_merton(flag, S, K, t, r, sigma, q) self.assertTrue(almost_equal(c_price, py_price))
def test_implied_volatility_call(self): F = 100 K = 100 sigma = .2 t = .5 r = .02 flag = 'c' c_price = c_black(flag, F, K, t, r, sigma) py_price = py_black(flag, F, K, t, r, sigma) c_iv = c_implied_volatility(c_price, F, K, t, r, flag) py_iv = py_implied_volatility(py_price, F, K, t, r, flag) self.assertTrue(almost_equal(c_iv, py_iv))
def test_implied_volatility_call(self): S = 100 K = 100 sigma = .232323232 t = .5 r = .01 flag = 'c' c_price = c_black_scholes(flag, S, K, t, r, sigma) py_price = py_black_scholes(flag, S, K, t, r, sigma) c_iv = c_implied_volatility(c_price, S, K, t, r, flag) py_iv = py_implied_volatility(py_price, S, K, t, r, flag) self.assertTrue(almost_equal(c_iv, py_iv))