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 is_rollover(self): if len(self.position) != 0: for p in self.position.legs.values(): rh = RolloverHelper(p.instrument) if rh.is_rollover(p): return True return False