예제 #1
0
 def __init__(self,
              underlying_pair,
              db,
              underlying_price=None,
              expirations=[],
              strikes={},
              atm_volatility=0.5,
              interest_rate=0):
     self.underlying_pair = underlying_pair
     self.db = db
     self.underlying_price = underlying_price
     self.expirations = expirations
     self.strikes = {e: strikes for e in self.expirations}
     self.atm_volatility = atm_volatility
     self.interest_rate = interest_rate
     self.currency = self.underlying_pair.split('/')[0]
     self.time = utils.get_current_time()
     self.options = {'call': {}, 'put': {}}
     self.exchange_symbols = []
     self.options_by_name = {}
     self.underlying_exchange_symbol = self.get_exchange_symbol(
         pair=self.underlying_pair)
     self.client = None
     if underlying_price is None:
         self.setup_client()
         self.get_underlying_price()
 def get_metadata(self, timestamp=None):
     if timestamp is None:
         timestamp = str(utils.get_current_time())
     return {
         'timestamp': timestamp,
         'expiry': str(self.expiry)[:10],
         'type': self.option_type,
         'strike': str(self.strike),
         'delta': str(self.delta),
         'gamma': str(self.gamma),
         'theta': str(self.theta),
         'wvega': str(self.wvega),
         'vega': str(self.vega),
         'vol': str(self.vol),
         'best_bid': str(self.best_bid),
         'best_ask': str(self.best_ask),
         'exchange_symbol': self.exchange_symbol
     }
예제 #3
0
 def iterate_options(self):
     expirys_to_remove = []
     for option_type in self.options:
         for expiry in self.options[option_type]:
             if expiry > utils.get_current_time():
                 for strike in self.options[option_type][expiry]:
                     yield self.options[option_type][expiry][strike]
             else:
                 logging.info("Expiry to remove: " + str(expiry))
                 expirys_to_remove.append(expiry)
     if expirys_to_remove:
         for option_type in self.options:
             self.options[option_type] = {
                 k: v
                 for k, v in self.options[option_type].items()
                 if k not in expirys_to_remove
             }
             logging.info("Expirys after removal: " +
                          str(self.options[option_type]))
 def __init__(self,
              underlying_pair,
              option_type,
              strike,
              expiry,
              interest_rate=0,
              volatility=None,
              underlying_price=None,
              time=utils.get_current_time(),
              exchange_symbol=None):
     self.underlying_pair = underlying_pair
     if not option_type == 'call' and not option_type == 'put':
         raise ValueError('Expected "call" or "put", got ' + option_type)
     self.option_type = option_type
     self.strike = int(strike)
     self.expiry = expiry
     self.interest_rate = interest_rate
     if volatility is not None:
         self.vol = volatility
     else:
         self.vol = None
     self.underlying_price = underlying_price
     self.time = time
     self.exchange_symbol = exchange_symbol
     self.time_left = self.get_time_left(self.time)
     self.d1 = None
     self.d2 = None
     self.theo = None
     self.delta = None
     self.gamma = None
     self.theta = None
     self.vega = None
     self.wvega = None
     self.present_value = None
     self.mid_market = None
     self.best_bid = None
     self.best_ask = None
 def get_time_left(self, current_datetime=utils.get_current_time()):
     return (self.expiry - current_datetime).total_seconds() / (day * 365)