Beispiel #1
0
    def calc_impliedVolatility(cls, optPx, F, K, r, tau, isCall=True, q=0):

        if isCall:
            return iv.implied_volatility(optPx, F, K, r, tau, "c")

        else:
            return iv.implied_volatility(optPx, F, K, r, tau, "p")
Beispiel #2
0
def lam_pyvol(r):
    try:
        return implied_volatility.implied_volatility(r.close_x, r.close_y,
                                                     r.strike, .02,
                                                     r.dte / 365, r.pc.lower())
    except:
        return -1
Beispiel #3
0
def _test_py_vollib():
    #CL,Q2019,560P,07/02/2019,0.6,1.61,0.54,1.54,1997,4465
    F = 56.25
    K = 56
    sigma = .366591539
    flag = 'p'
    t = 15 / 365.0
    r = .025
    discounted_call_price = black.black(flag, F, K, t, r, sigma)
    dcp = 1.54
    ivpy = implied_volatility.implied_volatility(dcp, F, K, r, t, flag)
    ivmn = mibian.BS([F, K, 2.5, 15], callPrice=dcp).impliedVolatility
    discounted_call_price, ivpy, ivmn
Beispiel #4
0
def blackIV(df, F=None, rf=None):
    if F is None: F = df['F']
    if rf is None: rf = .02
    try:
        iv = implied_volatility(
            discounted_option_price=df['Mid'],  # change to 'Mid'
            F=F,
            K=df['Strike'],
            r=rf,
            t=df['BDTE'] / 252,
            flag=df['Flag'])
    except:
        iv = np.nan
    return iv
Beispiel #5
0
    def iv(self, option_obj, asset_price, timestamp, expiration,
           call_put_flag):
        discounted_option_price = self.option_price(ask=option_obj.ask,
                                                    bid=option_obj.bid)
        F = asset_price
        K = option_obj.strike
        r = self.risk_free_rate
        t = self.time_2_expiration(timestamp, expiration)
        flag = call_put_flag

        try:
            iv = vollib_iv.implied_volatility(discounted_option_price, F, K, r,
                                              t, flag)
        except Exception as e:
            print(e)
            iv = 0

        return iv