def testLimitOrderTriggerBuy(self): barsBuilder = broker_backtesting_test.BarsBuilder(BaseTestCase.TestInstrument, bar.Frequency.MINUTE) # Bar is above self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(15, 15, 15, 15)), None) self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(15, 16, 11, 15)), None) # Low touches self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(15, 16, 10, 11)), 10) # Low penetrates self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(15, 16, 9, 11)), 10) # Open touches self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(10, 10, 10, 10)), 10) # Open is below self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(9, 12, 4, 9)), 9) # Bar gaps below self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.BUY, 10, False, barsBuilder.nextBar(8, 9, 6, 9)), 8)
def testLimitOrderTriggerSell(self): barsBuilder = broker_backtesting_test.BarsBuilder(BaseTestCase.TestInstrument, bar.Frequency.MINUTE) # Bar is below self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(5, 5, 5, 5)), None) self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(5, 6, 4, 5)), None) # High touches self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(5, 10, 4, 9)), 10) # High penetrates self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(5, 11, 4, 9)), 10) # Open touches self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(10, 10, 10, 10)), 10) # Open is above self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(11, 12, 4, 9)), 11) # Bar gaps above self.assertEqual(fillstrategy.get_limit_price_trigger(broker.Order.Action.SELL, 10, False, barsBuilder.nextBar(12, 13, 11, 12)), 12)
def setUp(self): BaseTestCase.setUp(self) self.priceImpact = 0.1 self.slippage = slippage.VolumeShareSlippage(self.priceImpact) self.barsBuilder = broker_backtesting_test.BarsBuilder( BaseTestCase.TestInstrument, bar.Frequency.DAY)
def setUp(self): BaseTestCase.setUp(self) self.slippage = slippage.NoSlippage() self.barsBuilder = broker_backtesting_test.BarsBuilder( BaseTestCase.TestInstrument, bar.Frequency.DAY)
def setUp(self): BaseTestCase.setUp(self) self.barsBuilder = broker_backtesting_test.BarsBuilder(BaseTestCase.TestInstrument, bar.Frequency.MINUTE) self.strategy = fillstrategy.DefaultStrategy()