def test_nearest_column_round_down(data_dod_greeks, value): # here we test for mid-point, values returned should round down. chain = op.OptionQuery(data_dod_greeks).nearest(value[0], value[1], 'rounddown').fetch() values = chain[value[0]].unique() assert len(values) == 1 assert values[0] == value[2]
def update(self, date): # current quote date self.now = date # we will slice our spread_data by today's date latest_quote = op.OptionQuery(self.spread_data.loc[self.now]) # run entry filters against our current quote prices if defined if self.filters is not None: self.filter_stack(self, latest_quote) else: # if no filters provided, use the logic in the overridden on_update function self.on_update(latest_quote)
def vertical_strategies(request): data = op.option_strategy.Vertical(option_type=request.param[1], width=request.param[2])( request.param[0]()) return op.OptionQuery(data)
def test_lte(data_dod_greeks, value): chain = op.OptionQuery(data_dod_greeks).lte(value[0], value[1]) values = chain.oc[value[0]].unique() assert all(v <= value[1] for v in values)
def test_invalid_column_values(data_dod_greeks, value): with pytest.raises(ValueError): op.OptionQuery(data_dod_greeks)._check_inputs(value[0], value[1])
def test_option_query_init(): with pytest.raises(ValueError): op.OptionQuery(op.OptionStrategy())
def test_without_underlying_price(data_dod_greeks): with pytest.raises(ValueError): op.OptionQuery(data_dod_greeks).underlying_price()
def test_underlying_price(data_dod_underlying): chain = op.OptionQuery(data_dod_underlying).underlying_price() assert chain == 40.55
def test_option_type(data_dod_greeks, option_type): chain = op.OptionQuery(data_dod_greeks).option_type(option_type).fetch().option_type.unique() assert len(chain) == 1 assert chain[0] == option_type.value[0]
def test_invalid_option_type(data_dod_greeks, option_type): with pytest.raises(ValueError): op.OptionQuery(data_dod_greeks).option_type(option_type)
def test_between(data_dod_greeks, value): chain = op.OptionQuery(data_dod_greeks).between(value[0], value[1], value[2]) values = chain.oc[value[0]].unique() assert all(value[1] <= v <= value[2] for v in values)
def test_puts(data_dod_greeks): puts = op.OptionQuery(data_dod_greeks).puts().fetch().option_type.unique() assert len(puts) == 1 assert puts[0] == 'p'
def test_calls(data_dod_greeks): calls = op.OptionQuery(data_dod_greeks).calls().fetch().option_type.unique() assert len(calls) == 1 assert calls[0] == 'c'