Beispiel #1
0
 def test_analytical_theta(self):
     while self.tdi.has_next():
         row = self.tdi.next_row()
         S, K, t, r, sigma = row['S'], row['K'], row['t'], row['R'], row[
             'v']
         self.assertAlmostEqual(analytical.theta('c', S, K, t, r, sigma, q),
                                row['CT'] / 365.0,
                                delta=0.000001)
         self.assertAlmostEqual(analytical.theta('p', S, K, t, r, sigma, q),
                                row['PT'] / 365.0,
                                delta=0.000001)
Beispiel #2
0
    def test_analytical_theta(self):
        S = 49
        K = 50
        sigma = .2
        r = .05
        t = 0.3846
        q = 0.2

        flag = 'p'
        c_put = c_analytical.theta(flag, S, K, t, r, sigma, q)
        py_put = py_analytical.theta(flag, S, K, t, r, sigma, q)
        self.assertTrue(almost_equal(c_put, py_put))

        flag = 'c'
        c_call = c_analytical.theta(flag, S, K, t, r, sigma, q)
        py_call = py_analytical.theta(flag, S, K, t, r, sigma, q)
        self.assertTrue(almost_equal(c_call, py_call))
Beispiel #3
0
 def test_theta(self):
     thetas = [
         theta(flag, S, K, t, r, sigma, q)
         for flag, S, K, t, r, sigma, q in self.arg_combinations
     ]
     nthetas = [
         ntheta(flag, S, K, t, r, sigma, q)
         for flag, S, K, t, r, sigma, q in self.arg_combinations
     ]
     self.assertTrue(self.diff_mean(thetas, nthetas) < self.epsilon)
Beispiel #4
0
 def theta(self, S, vol):
     if option.time_exp[self.exp] <= 0: return 0.
     return bsg.theta(self.flag, S, self.K, option.time_exp[self.exp],
                      self.rate, vol, 0.)
Beispiel #5
0
import py_vollib.black_scholes_merton.implied_volatility as BSvol
import py_vollib.black_scholes_merton.greeks.analytical as BSgreeks

t = 10 / 365
price = 0.56
S = 233.2
K = 235
flag = 'c'
r = .02
q = .0224

iv = BSvol.implied_volatility(price, S, K, t, r, q, flag)
td = BSgreeks.theta(flag, S, K, t, r, iv, q)
print(round(iv, 3))
print(round(td, 3))