Ejemplo n.º 1
0
 def testLimitOrderTriggerSell(self):
     barsBuilder = broker_backtesting_test.BarsBuilder(INSTRUMENT, 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
     )
Ejemplo n.º 2
0
 def testLimitOrderTriggerBuy(self):
     barsBuilder = broker_backtesting_test.BarsBuilder(INSTRUMENT, 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
     )
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)