def set_strike(self, val): """ Specifies a strike price """ d = {} for dic in self.data: if parse(dic['strike']) == val and val in self.strikes: d = dic break if d: self._price = parse(d.get('p')) or d.get('lastPrice') self.id = d.get('cid') self.exchange = d.get('e') self._bid = parse(d.get('b')) or d.get('bid', 0) self._ask = parse(d.get('a')) or d.get('ask', 0) self.strike = parse(d['strike']) self._change = parse(d.get('c')) or d.get('change', 0) # change in currency self._cp = parse(d.get('cp', 0)) or d.get('percentChange', 0) # percentage change self._volume = parse(d.get('vol')) or d.get('volume', 0) self._open_interest = parse(d.get('oi')) or d.get( 'openInterest', 0) self.code = d.get('s') or d.get('contractSymbol') self.itm = ( (self.__class__.Option_type == 'Call' and self.underlying.price > self.strike) or (self.__class__.Option_type == 'Put' and self.underlying.price < self.strike)) # in the money self.BandS = BlackandScholes(self.underlying.price, self.strike, self.T, self._price, self.rate(self.T), self.__class__.Option_type, self.q) else: raise LookupError('No options listed for given strike price.')
def set_strike(self, val): d = {} for dic in self.data: if parse(dic['strike']) == val and val in self.strikes: d = dic break if d: self._price = parse(d['p']) self.id = d['cid'] self.exchange = d['e'] self._bid = parse(d['b']) self._ask = parse(d['a']) self.strike = parse(d['strike']) self._change = parse(d.get('c', 0)) # change in currency self._cp = parse(d.get('cp', 0)) # percentage change self._volume = parse(d['vol']) self._open_interest = parse(d['oi']) self.code = d['s'] self.ticker = self.code[:-15] self.BandS = BlackandScholes( self.underlying.price, self.strike, self.T, self._price, rate(self.T), self.__class__.Option_type, self.q ) else: raise LookupError('No options listed for given strike price.')