def test_is_rollover(self): inst_dict = {'name': 'TEST', 'futures': []} dinst = DummyInstrument(inst_dict) rh = RolloverHelper(dinst) rh.rollover_months = [1, 3] rh.days_before_expiration = 10 contr = DummyContract({ 'days': 20, 'name': 'fut1', 'expiration': datetime(2015, 1, 10), 'options': [] }) self.assertEqual(rh.is_rollover(contr), False) contr = DummyContract({ 'days': 10, 'name': 'fut1', 'expiration': datetime(2015, 1, 10), 'options': [] }) self.assertEqual(rh.is_rollover(contr), True) contr = DummyContract({ 'days': 1, 'name': 'fut1', 'expiration': datetime(2015, 1, 10), 'options': [] }) self.assertEqual(rh.is_rollover(contr), True)
def test_active_chains_rollover_options_no_options_chains(self): inst_dict = { 'name': 'TEST', 'futures': [{ 'days': 20, 'name': 'fut1', 'expiration': datetime(2015, 1, 10), 'options': [] }, { 'days': 20, 'name': 'fut2', 'expiration': datetime(2015, 2, 10), 'options': [] }, { 'days': 40, 'name': 'fut3', 'expiration': datetime(2015, 3, 10), 'options': [] }] } dinst = DummyInstrument(inst_dict) rh = RolloverHelper(dinst) rh.rollover_months = [1, 3] rh.days_before_expiration = 10 fut, opt = rh.get_active_chains() self.assertEqual(fut.name, 'fut1') self.assertEqual(opt, None)
def test_active_chains_rollover_options_no_futures(self): inst_dict = {'name': 'TEST', 'futures': []} dinst = DummyInstrument(inst_dict) rh = RolloverHelper(dinst) rh.rollover_months = [1, 3] rh.days_before_expiration = 10 fut, opt = rh.get_active_chains() self.assertEqual(fut, None) self.assertEqual(opt, None)