예제 #1
0
    def test_analytical_rho(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.assertTrue(
                almost_equal(analytical.rho('c', S, K, t, r, sigma),
                             row['CR'] * .01,
                             epsilon=.000000001))
            self.assertTrue(
                almost_equal(analytical.rho('p', S, K, t, r, sigma),
                             row['PR'] * .01,
                             epsilon=.000000001))
예제 #2
0
    def test_analytical_rho(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.assertTrue(
                almost_equal(
                    analytical.rho('c', S, K, t, r, sigma), row['CR']*.01, epsilon=.000000001
                )
            )
            self.assertTrue(
                almost_equal(
                    analytical.rho('p', S, K, t, r, sigma), row['PR']*.01, epsilon=.000000001
                )
            )
예제 #3
0
def implied_vol_calc(exp, fut, option):
    global rate

    iv_fun = lambda x: implied_volatility(x['SETTLE_PR'], fut, x[
        'STRIKE_PR'], exp, 0.1, 'c' if x.OPTION_TYP == 'CE' else 'p') * 100
    #vollib.black_scholes.greeks.numerical.delta(flag, S, K, t, r, sigma)
    option['VOLATILITY'] = option.apply(iv_fun, axis=1)
    delta_fun = lambda x: delta(('c' if x.OPTION_TYP == 'CE' else 'p'), fut, x[
        'STRIKE_PR'], exp, 0.1, x.VOLATILITY / 100)
    gamma_fun = lambda x: gamma(('c' if x.OPTION_TYP == 'CE' else 'p'), fut, x[
        'STRIKE_PR'], exp, 0.1, x.VOLATILITY / 100)
    vega_fun = lambda x: vega(('c' if x.OPTION_TYP == 'CE' else 'p'), fut, x[
        'STRIKE_PR'], exp, 0.1, x.VOLATILITY / 100)
    theta_fun = lambda x: theta(('c' if x.OPTION_TYP == 'CE' else 'p'), fut, x[
        'STRIKE_PR'], exp, 0.1, x.VOLATILITY / 100)
    rho_fun = lambda x: rho(('c' if x.OPTION_TYP == 'CE' else 'p'), fut, x[
        'STRIKE_PR'], exp, 0.1, x.VOLATILITY / 100)
    option['DELTA'] = option.apply(delta_fun, axis=1)
    option['GAMMA'] = option.apply(gamma_fun, axis=1)
    option['VEGA'] = option.apply(vega_fun, axis=1)
    option['THETA'] = option.apply(theta_fun, axis=1)
    option['RHO'] = option.apply(rho_fun, axis=1)
    #Remove option with delta <0.05 for calls and delta >-0.05 for puts
    option = option[(option.DELTA > 0.05) | (option.DELTA < -0.05)]
    #Remove where no contracts are being traded
    option = option[option.CONTRACTS != 0]
    option['FUT'] = fut

    return option
예제 #4
0
 def test_rho(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 = rho(flag, S, K, t, r, sigma)
                             val2 = nrho(flag, S, K, t, r, sigma)
                             results_match = abs(val1-val2)<epsilon
                             if not results_match:
                                 print flag, val1, val2
                             self.assertTrue(results_match)
예제 #5
0
 def test_rho(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 = rho(flag, S, K, t, r, sigma)
                             val2 = nrho(flag, S, K, t, r, sigma)
                             results_match = abs(val1-val2)<epsilon
                             if not results_match:
                                 print flag, val1, val2
                             self.assertTrue(results_match)
예제 #6
0
def implied_vol_calc(exp,fut,option):
    global rate
    
    iv_fun=lambda x:implied_volatility(x['SETTLE_PR'],fut,x['STRIKE_PR'],exp,0.1,'c' if x.OPTION_TYP=='CE' else 'p')*100
    #vollib.black_scholes.greeks.numerical.delta(flag, S, K, t, r, sigma)
    option['VOLATILITY']=option.apply(iv_fun,axis=1)
    delta_fun=lambda x:delta(('c' if x.OPTION_TYP=='CE' else 'p'),fut,x['STRIKE_PR'],exp,0.1,x.VOLATILITY/100)
    gamma_fun=lambda x:gamma(('c' if x.OPTION_TYP=='CE' else 'p'),fut,x['STRIKE_PR'],exp,0.1,x.VOLATILITY/100)
    vega_fun=lambda x:vega(('c' if x.OPTION_TYP=='CE' else 'p'),fut,x['STRIKE_PR'],exp,0.1,x.VOLATILITY/100)
    theta_fun=lambda x:theta(('c' if x.OPTION_TYP=='CE' else 'p'),fut,x['STRIKE_PR'],exp,0.1,x.VOLATILITY/100)
    rho_fun=lambda x:rho(('c' if x.OPTION_TYP=='CE' else 'p'),fut,x['STRIKE_PR'],exp,0.1,x.VOLATILITY/100)
    option['DELTA']=option.apply(delta_fun,axis=1)
    option['GAMMA']=option.apply(gamma_fun,axis=1)
    option['VEGA']=option.apply(vega_fun,axis=1)
    option['THETA']=option.apply(theta_fun,axis=1)
    option['RHO']=option.apply(rho_fun,axis=1)
    #Remove option with delta <0.05 for calls and delta >-0.05 for puts
    option=option[(option.DELTA>0.05) | (option.DELTA<-0.05)]
    #Remove where no contracts are being traded
    option=option[option.CONTRACTS!=0]
    option['FUT']=fut
    
    return option