Ejemplo n.º 1
0
def get_greeks(trades):
    lots = []
    op_objects = []
    for trade in trades:
        if trade['op_type'] == 'CE':
            op_objects.append(
                qbdp.EqOption(option_type='Call',
                              strike=trade['price'] / scale,
                              expiry_date=datetime.strftime(
                                  expiry_dt, "%Y%m%d"),
                              expiry_type='European'))
            lots.append(trade['num_lots'])
        elif trade['op_type'] == 'PE':
            op_objects.append(
                qbdp.EqOption(option_type='Put',
                              strike=trade['price'] / scale,
                              expiry_date=datetime.strftime(
                                  expiry_dt, "%Y%m%d"),
                              expiry_type='European'))
            lots.append(trade['num_lots'])
        else:
            time.sleep(0.01)
            #print ("Future")

    custom_option = [(op_objects[i], lots[i]) for i in range(len(lots))]
    custom_stgy1 = qbdp.OptionStr1Udl(option_portfolio=custom_option)
    eq1_engine = custom_stgy1.engine(model='BSM',
                                     pricing_date=datetime.strftime(
                                         datetime.now(), "%Y%m%d"),
                                     spot0=spot_price,
                                     rf_rate=3.68,
                                     volatility=0.25)
    #print(eq1_engine.risk_parameters())
    greeks = eq1_engine.risk_parameters()
    return greeks['delta'], greeks['theta'], greeks['vega'], greeks['gamma']
Ejemplo n.º 2
0
def greeks(pos,
           ticker,
           target_value,
           flag,
           S,
           K,
           t0,
           t1,
           r,
           div,
           px='',
           IV_only=False):

    if flag == 'C':
        call_put = 'Call'
    else:
        call_put = "Put"

    d1 = datetime.strptime(t1, '%Y%m%d')
    d0 = datetime.strptime(t0, '%Y%m%d')

    delta = d1 - d0
    delta_annual = delta.days / 365

    sigma = BSM.implied_volatility(target_value, S, K, delta_annual, r, div,
                                   flag.lower())

    if IV_only == False:
        risk_parameters = {
            'delta_spot': 0.02,
            'delta_vol': 0.02,
            'delta_rf_rate': 0.02,
            'delta_time': 1
        }  # TODO Fix with next quantsbin release

        equity_o = qbdp.EqOption(option_type=call_put,
                                 strike=K,
                                 expiry_date=t1,
                                 expiry_type='American')
        engine = equity_o.engine(model="Binomial",
                                 spot0=S,
                                 pricing_date=t0,
                                 rf_rate=r,
                                 yield_div=div,
                                 volatility=sigma)

        greeks = engine.risk_parameters(**risk_parameters)
        greeks['Contract'] = [ticker, t1, str(K), flag]
        greeks['IV'] = sigma

        if px == '':
            greeks['Avg px'] = target_value
        else:
            greeks['Avg px'] = px
        greeks['DTE'] = delta.days
        greeks['pos'] = pos
        # print(greeks)
        return greeks
    else:
        return sigma
Ejemplo n.º 3
0
    1. Equity: qbdp.EqOption
    2. Futures: qbdp.FutOption
    3. Currencies: qbdp.FXOption
    4. Commodities: qbdp.ComOption
    
 Let's check doc string to get more information about Option objects.
"""

print(qbdp.EqOption.__doc__)
"""We can observe above that therevare five argumnents which are required for deifning an option.

Let's deifne our own Equity call option with European expiry.
"""

equity_option1 = qbdp.EqOption(option_type='Call',
                               strike=57.5,
                               expiry_date='20200320',
                               expiry_type='European')
"""**Congrates!!!** you have defined you first option. Let's explore more into this option.

We will start with calculating payoff given Spot (current underlying price) is 55.
"""

print(equity_option1.payoff(58))
"""### Plotting Payoff

Let's plot the payoff profile for this option.

qbdp.Plotting takes first argument as option object, second argument as parameter to be plotted and this argument as range for which plot is required.

**Payoff Plotting**
"""
Ejemplo n.º 4
0
"""
    developed by Quantsbin - Jun'18

"""

import quantsbin.derivativepricing as qbdp

import quantsbin.derivativepricing.plotting as pt


"""Defining options"""
eqOption1 = qbdp.EqOption(option_type='Call', strike=100, expiry_date='20180630', expiry_type='European')
eqOption2 = qbdp.EqOption(option_type='Call', strike=110, expiry_date='20180630', expiry_type='European')

fxOption1 = qbdp.FXOption(option_type='Call', strike=98, expiry_date='20190630', expiry_type='European')
fxOption2 = qbdp.FXOption(option_type='Put', strike=95, expiry_date='20180630', expiry_type='American')

futOption1 = qbdp.FutOption(option_type='Put', strike=102, expiry_date='20190630', expiry_type='American')
futOption2 = qbdp.FutOption(option_type='Call', strike=95, expiry_date='20180630', expiry_type='European')

comOption1 = qbdp.ComOption(option_type='Put', strike=95, expiry_date='20190630', expiry_type='European')
comOption2 = qbdp.ComOption(option_type='Call', strike=105, expiry_date='20190630', expiry_type='American')

"""Creating list of all defined option for consolidate testing"""

# option_list = [eqOption1, eqOption2, fxOption1, fxOption2, futOption1, futOption2, comOption1, comOption2]
#
# # print(eqOption2.payoff(0))
#
# """Payoff plot testing"""
# for option in option_list:
Ejemplo n.º 5
0
 def setUp(self):
     self.eq_option = qbdp.EqOption(**Input['equityInst'])
     self.eq_option_engine = self.eq_option.engine(**Input['equityEng'])