diff --git a/pyalgotrade/feed/memfeed.py b/pyalgotrade/feed/memfeed.py index e9a82b55e..823740a9b 100644 --- a/pyalgotrade/feed/memfeed.py +++ b/pyalgotrade/feed/memfeed.py @@ -23,7 +23,7 @@ class MemFeed(feed.BaseFeed): def __init__(self, maxLen=None): - super(MemFeed, self).__init__(maxLen, False) + super(MemFeed, self).__init__(maxLen) self.__values = [] self.__nextIdx = 0 diff --git a/testcases/bar_test.py b/testcases/bar_test.py index 83695685a..0304577c1 100644 --- a/testcases/bar_test.py +++ b/testcases/bar_test.py @@ -42,30 +42,30 @@ def testInvalidConstruction(self): def testTypicalPrice(self): b = bar.BasicBar(datetime.datetime.now(), 2, 3, 1, 2.1, 10, 5, bar.Frequency.DAY) - self.assertEquals(b.getTypicalPrice(), (3 + 1 + 2.1) / 3) + self.assertEqual(b.getTypicalPrice(), (3 + 1 + 2.1) / 3) def testGetPrice(self): b = bar.BasicBar(datetime.datetime.now(), 2, 3, 1, 2.1, 10, 5, bar.Frequency.DAY) - self.assertEquals(b.getPrice(), b.getClose()) + self.assertEqual(b.getPrice(), b.getClose()) b.setUseAdjustedValue(True) - self.assertEquals(b.getPrice(), b.getAdjClose()) + self.assertEqual(b.getPrice(), b.getAdjClose()) def testPickle(self): b1 = bar.BasicBar(datetime.datetime.now(), 2, 3, 1, 2.1, 10, 5, bar.Frequency.DAY) b2 = cPickle.loads(cPickle.dumps(b1)) - self.assertEquals(b1.getDateTime(), b2.getDateTime()) - self.assertEquals(b1.getOpen(), b2.getOpen()) - self.assertEquals(b1.getHigh(), b2.getHigh()) - self.assertEquals(b1.getLow(), b2.getLow()) - self.assertEquals(b1.getClose(), b2.getClose()) - self.assertEquals(b1.getVolume(), b2.getVolume()) - self.assertEquals(b1.getAdjClose(), b2.getAdjClose()) - self.assertEquals(b1.getFrequency(), b2.getFrequency()) - self.assertEquals(b1.getPrice(), b2.getPrice()) - self.assertEquals(b1.getOpen(True), b2.getOpen(True)) - self.assertEquals(b1.getHigh(True), b2.getHigh(True)) - self.assertEquals(b1.getLow(True), b2.getLow(True)) - self.assertEquals(b1.getClose(True), b2.getClose(True)) + self.assertEqual(b1.getDateTime(), b2.getDateTime()) + self.assertEqual(b1.getOpen(), b2.getOpen()) + self.assertEqual(b1.getHigh(), b2.getHigh()) + self.assertEqual(b1.getLow(), b2.getLow()) + self.assertEqual(b1.getClose(), b2.getClose()) + self.assertEqual(b1.getVolume(), b2.getVolume()) + self.assertEqual(b1.getAdjClose(), b2.getAdjClose()) + self.assertEqual(b1.getFrequency(), b2.getFrequency()) + self.assertEqual(b1.getPrice(), b2.getPrice()) + self.assertEqual(b1.getOpen(True), b2.getOpen(True)) + self.assertEqual(b1.getHigh(True), b2.getHigh(True)) + self.assertEqual(b1.getLow(True), b2.getLow(True)) + self.assertEqual(b1.getClose(True), b2.getClose(True)) def testNoAdjClose(self): b = bar.BasicBar(datetime.datetime.now(), 2, 3, 1, 2.1, 10, None, bar.Frequency.DAY) @@ -97,11 +97,11 @@ def testBasic(self): b1 = bar.BasicBar(dt, 1, 1, 1, 1, 10, 1, bar.Frequency.DAY) b2 = bar.BasicBar(dt, 2, 2, 2, 2, 10, 2, bar.Frequency.DAY) bars = bar.Bars({"a": b1, "b": b2}) - self.assertEquals(bars["a"].getClose(), 1) - self.assertEquals(bars["b"].getClose(), 2) + self.assertEqual(bars["a"].getClose(), 1) + self.assertEqual(bars["b"].getClose(), 2) self.assertTrue("a" in bars) - self.assertEquals(bars.items(), [("a", b1), ("b", b2)]) - self.assertEquals(bars.keys(), ["a", "b"]) - self.assertEquals(bars.getInstruments(), ["a", "b"]) - self.assertEquals(bars.getDateTime(), dt) - self.assertEquals(bars.getBar("a").getClose(), 1) + self.assertEqual(bars.items(), [("a", b1), ("b", b2)]) + self.assertEqual(bars.keys(), ["a", "b"]) + self.assertEqual(bars.getInstruments(), ["a", "b"]) + self.assertEqual(bars.getDateTime(), dt) + self.assertEqual(bars.getBar("a").getClose(), 1) diff --git a/testcases/barfeed_test.py b/testcases/barfeed_test.py index 73e377afd..4f981d385 100644 --- a/testcases/barfeed_test.py +++ b/testcases/barfeed_test.py @@ -33,12 +33,12 @@ def check_base_barfeed(testCase, barFeed, barsHaveAdjClose): def callback(dateTime, bars): called["called"] = True - testCase.assertEquals(barFeed.getCurrentDateTime(), dateTime) + testCase.assertEqual(barFeed.getCurrentDateTime(), dateTime) - testCase.assertEquals(barFeed.getCurrentDateTime(), None) - testCase.assertEquals(barFeed.barsHaveAdjClose(), barsHaveAdjClose) + testCase.assertEqual(barFeed.getCurrentDateTime(), None) + testCase.assertEqual(barFeed.barsHaveAdjClose(), barsHaveAdjClose) if not barsHaveAdjClose: - with testCase.assertRaisesRegexp(Exception, "The barfeed doesn't support adjusted close values.*"): + with testCase.assertRaisesRegex(Exception, "The barfeed doesn't support adjusted close values.*"): barFeed.setUseAdjustedValues(True) d = dispatcher.Dispatcher() @@ -46,7 +46,7 @@ def callback(dateTime, bars): barFeed.getNewValuesEvent().subscribe(callback) d.run() - testCase.assertEquals(called["called"], True) + testCase.assertEqual(called["called"], True) class OptimizerBarFeedTestCase(common.TestCase): @@ -56,7 +56,7 @@ def testDateTimesNotInOrder(self): bar.Bars({"orcl": bar.BasicBar(datetime.datetime(2001, 1, 1), 1, 1, 1, 1, 1, 1, bar.Frequency.DAY)}), ] f = barfeed.OptimizerBarFeed(bar.Frequency.DAY, ["orcl"], bars) - with self.assertRaisesRegexp(Exception, "Bar date times are not in order.*"): + with self. assertRaisesRegex(Exception, "Bar date times are not in order.*"): for dt, b, freq in f: pass @@ -78,7 +78,7 @@ def testBaseBarFeedNoAdjClose(self): def testEmtpy(self): barFeed = barfeed.OptimizerBarFeed(bar.Frequency.DAY, ["orcl"], []) - self.assertEquals(barFeed.barsHaveAdjClose(), False) + self.assertEqual(barFeed.barsHaveAdjClose(), False) class CommonTestCase(common.TestCase): diff --git a/testcases/bitstamp_test.py b/testcases/bitstamp_test.py index 815ecf798..aceb3f05d 100644 --- a/testcases/bitstamp_test.py +++ b/testcases/bitstamp_test.py @@ -219,12 +219,12 @@ def __onOrderBookUpdate(self, orderBookUpdate): class InstrumentTraitsTestCase(tc_common.TestCase): def testInstrumentTraits(self): traits = common.BTCTraits() - self.assertEquals(traits.roundQuantity(0), 0) - self.assertEquals(traits.roundQuantity(1), 1) - self.assertEquals(traits.roundQuantity(1.1 + 1.1 + 1.1), 3.3) - self.assertEquals(traits.roundQuantity(1.1 + 1.1 + 1.1 - 3.3), 0) - self.assertEquals(traits.roundQuantity(0.00441376), 0.00441376) - self.assertEquals(traits.roundQuantity(0.004413764), 0.00441376) + self.assertEqual(traits.roundQuantity(0), 0) + self.assertEqual(traits.roundQuantity(1), 1) + self.assertEqual(traits.roundQuantity(1.1 + 1.1 + 1.1), 3.3) + self.assertEqual(traits.roundQuantity(1.1 + 1.1 + 1.1 - 3.3), 0) + self.assertEqual(traits.roundQuantity(0.00441376), 0.00441376) + self.assertEqual(traits.roundQuantity(0.004413764), 0.00441376) class BacktestingTestCase(tc_common.TestCase): @@ -244,10 +244,10 @@ def onBars(self, bars): brk = broker.BacktestingBroker(100, barFeed) strat = TestStrategy(barFeed, brk) strat.run() - self.assertEquals(strat.pos.getShares(), 1) - self.assertEquals(strat.pos.entryActive(), False) - self.assertEquals(strat.pos.isOpen(), True) - self.assertEquals(strat.pos.getEntryOrder().getAvgFillPrice(), 5.83) + self.assertEqual(strat.pos.getShares(), 1) + self.assertEqual(strat.pos.entryActive(), False) + self.assertEqual(strat.pos.isOpen(), True) + self.assertEqual(strat.pos.getEntryOrder().getAvgFillPrice(), 5.83) def testMinTrade(self): class TestStrategy(strategy.BaseStrategy): @@ -263,7 +263,7 @@ def onBars(self, bars): barFeed.addBarsFromCSV(tc_common.get_data_file_path("bitstampUSD.csv")) brk = broker.BacktestingBroker(100, barFeed) strat = TestStrategy(barFeed, brk) - with self.assertRaisesRegexp(Exception, "Trade must be >= 5"): + with self. assertRaisesRegex(Exception, "Trade must be >= 5"): strat.run() @@ -290,9 +290,9 @@ def onBars(self, bars): strat.run() self.assertTrue(strat.pos.isOpen()) - self.assertEquals(round(strat.pos.getShares(), 3), 0.3) - self.assertEquals(len(strat.posExecutionInfo), 1) - self.assertEquals(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(round(strat.pos.getShares(), 3), 0.3) + self.assertEqual(len(strat.posExecutionInfo), 1) + self.assertEqual(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) def testBuyAndSellWithPartialFill1(self): @@ -320,10 +320,10 @@ def onBars(self, bars): strat.run() self.assertTrue(strat.pos.isOpen()) - self.assertEquals(round(strat.pos.getShares(), 3), 0.1) - self.assertEquals(len(strat.posExecutionInfo), 1) - self.assertEquals(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) - self.assertEquals(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(round(strat.pos.getShares(), 3), 0.1) + self.assertEqual(len(strat.posExecutionInfo), 1) + self.assertEqual(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) def testBuyAndSellWithPartialFill2(self): @@ -352,10 +352,10 @@ def onBars(self, bars): strat.run() self.assertFalse(strat.pos.isOpen()) - self.assertEquals(strat.pos.getShares(), 0) - self.assertEquals(len(strat.posExecutionInfo), 2) - self.assertEquals(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) - self.assertEquals(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(strat.pos.getShares(), 0) + self.assertEqual(len(strat.posExecutionInfo), 2) + self.assertEqual(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) def testRoundingBugWithTrades(self): # Unless proper rounding is in place 0.01 - 0.00441376 - 0.00445547 - 0.00113077 == 6.50521303491e-19 @@ -383,19 +383,19 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(brk.getShares("BTC"), 0) - self.assertEquals(strat.pos.getEntryOrder().getAvgFillPrice(), 1000) - self.assertEquals(strat.pos.getExitOrder().getAvgFillPrice(), 1000) - self.assertEquals(strat.pos.getEntryOrder().getFilled(), 0.01) - self.assertEquals(strat.pos.getExitOrder().getFilled(), 0.01) - self.assertEquals(strat.pos.getEntryOrder().getRemaining(), 0) - self.assertEquals(strat.pos.getExitOrder().getRemaining(), 0) - self.assertEquals(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) - self.assertEquals(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(brk.getShares("BTC"), 0) + self.assertEqual(strat.pos.getEntryOrder().getAvgFillPrice(), 1000) + self.assertEqual(strat.pos.getExitOrder().getAvgFillPrice(), 1000) + self.assertEqual(strat.pos.getEntryOrder().getFilled(), 0.01) + self.assertEqual(strat.pos.getExitOrder().getFilled(), 0.01) + self.assertEqual(strat.pos.getEntryOrder().getRemaining(), 0) + self.assertEqual(strat.pos.getExitOrder().getRemaining(), 0) + self.assertEqual(strat.pos.getEntryOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) + self.assertEqual(strat.pos.getExitOrder().getSubmitDateTime().date(), wsclient.get_current_datetime().date()) self.assertFalse(strat.pos.isOpen()) - self.assertEquals(len(strat.posExecutionInfo), 2) - self.assertEquals(strat.pos.getShares(), 0.0) + self.assertEqual(len(strat.posExecutionInfo), 2) + self.assertEqual(strat.pos.getShares(), 0.0) def testInvalidOrders(self): barFeed = TestingLiveTradeFeed() @@ -433,9 +433,9 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(strat.errors, 4) - self.assertEquals(brk.getShares("BTC"), 0) - self.assertEquals(brk.getCash(), 0) + self.assertEqual(strat.errors, 4) + self.assertEqual(brk.getShares("BTC"), 0) + self.assertEqual(brk.getCash(), 0) def testRanOutOfCash(self): class Strategy(TestStrategy): @@ -458,9 +458,9 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(strat.errors, 2) - self.assertEquals(brk.getShares("BTC"), 0.1) - self.assertEquals(brk.getCash(), 0) + self.assertEqual(strat.errors, 2) + self.assertEqual(brk.getShares("BTC"), 0.1) + self.assertEqual(brk.getCash(), 0) def testSellWithoutBTC(self): class Strategy(TestStrategy): @@ -482,9 +482,9 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(strat.errors, 2) - self.assertEquals(brk.getShares("BTC"), 0) - self.assertEquals(brk.getCash(), 0) + self.assertEqual(strat.errors, 2) + self.assertEqual(brk.getShares("BTC"), 0) + self.assertEqual(brk.getCash(), 0) def testRanOutOfCoins(self): class Strategy(TestStrategy): @@ -512,9 +512,9 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(strat.errors, 1) - self.assertEquals(brk.getShares("BTC"), 0) - self.assertEquals(brk.getCash(), 10) + self.assertEqual(strat.errors, 1) + self.assertEqual(brk.getShares("BTC"), 0) + self.assertEqual(brk.getCash(), 10) class LiveTradingTestCase(tc_common.TestCase): @@ -544,15 +544,15 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(len(strat.orderExecutionInfo), 2) - self.assertEquals(strat.orderExecutionInfo[0].getPrice(), 578.79) - self.assertEquals(strat.orderExecutionInfo[0].getQuantity(), 0.04557395) - self.assertEquals(strat.orderExecutionInfo[0].getCommission(), 0.14) - self.assertEquals(strat.orderExecutionInfo[0].getDateTime().date(), datetime.datetime.now().date()) - self.assertEquals(strat.orderExecutionInfo[1].getPrice(), 567.21) - self.assertEquals(strat.orderExecutionInfo[1].getQuantity(), 0.04601436) - self.assertEquals(strat.orderExecutionInfo[1].getCommission(), 0.14) - self.assertEquals(strat.orderExecutionInfo[1].getDateTime().date(), datetime.datetime.now().date()) + self.assertEqual(len(strat.orderExecutionInfo), 2) + self.assertEqual(strat.orderExecutionInfo[0].getPrice(), 578.79) + self.assertEqual(strat.orderExecutionInfo[0].getQuantity(), 0.04557395) + self.assertEqual(strat.orderExecutionInfo[0].getCommission(), 0.14) + self.assertEqual(strat.orderExecutionInfo[0].getDateTime().date(), datetime.datetime.now().date()) + self.assertEqual(strat.orderExecutionInfo[1].getPrice(), 567.21) + self.assertEqual(strat.orderExecutionInfo[1].getQuantity(), 0.04601436) + self.assertEqual(strat.orderExecutionInfo[1].getCommission(), 0.14) + self.assertEqual(strat.orderExecutionInfo[1].getDateTime().date(), datetime.datetime.now().date()) def testCancelOrder(self): class Strategy(TestStrategy): @@ -577,11 +577,11 @@ def onBars(self, bars): strat = Strategy(barFeed, brk) strat.run() - self.assertEquals(brk.getShares("BTC"), 0) - self.assertEquals(brk.getCash(), 0) - self.assertEquals(len(strat.orderExecutionInfo), 1) - self.assertEquals(strat.orderExecutionInfo[0], None) - self.assertEquals(len(strat.ordersUpdated), 1) + self.assertEqual(brk.getShares("BTC"), 0) + self.assertEqual(brk.getCash(), 0) + self.assertEqual(len(strat.orderExecutionInfo), 1) + self.assertEqual(strat.orderExecutionInfo[0], None) + self.assertEqual(len(strat.ordersUpdated), 1) self.assertTrue(strat.ordersUpdated[0].isCanceled()) def testBuyAndSell(self): @@ -621,17 +621,17 @@ def onBars(self, bars): self.assertTrue(strat.buyOrder.isPartiallyFilled()) self.assertTrue(strat.sellOrder.isFilled()) # 2 events for each order: 1 for accepted, 1 for fill. - self.assertEquals(len(strat.orderExecutionInfo), 4) - self.assertEquals(strat.orderExecutionInfo[0], None) - self.assertEquals(strat.orderExecutionInfo[1].getPrice(), 10) - self.assertEquals(strat.orderExecutionInfo[1].getQuantity(), 0.5) - self.assertEquals(strat.orderExecutionInfo[1].getCommission(), 0.01) - self.assertEquals(strat.orderExecutionInfo[1].getDateTime().date(), datetime.datetime.now().date()) - self.assertEquals(strat.orderExecutionInfo[2], None) - self.assertEquals(strat.orderExecutionInfo[3].getPrice(), 10) - self.assertEquals(strat.orderExecutionInfo[3].getQuantity(), 0.5) - self.assertEquals(strat.orderExecutionInfo[3].getCommission(), 0.01) - self.assertEquals(strat.orderExecutionInfo[3].getDateTime().date(), datetime.datetime.now().date()) + self.assertEqual(len(strat.orderExecutionInfo), 4) + self.assertEqual(strat.orderExecutionInfo[0], None) + self.assertEqual(strat.orderExecutionInfo[1].getPrice(), 10) + self.assertEqual(strat.orderExecutionInfo[1].getQuantity(), 0.5) + self.assertEqual(strat.orderExecutionInfo[1].getCommission(), 0.01) + self.assertEqual(strat.orderExecutionInfo[1].getDateTime().date(), datetime.datetime.now().date()) + self.assertEqual(strat.orderExecutionInfo[2], None) + self.assertEqual(strat.orderExecutionInfo[3].getPrice(), 10) + self.assertEqual(strat.orderExecutionInfo[3].getQuantity(), 0.5) + self.assertEqual(strat.orderExecutionInfo[3].getCommission(), 0.01) + self.assertEqual(strat.orderExecutionInfo[3].getDateTime().date(), datetime.datetime.now().date()) class WebSocketTestCase(tc_common.TestCase): diff --git a/testcases/broker_backtesting_test.py b/testcases/broker_backtesting_test.py index 0df4d7992..221801f0b 100644 --- a/testcases/broker_backtesting_test.py +++ b/testcases/broker_backtesting_test.py @@ -96,7 +96,7 @@ def roundQuantity(self, quantity): class BarFeed(barfeed.BaseBarFeed): def __init__(self, instrument, frequency): - barfeed.BaseBarFeed.__init__(self, frequency) + barfeed.BaseBarFeed.__init__(self, [frequency]) self.__builder = BarsBuilder(instrument, frequency) self.__nextBars = None @@ -168,9 +168,9 @@ def onOrderEvent(broker_, orderEvent): # Buy order. order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) self.assertTrue(order.isFilled()) @@ -180,14 +180,14 @@ def onOrderEvent(broker_, orderEvent): # Create a sell limit and a stop loss order. order = brk.createLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 11, 1) orders["sell"] = order - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) order = brk.createStopOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 8, 1) orders["stoploss"] = order - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 5, 12) # Only one order (the sell limit order) should have got filled. The other one should be canceled. @@ -207,13 +207,13 @@ def onOrderEvent(brk, orderEvent): brk.getOrderUpdatedEvent().subscribe(onOrderEvent) o1 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(o1.getSubmitDateTime(), None) + self.assertEqual(o1.getSubmitDateTime(), None) brk.submitOrder(o1) - self.assertEquals(o1.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(o1.getSubmitDateTime(), barFeed.getCurrentDateTime()) o2 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(o2.getSubmitDateTime(), None) + self.assertEqual(o2.getSubmitDateTime(), None) brk.submitOrder(o2) - self.assertEquals(o2.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(o2.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(o1.getFilled(), 0) self.assertEqual(o2.getFilled(), 0) @@ -222,8 +222,8 @@ def onOrderEvent(brk, orderEvent): barFeed.dispatchBars(10, 15, 8, 12) - self.assertNotEquals(o1.getSubmitDateTime(), barFeed.getCurrentDateTime()) - self.assertNotEquals(o2.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertNotEqual(o1.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertNotEqual(o2.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(o1.getFilled(), 1) self.assertEqual(o2.getFilled(), 1) @@ -241,9 +241,9 @@ def testVolumeLimitMinuteBars(self): brk = self.buildBroker(1000, barFeed) order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 3) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 3) @@ -265,9 +265,9 @@ def testVolumeLimitTradeBars(self): # Try with different order types. order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 3) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 3) @@ -294,9 +294,9 @@ def onOrderEvent(broker, orderEvent): brk.getOrderUpdatedEvent().subscribe(onOrderEvent) order = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) # Check that cancelation event gets emited right away. @@ -312,24 +312,24 @@ def onOrderEvent(broker_, orderEvent): if orderEvent.getEventType() != broker.OrderEvent.Type.SUBMITTED: ordersUpdated.append(orderEvent.getOrder()) newOrder = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(newOrder.getSubmitDateTime(), None) + self.assertEqual(newOrder.getSubmitDateTime(), None) brk.submitOrder(newOrder) - self.assertEquals(newOrder.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(newOrder.getSubmitDateTime(), barFeed.getCurrentDateTime()) brk.getOrderUpdatedEvent().subscribe(onOrderEvent) # The first order gets submitted. firstOrder = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2, 1) - self.assertEquals(firstOrder.getSubmitDateTime(), None) + self.assertEqual(firstOrder.getSubmitDateTime(), None) brk.submitOrder(firstOrder) - self.assertEquals(firstOrder.getSubmitDateTime(), barFeed.getCurrentDateTime()) - self.assertEquals(len(ordersUpdated), 0) + self.assertEqual(firstOrder.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(len(ordersUpdated), 0) # The first order gets accepted, and the second one gets submitted.. barFeed.dispatchBars(10, 15, 8, 12) - self.assertEquals(len(ordersUpdated), 1) # First order got accepted. + self.assertEqual(len(ordersUpdated), 1) # First order got accepted. self.assertTrue(firstOrder in ordersUpdated) - self.assertEquals(len(brk.getActiveOrders()), 2) # Both orders are active. + self.assertEqual(len(brk.getActiveOrders()), 2) # Both orders are active. # Check that the first one was accepted, and the second one submitted. for activeOrder in brk.getActiveOrders(): if activeOrder.getId() == firstOrder.getId(): @@ -339,7 +339,7 @@ def onOrderEvent(broker_, orderEvent): # Second order should get accepted and filled. barFeed.dispatchBars(10, 15, 8, 12) - self.assertEquals(len(ordersUpdated), 3) + self.assertEqual(len(ordersUpdated), 3) self.assertTrue(firstOrder.isAccepted()) def testPartialFillAndCancel(self): @@ -348,9 +348,9 @@ def testPartialFillAndCancel(self): cb = OrderUpdateCallback(brk) order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 2 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 10) @@ -372,13 +372,13 @@ def testVolumeLimitPerBar1(self): brk = self.buildBroker(1000, barFeed) order1 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2) - self.assertEquals(order1.getSubmitDateTime(), None) + self.assertEqual(order1.getSubmitDateTime(), None) brk.submitOrder(order1) - self.assertEquals(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) order2 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2) - self.assertEquals(order2.getSubmitDateTime(), None) + self.assertEqual(order2.getSubmitDateTime(), None) brk.submitOrder(order2) - self.assertEquals(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(12, 15, 8, 12, 10) # 2 should get filled for the first order. @@ -411,13 +411,13 @@ def testVolumeLimitPerBar2(self): brk = self.buildBroker(1000, barFeed) order1 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order1.getSubmitDateTime(), None) + self.assertEqual(order1.getSubmitDateTime(), None) brk.submitOrder(order1) - self.assertEquals(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) order2 = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order2.getSubmitDateTime(), None) + self.assertEqual(order2.getSubmitDateTime(), None) brk.submitOrder(order2) - self.assertEquals(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(12, 15, 8, 12, 10) # 1 should get filled for the first order. @@ -442,13 +442,13 @@ def testGetActiveOrders(self): brk = self.buildBroker(1000, barFeed) order1 = brk.createMarketOrder(broker.Order.Action.BUY, "ins1", 1) - self.assertEquals(order1.getSubmitDateTime(), None) + self.assertEqual(order1.getSubmitDateTime(), None) brk.submitOrder(order1) - self.assertEquals(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order1.getSubmitDateTime(), barFeed.getCurrentDateTime()) order2 = brk.createMarketOrder(broker.Order.Action.BUY, "ins2", 1) - self.assertEquals(order2.getSubmitDateTime(), None) + self.assertEqual(order2.getSubmitDateTime(), None) brk.submitOrder(order2) - self.assertEquals(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order2.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(len(brk.getActiveOrders()), 2) self.assertEqual(len(brk.getActiveOrders("ins1")), 1) @@ -474,14 +474,14 @@ def testGetPositions(self): brk.submitOrder(order) barFeed.dispatchBars(12.03, 12.03, 12.03, 12.03, 555.00) self.assertTrue(order.isFilled()) - self.assertEquals(brk.getPositions().get(BaseTestCase.TestInstrument), 1) + self.assertEqual(brk.getPositions().get(BaseTestCase.TestInstrument), 1) # Sell order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 1) brk.submitOrder(order) barFeed.dispatchBars(12.03, 12.03, 12.03, 12.03, 555.00) self.assertTrue(order.isFilled()) - self.assertEquals(brk.getPositions().get(BaseTestCase.TestInstrument), None) + self.assertEqual(brk.getPositions().get(BaseTestCase.TestInstrument), None) def testBuyPartialWithTwoDecimals(self): class Broker(backtesting.Broker): @@ -494,9 +494,9 @@ def getInstrumentTraits(self, instrument): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 500) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 138.75 should get filled. barFeed.dispatchBars(12.03, 12.03, 12.03, 12.03, 555.00) @@ -535,9 +535,9 @@ def getInstrumentTraits(self, instrument): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) volumes = [0.0001, 0.1, 0.0000001, 0.00000001, 0.132401] volumeFill = [(volume, round(volume*maxFill, quantityPresicion)) for volume in volumes] @@ -576,9 +576,9 @@ def testBuySellPartial(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 2 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 10) self.assertTrue(order.isPartiallyFilled()) @@ -609,9 +609,9 @@ def testBuySellPartial(self): # Sell order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 2) self.assertTrue(order.isAccepted()) @@ -643,9 +643,9 @@ def testBuyAndSell(self): # Buy cb = OrderUpdateCallback(brk) order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 8, 12) @@ -665,9 +665,9 @@ def testBuyAndSell(self): order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) self.assertTrue(order.isFilled()) self.assertEqual(order.getAvgFillPrice(), 10) @@ -688,9 +688,9 @@ def testFailToBuy(self): # Fail to buy. No money. cb = OrderUpdateCallback(brk) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 8, 12, sessionClose=True) @@ -728,9 +728,9 @@ def testBuy_GTC(self): # Fail to buy. No money. cb = OrderUpdateCallback(brk) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # Set sessionClose to true test that the order doesn't get canceled. barFeed.dispatchBars(10, 15, 8, 12, sessionClose=True) self.assertTrue(order.isAccepted()) @@ -762,9 +762,9 @@ def testBuyAndSellInTwoSteps(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 2) barFeed.dispatchBars(10, 15, 8, 12) @@ -780,9 +780,9 @@ def testBuyAndSellInTwoSteps(self): # Sell order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 8, 12) @@ -800,9 +800,9 @@ def testBuyAndSellInTwoSteps(self): order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(11, 15, 8, 12) self.assertTrue(order.isFilled()) self.assertEqual(order.getAvgFillPrice(), 11) @@ -820,9 +820,9 @@ def testPortfolioValue(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -846,9 +846,9 @@ def testBuyWithCommission(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 100) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 100) barFeed.dispatchBars(10, 15, 8, 12, volume=500) @@ -867,9 +867,9 @@ def testSellShort_1(self): # Short sell order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(200, 200, 200, 200) @@ -892,9 +892,9 @@ def testSellShort_1(self): order = brk.createMarketOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(200, 200, 200, 200) self.assertTrue(order.isFilled()) self.assertEqual(order.getAvgFillPrice(), 200) @@ -913,9 +913,9 @@ def testSellShort_2(self): order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(100, 100, 100, 100) self.assertTrue(order.isFilled()) self.assertEqual(order.getFilled(), 1) @@ -937,9 +937,9 @@ def testSellShort_2(self): order = brk.createMarketOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 2) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 2) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(50, 50, 50, 50) self.assertTrue(order.isFilled()) self.assertEqual(order.getAvgFillPrice(), 50) @@ -957,9 +957,9 @@ def testSellShort_2(self): order = brk.createMarketOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(100, 100, 100, 100) self.assertTrue(order.isFilled()) self.assertEqual(order.getFilled(), 1) @@ -978,9 +978,9 @@ def testSellShort_3(self): order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(100, 100, 100, 100) self.assertEqual(order.getFilled(), 1) self.assertEqual(order.getRemaining(), 0) @@ -994,9 +994,9 @@ def testSellShort_3(self): order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 2) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 2) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(100, 100, 100, 100) self.assertEqual(order.getFilled(), 2) self.assertEqual(order.getRemaining(), 0) @@ -1008,9 +1008,9 @@ def testSellShort_3(self): # Buy 1 order = brk.createMarketOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(100, 100, 100, 100) @@ -1032,9 +1032,9 @@ def testSellShortWithCommission(self): order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 10) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(sharePrice, sharePrice, sharePrice, sharePrice) self.assertEqual(order.getFilled(), 10) self.assertEqual(order.getRemaining(), 0) @@ -1046,9 +1046,9 @@ def testSellShortWithCommission(self): # Buy the 10 shares sold short plus 9 extra order = brk.createMarketOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 19) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 19) barFeed.dispatchBars(sharePrice, sharePrice, sharePrice, sharePrice) @@ -1067,9 +1067,9 @@ def testCancel(self): order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) brk.cancelOrder(order) @@ -1088,9 +1088,9 @@ def testTradePercentageWithPartialFills(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getCommissions(), 0) # 2 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 10) @@ -1130,9 +1130,9 @@ def testFixedPerTradeWithPartialFills(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getCommissions(), 0) # 2 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 10) @@ -1172,7 +1172,7 @@ def testDailyMarketOnClose(self): # Buy order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 2, onClose=True) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) # 2 should get filled at the closing price. @@ -1189,7 +1189,7 @@ def testIntradayMarketOnClose(self): cash = 1000000 brk = backtesting.Broker(cash, barFeed) - with self.assertRaisesRegexp(Exception, "Market-on-close not supported with intraday feeds"): + with self. assertRaisesRegex(Exception, "Market-on-close not supported with intraday feeds"): brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1, onClose=True) @@ -1200,9 +1200,9 @@ def testBuySellPartial(self): # Buy order = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 2 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 10) self.assertTrue(order.isPartiallyFilled()) @@ -1233,9 +1233,9 @@ def testBuySellPartial(self): # Sell order = brk.createLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 10, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. barFeed.dispatchBars(12, 15, 8, 12, 2) self.assertTrue(order.isAccepted()) @@ -1269,9 +1269,9 @@ def testBuyAndSell_HitTargetPrice(self): order = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 10, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(12, 15, 8, 12) self.assertEqual(order.getFilled(), 1) self.assertEqual(order.getRemaining(), 0) @@ -1287,9 +1287,9 @@ def testBuyAndSell_HitTargetPrice(self): # Sell cb = OrderUpdateCallback(brk) order = brk.createLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 15, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 17, 8, 10) @@ -1313,9 +1313,9 @@ def testBuyAndSell_GetBetterPrice(self): order = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 14, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(12, 15, 8, 12) self.assertEqual(order.getFilled(), 1) self.assertEqual(order.getRemaining(), 0) @@ -1331,9 +1331,9 @@ def testBuyAndSell_GetBetterPrice(self): # Sell cb = OrderUpdateCallback(brk) order = brk.createLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 15, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(16, 17, 8, 10) @@ -1355,9 +1355,9 @@ def testBuyAndSell_GappingBars(self): # Buy. Bar is below the target price. cb = OrderUpdateCallback(brk) order = brk.createLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 20, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 8, 10) @@ -1377,9 +1377,9 @@ def testBuyAndSell_GappingBars(self): order = brk.createLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 30, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(35, 40, 32, 35) self.assertEqual(order.getFilled(), 1) self.assertEqual(order.getRemaining(), 0) @@ -1402,9 +1402,9 @@ def testFailToBuy(self): # Fail to buy (couldn't get specific price). cb = OrderUpdateCallback(brk) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12, sessionClose=True) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -1440,9 +1440,9 @@ def testBuy_GTC(self): # Fail to buy (couldn't get specific price). cb = OrderUpdateCallback(brk) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # Set sessionClose to true test that the order doesn't get canceled. barFeed.dispatchBars(10, 15, 8, 12, sessionClose=True) self.assertEqual(order.getFilled(), 0) @@ -1476,9 +1476,9 @@ def testStopHitWithoutVolume(self): # Buy. Stop >= 15. order = brk.createStopOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. There is not enough volume. barFeed.dispatchBars(18, 19, 17.01, 18, 3) @@ -1495,9 +1495,9 @@ def testBuySellPartial_ActivateAndThenFill(self): # Buy. Stop >= 15. order = brk.createStopOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. The stop price should have not been hit. barFeed.dispatchBars(12, 14, 8, 12, 10) @@ -1536,9 +1536,9 @@ def testBuySellPartial_ActivateAndThenFill(self): # Sell. Stop <= 19. order = brk.createStopOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 19, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. The stop price should have not been hit. barFeed.dispatchBars(19.1, 19.5, 19.1, 19.4, 10) self.assertTrue(order.isAccepted()) @@ -1598,9 +1598,9 @@ def testBuySellPartial_ActivateAndFill(self): # Buy. Stop >= 15. order = brk.createStopOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 5 should get filled. barFeed.dispatchBars(18, 18, 16, 18, 20) @@ -1630,9 +1630,9 @@ def testBuySellPartial_ActivateAndFill(self): # Sell. Stop <= 19. order = brk.createStopOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 19, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 5 should get filled. barFeed.dispatchBars(20, 21, 17, 18, 20) self.assertEqual(order.getStopHit(), True) @@ -1686,9 +1686,9 @@ def testLongPosStopLoss(self): order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) self.assertTrue(order.isFilled()) self.assertEqual(order.getFilled(), 1) @@ -1706,9 +1706,9 @@ def testLongPosStopLoss(self): order = brk.createStopOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 9, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 10, 12) # Stop loss not hit. self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -1737,9 +1737,9 @@ def testLongPosStopLoss_GappingBars(self): order = brk.createMarketOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) self.assertTrue(order.isFilled()) self.assertEqual(order.getFilled(), 1) @@ -1755,9 +1755,9 @@ def testLongPosStopLoss_GappingBars(self): # Create stop loss order. cb = OrderUpdateCallback(brk) order = brk.createStopOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 9, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 10, 12) # Stop loss not hit. @@ -1786,9 +1786,9 @@ def testShortPosStopLoss(self): # Sell short cb = OrderUpdateCallback(brk) order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(10, 15, 8, 12) @@ -1806,9 +1806,9 @@ def testShortPosStopLoss(self): # Create stop loss order. cb = OrderUpdateCallback(brk) order = brk.createStopOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 11, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(8, 10, 7, 9) # Stop loss not hit. @@ -1838,9 +1838,9 @@ def testShortPosStopLoss_GappingBars(self): order = brk.createMarketOrder(broker.Order.Action.SELL_SHORT, BaseTestCase.TestInstrument, 1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) barFeed.dispatchBars(10, 15, 8, 12) self.assertTrue(order.isFilled()) self.assertEqual(order.getFilled(), 1) @@ -1856,9 +1856,9 @@ def testShortPosStopLoss_GappingBars(self): # Create stop loss order. cb = OrderUpdateCallback(brk) order = brk.createStopOrder(broker.Order.Action.BUY_TO_COVER, BaseTestCase.TestInstrument, 11, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) barFeed.dispatchBars(8, 10, 7, 9) # Stop loss not hit. @@ -1888,9 +1888,9 @@ def testStopHitWithoutVolume(self): # Buy. Stop >= 15. Buy <= 17. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 17, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. There is not enough volume. barFeed.dispatchBars(18, 19, 15, 18, 3) @@ -1907,9 +1907,9 @@ def testRegressionBarGapsAboveStop(self): # Buy. Stop >= 15. Buy <= 17. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 17, 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 1 should get filled at 17. Before the bug was fixed it was filled at 15. barFeed.dispatchBars(18, 18, 16, 18, 20) @@ -1927,9 +1927,9 @@ def testBuySellPartial_ActivateAndThenFill(self): # Buy. Stop >= 15. Buy <= 17. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 17, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. The stop price should have not been hit. barFeed.dispatchBars(12, 14, 8, 12, 10) @@ -1977,9 +1977,9 @@ def testBuySellPartial_ActivateAndThenFill(self): # Sell. Stop <= 19. Sell >= 20. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 19, 20, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 0 should get filled. The stop price should have not been hit. barFeed.dispatchBars(19.1, 19.5, 19.1, 19.4, 10) self.assertTrue(order.isAccepted()) @@ -2048,9 +2048,9 @@ def testBuySellPartial_ActivateAndFill(self): # Buy. Stop >= 15. Buy <= 17. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, 15, 17, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 5 should get filled. barFeed.dispatchBars(18, 18, 16, 18, 20) @@ -2082,9 +2082,9 @@ def testBuySellPartial_ActivateAndFill(self): # Sell. Stop <= 19. Sell >= 20. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, 19, 20, 10) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) # 5 should get filled. barFeed.dispatchBars(20, 21, 17, 18, 20) self.assertTrue(order.isPartiallyFilled()) @@ -2139,9 +2139,9 @@ def testFillOpen(self): order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=10, limitPrice=12, quantity=1) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2170,9 +2170,9 @@ def testFillOpen(self): # Sell. Stop <= 8. Sell >= 6. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=8, limitPrice=6, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2205,9 +2205,9 @@ def testFillOpen_GappingBars(self): # Buy. Stop >= 10. Buy <= 12. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=10, limitPrice=12, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2236,9 +2236,9 @@ def testFillOpen_GappingBars(self): # Sell. Stop <= 8. Sell >= 6. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=8, limitPrice=6, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2271,9 +2271,9 @@ def testFillLimit(self): # Buy. Stop >= 10. Buy <= 12. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=10, limitPrice=12, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2302,9 +2302,9 @@ def testFillLimit(self): # Sell. Stop <= 8. Sell >= 6. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=8, limitPrice=6, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2337,9 +2337,9 @@ def testHitStopAndLimit(self): # Buy. Stop >= 10. Buy <= 12. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=10, limitPrice=12, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2354,9 +2354,9 @@ def testHitStopAndLimit(self): # Sell. Stop <= 8. Sell >= 6. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=8, limitPrice=6, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2375,9 +2375,9 @@ def testInvertedPrices_FillOpen(self): # Buy. Stop >= 12. Buy <= 10. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=12, limitPrice=10, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2406,9 +2406,9 @@ def testInvertedPrices_FillOpen(self): # Sell. Stop <= 6. Sell >= 8. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=6, limitPrice=8, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2441,9 +2441,9 @@ def testInvertedPrices_FillOpen_GappingBars(self): # Buy. Stop >= 12. Buy <= 10. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=12, limitPrice=10, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2472,9 +2472,9 @@ def testInvertedPrices_FillOpen_GappingBars(self): # Sell. Stop <= 6. Sell >= 8. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=6, limitPrice=8, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2507,9 +2507,9 @@ def testInvertedPrices_FillLimit(self): # Buy. Stop >= 12. Buy <= 10. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=12, limitPrice=10, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2538,9 +2538,9 @@ def testInvertedPrices_FillLimit(self): # Sell. Stop <= 6. Sell >= 8. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=6, limitPrice=8, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2573,9 +2573,9 @@ def testInvertedPrices_HitStopAndLimit(self): # Buy. Stop >= 12. Buy <= 10. order = brk.createStopLimitOrder(broker.Order.Action.BUY, BaseTestCase.TestInstrument, stopPrice=12, limitPrice=10, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) @@ -2590,9 +2590,9 @@ def testInvertedPrices_HitStopAndLimit(self): # Sell. Stop <= 6. Sell >= 8. order = brk.createStopLimitOrder(broker.Order.Action.SELL, BaseTestCase.TestInstrument, stopPrice=6, limitPrice=8, quantity=1) - self.assertEquals(order.getSubmitDateTime(), None) + self.assertEqual(order.getSubmitDateTime(), None) brk.submitOrder(order) - self.assertEquals(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) + self.assertEqual(order.getSubmitDateTime(), barFeed.getCurrentDateTime()) self.assertEqual(order.getFilled(), 0) self.assertEqual(order.getRemaining(), 1) diff --git a/testcases/broker_test.py b/testcases/broker_test.py index 7cb79bfb1..25d835c07 100644 --- a/testcases/broker_test.py +++ b/testcases/broker_test.py @@ -33,10 +33,10 @@ def roundQuantity(self, quantity): class OrderTestCase(common.TestCase): def __buildAcceptedLimitOrder(self, action, limitPrice, quantity): ret = broker.LimitOrder(action, "orcl", limitPrice, quantity, DefaultTraits()) - self.assertEquals(ret.getSubmitDateTime(), None) + self.assertEqual(ret.getSubmitDateTime(), None) ret.switchState(broker.Order.State.SUBMITTED) ret.setSubmitted(1, datetime.datetime.now()) - self.assertNotEquals(ret.getSubmitDateTime(), None) + self.assertNotEqual(ret.getSubmitDateTime(), None) ret.switchState(broker.Order.State.ACCEPTED) return ret diff --git a/testcases/btcharts_test.py b/testcases/btcharts_test.py index 524203b74..332b8e20b 100644 --- a/testcases/btcharts_test.py +++ b/testcases/btcharts_test.py @@ -32,52 +32,52 @@ def testLoadNoFilter(self): feed.addBarsFromCSV(common.get_data_file_path("bitstampUSD.csv")) loaded = [(dateTime, bars) for dateTime, bars, _ in feed] - self.assertEquals(len(loaded), 9999) + self.assertEqual(len(loaded), 9999) - self.assertEquals(loaded[0][0], dt.as_utc(datetime.datetime(2011, 9, 13, 13, 53, 36))) - self.assertEquals(loaded[0][1]["BTC"].getDateTime(), dt.as_utc(datetime.datetime(2011, 9, 13, 13, 53, 36))) - self.assertEquals(loaded[0][1]["BTC"].getClose(), 5.8) - self.assertEquals(loaded[0][1]["BTC"].getPrice(), 5.8) - self.assertEquals(loaded[0][1]["BTC"].getVolume(), 1.0) + self.assertEqual(loaded[0][0], dt.as_utc(datetime.datetime(2011, 9, 13, 13, 53, 36))) + self.assertEqual(loaded[0][1]["BTC"].getDateTime(), dt.as_utc(datetime.datetime(2011, 9, 13, 13, 53, 36))) + self.assertEqual(loaded[0][1]["BTC"].getClose(), 5.8) + self.assertEqual(loaded[0][1]["BTC"].getPrice(), 5.8) + self.assertEqual(loaded[0][1]["BTC"].getVolume(), 1.0) - self.assertEquals(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) - self.assertEquals(loaded[-1][1]["BTC"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) - self.assertEquals(loaded[-1][1]["BTC"].getClose(), 5.1) - self.assertEquals(loaded[-1][1]["BTC"].getPrice(), 5.1) - self.assertEquals(loaded[-1][1]["BTC"].getVolume(), 0.39215686) + self.assertEqual(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) + self.assertEqual(loaded[-1][1]["BTC"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) + self.assertEqual(loaded[-1][1]["BTC"].getClose(), 5.1) + self.assertEqual(loaded[-1][1]["BTC"].getPrice(), 5.1) + self.assertEqual(loaded[-1][1]["BTC"].getVolume(), 0.39215686) def testLoadFilterFrom(self): feed = barfeed.CSVTradeFeed() feed.addBarsFromCSV(common.get_data_file_path("bitstampUSD.csv"), "bitstampUSD", fromDateTime=dt.as_utc(datetime.datetime(2012, 5, 29))) loaded = [(dateTime, bars) for dateTime, bars, _ in feed] - self.assertEquals(len(loaded), 646) + self.assertEqual(len(loaded), 646) - self.assertEquals(loaded[0][0], dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) - self.assertEquals(loaded[0][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) - self.assertEquals(loaded[0][1]["bitstampUSD"].getClose(), 5.07) - self.assertEquals(loaded[0][1]["bitstampUSD"].getPrice(), 5.07) - self.assertEquals(loaded[0][1]["bitstampUSD"].getVolume(), 1.39081288) + self.assertEqual(loaded[0][0], dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) + self.assertEqual(loaded[0][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) + self.assertEqual(loaded[0][1]["bitstampUSD"].getClose(), 5.07) + self.assertEqual(loaded[0][1]["bitstampUSD"].getPrice(), 5.07) + self.assertEqual(loaded[0][1]["bitstampUSD"].getVolume(), 1.39081288) - self.assertEquals(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getClose(), 5.1) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getPrice(), 5.1) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getVolume(), 0.39215686) + self.assertEqual(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 31, 8, 41, 18, 5))) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getClose(), 5.1) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getPrice(), 5.1) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getVolume(), 0.39215686) def testLoadFilterFromAndTo(self): feed = barfeed.CSVTradeFeed() feed.addBarsFromCSV(common.get_data_file_path("bitstampUSD.csv"), "bitstampUSD", fromDateTime=dt.as_utc(datetime.datetime(2012, 5, 29)), toDateTime=datetime.datetime(2012, 5, 31)) loaded = [(dateTime, bars) for dateTime, bars, _ in feed] - self.assertEquals(len(loaded), 579) + self.assertEqual(len(loaded), 579) - self.assertEquals(loaded[0][0], dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) - self.assertEquals(loaded[0][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) - self.assertEquals(loaded[0][1]["bitstampUSD"].getClose(), 5.07) - self.assertEquals(loaded[0][1]["bitstampUSD"].getVolume(), 1.39081288) + self.assertEqual(loaded[0][0], dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) + self.assertEqual(loaded[0][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 29, 1, 47, 52))) + self.assertEqual(loaded[0][1]["bitstampUSD"].getClose(), 5.07) + self.assertEqual(loaded[0][1]["bitstampUSD"].getVolume(), 1.39081288) - self.assertEquals(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 30, 23, 49, 21))) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 30, 23, 49, 21))) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getClose(), 5.14) - self.assertEquals(loaded[-1][1]["bitstampUSD"].getVolume(), 20) + self.assertEqual(loaded[-1][0], dt.as_utc(datetime.datetime(2012, 5, 30, 23, 49, 21))) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getDateTime(), dt.as_utc(datetime.datetime(2012, 5, 30, 23, 49, 21))) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getClose(), 5.14) + self.assertEqual(loaded[-1][1]["bitstampUSD"].getVolume(), 20) diff --git a/testcases/fill_strategy_test.py b/testcases/fill_strategy_test.py index 5ebda2b4b..90e7e691d 100644 --- a/testcases/fill_strategy_test.py +++ b/testcases/fill_strategy_test.py @@ -120,14 +120,14 @@ def __getFilledMarketOrder(self, quantity, price): def testVolumeLimitPerBar(self): volume = 100 self.strategy.onBars(None, self.barsBuilder.nextBars(11, 12, 4, 9, volume)) - self.assertEquals(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 25) - self.assertEquals(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 0) + self.assertEqual(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 25) + self.assertEqual(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 0) self.strategy.onOrderFilled(None, self.__getFilledMarketOrder(24, 11)) - self.assertEquals(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 1) - self.assertEquals(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 24) + self.assertEqual(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 1) + self.assertEqual(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 24) - with self.assertRaisesRegexp(Exception, "Invalid fill quantity 25. Not enough volume left 1"): + with self. assertRaisesRegex(Exception, "Invalid fill quantity 25. Not enough volume left 1"): self.strategy.onOrderFilled(None, self.__getFilledMarketOrder(25, 11)) - self.assertEquals(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 1) - self.assertEquals(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 24) + self.assertEqual(self.strategy.getVolumeLeft()[BaseTestCase.TestInstrument], 1) + self.assertEqual(self.strategy.getVolumeUsed()[BaseTestCase.TestInstrument], 24) diff --git a/testcases/ninjatraderfeed_test.py b/testcases/ninjatraderfeed_test.py index 692d40935..5359c6cb9 100644 --- a/testcases/ninjatraderfeed_test.py +++ b/testcases/ninjatraderfeed_test.py @@ -113,7 +113,7 @@ def testBaseBarFeed(self): barfeed_test.check_base_barfeed(self, barFeed, False) def testInvalidFrequency(self): - with self.assertRaisesRegexp(Exception, "Invalid frequency.*"): + with self. assertRaisesRegex(Exception, "Invalid frequency.*"): ninjatraderfeed.Feed(bar.Frequency.WEEK) def testReset(self): diff --git a/testcases/optimizer_test.py b/testcases/optimizer_test.py index b8ef137fd..c6e8b4b9b 100644 --- a/testcases/optimizer_test.py +++ b/testcases/optimizer_test.py @@ -53,8 +53,8 @@ def testLocal(self): sma_crossover.SMACrossOver, barFeed, parameters_generator(instrument, 5, 100), logLevel=logging.DEBUG, batchSize=50 ) - self.assertEquals(round(res.getResult(), 2), 1295462.6) - self.assertEquals(res.getParameters()[1], 20) + self.assertEqual(round(res.getResult(), 2), 1295462.6) + self.assertEqual(res.getParameters()[1], 20) def testFailingStrategy(self): barFeed = yahoofeed.Feed() diff --git a/testcases/quandl_test.py b/testcases/quandl_test.py index 64ed526da..c31033db8 100644 --- a/testcases/quandl_test.py +++ b/testcases/quandl_test.py @@ -69,16 +69,16 @@ def testDownloadAndParseDailyUsingApiKey(self): bf = quandlfeed.Feed() bf.addBarsFromCSV(instrument, path) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) - self.assertEquals(bf[instrument][-1].getOpen(), 31.22) - self.assertEquals(bf[instrument][-1].getHigh(), 31.33) - self.assertEquals(bf[instrument][-1].getLow(), 30.93) - self.assertEquals(bf[instrument][-1].getClose(), 31.3) - self.assertEquals(bf[instrument][-1].getVolume(), 11716300) - self.assertEquals(bf[instrument][-1].getPrice(), 31.3) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) + self.assertEqual(bf[instrument][-1].getOpen(), 31.22) + self.assertEqual(bf[instrument][-1].getHigh(), 31.33) + self.assertEqual(bf[instrument][-1].getLow(), 30.93) + self.assertEqual(bf[instrument][-1].getClose(), 31.3) + self.assertEqual(bf[instrument][-1].getVolume(), 11716300) + self.assertEqual(bf[instrument][-1].getPrice(), 31.3) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) def testDownloadAndParseDaily_UseAdjClose(self): with common.TmpDir() as tmpPath: @@ -91,16 +91,16 @@ def testDownloadAndParseDaily_UseAdjClose(self): # can't tell in advance if adjusted values are there or not. bf.setUseAdjustedValues(True) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) - self.assertEquals(bf[instrument][-1].getOpen(), 31.22) - self.assertEquals(bf[instrument][-1].getHigh(), 31.33) - self.assertEquals(bf[instrument][-1].getLow(), 30.93) - self.assertEquals(bf[instrument][-1].getClose(), 31.3) - self.assertEquals(bf[instrument][-1].getVolume(), 11716300) - self.assertEquals(bf[instrument][-1].getPrice(), bf[instrument][-1].getAdjClose()) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) + self.assertEqual(bf[instrument][-1].getOpen(), 31.22) + self.assertEqual(bf[instrument][-1].getHigh(), 31.33) + self.assertEqual(bf[instrument][-1].getLow(), 30.93) + self.assertEqual(bf[instrument][-1].getClose(), 31.3) + self.assertEqual(bf[instrument][-1].getVolume(), 11716300) + self.assertEqual(bf[instrument][-1].getPrice(), bf[instrument][-1].getAdjClose()) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) def testDownloadAndParseDailyNoAdjClose(self): with common.TmpDir() as tmpPath: @@ -114,14 +114,14 @@ def testDownloadAndParseDailyNoAdjClose(self): bf.setColumnName("close", "Price") bf.addBarsFromCSV(instrument, path, skipMalformedBars=True) bf.loadAll() - self.assertEquals(bf[instrument][0].getDateTime(), datetime.datetime(year, 1, 3)) - self.assertEquals(bf[instrument][0].getOpen(), 237.80) - self.assertEquals(bf[instrument][0].getHigh(), 247.00) - self.assertEquals(bf[instrument][0].getLow(), 236.30) - self.assertEquals(bf[instrument][0].getClose(), 237.80) - self.assertEquals(bf[instrument][0].getVolume(), 3494173) - self.assertEquals(bf[instrument][0].getAdjClose(), None) - self.assertEquals(bf[instrument][0].getPrice(), 237.80) + self.assertEqual(bf[instrument][0].getDateTime(), datetime.datetime(year, 1, 3)) + self.assertEqual(bf[instrument][0].getOpen(), 237.80) + self.assertEqual(bf[instrument][0].getHigh(), 247.00) + self.assertEqual(bf[instrument][0].getLow(), 236.30) + self.assertEqual(bf[instrument][0].getClose(), 237.80) + self.assertEqual(bf[instrument][0].getVolume(), 3494173) + self.assertEqual(bf[instrument][0].getAdjClose(), None) + self.assertEqual(bf[instrument][0].getPrice(), 237.80) def testDownloadAndParseWeekly(self): with common.TmpDir() as tmpPath: @@ -135,19 +135,19 @@ def testDownloadAndParseWeekly(self): self.assertTrue( bf[instrument][0].getDateTime() in [datetime.datetime(2010, 1, 3), datetime.datetime(2010, 1, 10)] ) - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) - self.assertEquals(bf[instrument][-1].getOpen(), 325.0) - self.assertEquals(bf[instrument][-1].getHigh(), 325.15) - self.assertEquals(bf[instrument][-1].getLow(), 323.17) - self.assertEquals(bf[instrument][-1].getClose(), 323.6) - self.assertEquals(bf[instrument][-1].getVolume(), 7969900) - self.assertEquals(bf[instrument][-1].getPrice(), 323.6) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) + self.assertEqual(bf[instrument][-1].getOpen(), 325.0) + self.assertEqual(bf[instrument][-1].getHigh(), 325.15) + self.assertEqual(bf[instrument][-1].getLow(), 323.17) + self.assertEqual(bf[instrument][-1].getClose(), 323.6) + self.assertEqual(bf[instrument][-1].getVolume(), 7969900) + self.assertEqual(bf[instrument][-1].getPrice(), 323.6) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) def testInvalidFrequency(self): - with self.assertRaisesRegexp(Exception, "Invalid frequency.*"): + with self. assertRaisesRegex(Exception, "Invalid frequency.*"): quandlfeed.Feed(frequency=bar.Frequency.MINUTE) def testBuildFeedDaily(self): @@ -155,16 +155,16 @@ def testBuildFeedDaily(self): instrument = "ORCL" bf = quandl.build_feed("WIKI", [instrument], 2010, 2010, tmpPath, authToken=QUANDL_API_KEY) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) - self.assertEquals(bf[instrument][-1].getOpen(), 31.22) - self.assertEquals(bf[instrument][-1].getHigh(), 31.33) - self.assertEquals(bf[instrument][-1].getLow(), 30.93) - self.assertEquals(bf[instrument][-1].getClose(), 31.3) - self.assertEquals(bf[instrument][-1].getVolume(), 11716300) - self.assertEquals(bf[instrument][-1].getPrice(), 31.3) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) + self.assertEqual(bf[instrument][-1].getOpen(), 31.22) + self.assertEqual(bf[instrument][-1].getHigh(), 31.33) + self.assertEqual(bf[instrument][-1].getLow(), 30.93) + self.assertEqual(bf[instrument][-1].getClose(), 31.3) + self.assertEqual(bf[instrument][-1].getVolume(), 11716300) + self.assertEqual(bf[instrument][-1].getPrice(), 31.3) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) def testBuildFeedWeekly(self): with common.TmpDir() as tmpPath: @@ -178,22 +178,22 @@ def testBuildFeedWeekly(self): self.assertTrue( bf[instrument][0].getDateTime() in [datetime.datetime(2010, 1, 3), datetime.datetime(2010, 1, 10)] ) - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) - self.assertEquals(bf[instrument][-1].getOpen(), 325.0) - self.assertEquals(bf[instrument][-1].getHigh(), 325.15) - self.assertEquals(bf[instrument][-1].getLow(), 323.17) - self.assertEquals(bf[instrument][-1].getClose(), 323.6) - self.assertEquals(bf[instrument][-1].getVolume(), 7969900) - self.assertEquals(bf[instrument][-1].getPrice(), 323.6) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) + self.assertEqual(bf[instrument][-1].getOpen(), 325.0) + self.assertEqual(bf[instrument][-1].getHigh(), 325.15) + self.assertEqual(bf[instrument][-1].getLow(), 323.17) + self.assertEqual(bf[instrument][-1].getClose(), 323.6) + self.assertEqual(bf[instrument][-1].getVolume(), 7969900) + self.assertEqual(bf[instrument][-1].getPrice(), 323.6) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) def testInvalidInstrument(self): instrument = "inexistent" # Don't skip errors. - with self.assertRaisesRegexp(Exception, "404 Client Error: Not Found"): + with self. assertRaisesRegex(Exception, "404 Client Error: Not Found"): with common.TmpDir() as tmpPath: quandl.build_feed( instrument, [instrument], 2010, 2010, tmpPath, bar.Frequency.WEEK, @@ -223,14 +223,14 @@ def testMapColumnNames(self): ) bf.setNoAdjClose() bf.loadAll() - self.assertEquals(bf[instrument][0].getDateTime(), datetime.datetime(year, 1, 3)) - self.assertEquals(bf[instrument][0].getOpen(), 237.80) - self.assertEquals(bf[instrument][0].getHigh(), 247.00) - self.assertEquals(bf[instrument][0].getLow(), 236.30) - self.assertEquals(bf[instrument][0].getClose(), 237.80) - self.assertEquals(bf[instrument][0].getVolume(), 3494173) - self.assertEquals(bf[instrument][0].getAdjClose(), None) - self.assertEquals(bf[instrument][0].getPrice(), 237.80) + self.assertEqual(bf[instrument][0].getDateTime(), datetime.datetime(year, 1, 3)) + self.assertEqual(bf[instrument][0].getOpen(), 237.80) + self.assertEqual(bf[instrument][0].getHigh(), 247.00) + self.assertEqual(bf[instrument][0].getLow(), 236.30) + self.assertEqual(bf[instrument][0].getClose(), 237.80) + self.assertEqual(bf[instrument][0].getVolume(), 3494173) + self.assertEqual(bf[instrument][0].getAdjClose(), None) + self.assertEqual(bf[instrument][0].getPrice(), 237.80) def testExtraColumns(self): with common.TmpDir() as tmpPath: @@ -244,12 +244,12 @@ def testExtraColumns(self): ) bf.loadAll() - self.assertEquals(len(bf["USD"][-1].getExtraColumns()), 3) - self.assertEquals(bf["USD"][-1].getExtraColumns()["Bid"], 319.19) - self.assertEquals(bf["USD"][-1].getExtraColumns()["Ask"], 319.63) + self.assertEqual(len(bf["USD"][-1].getExtraColumns()), 3) + self.assertEqual(bf["USD"][-1].getExtraColumns()["Bid"], 319.19) + self.assertEqual(bf["USD"][-1].getExtraColumns()["Ask"], 319.63) bids = bf["USD"].getExtraDataSeries("Bid") - self.assertEquals(bids[-1], 319.19) + self.assertEqual(bids[-1], 319.19) def testNoAdjClose(self): with common.TmpDir() as tmpPath: @@ -265,7 +265,7 @@ def testNoAdjClose(self): bf.loadAll() self.assertFalse(bf.barsHaveAdjClose()) - self.assertEquals(bf["USD"][-1].getAdjClose(), None) + self.assertEqual(bf["USD"][-1].getAdjClose(), None) def testBuildFeedDailyCreatingDir(self): tmpPath = tempfile.mkdtemp() @@ -275,16 +275,16 @@ def testBuildFeedDailyCreatingDir(self): bf = quandl.build_feed("WIKI", [instrument], 2010, 2010, tmpPath, authToken=QUANDL_API_KEY) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) - self.assertEquals(bf[instrument][-1].getOpen(), 31.22) - self.assertEquals(bf[instrument][-1].getHigh(), 31.33) - self.assertEquals(bf[instrument][-1].getLow(), 30.93) - self.assertEquals(bf[instrument][-1].getClose(), 31.3) - self.assertEquals(bf[instrument][-1].getVolume(), 11716300) - self.assertEquals(bf[instrument][-1].getPrice(), 31.3) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) + self.assertEqual(bf[instrument][-1].getOpen(), 31.22) + self.assertEqual(bf[instrument][-1].getHigh(), 31.33) + self.assertEqual(bf[instrument][-1].getLow(), 30.93) + self.assertEqual(bf[instrument][-1].getClose(), 31.3) + self.assertEqual(bf[instrument][-1].getVolume(), 11716300) + self.assertEqual(bf[instrument][-1].getPrice(), 31.3) # Not checking against a specific value since this is going to change # as time passes by. - self.assertNotEquals(bf[instrument][-1].getAdjClose(), None) + self.assertNotEqual(bf[instrument][-1].getAdjClose(), None) finally: shutil.rmtree(tmpPath) @@ -305,13 +305,13 @@ def testCommandLineDailyCreatingDir(self): bf = quandlfeed.Feed() bf.addBarsFromCSV(instrument, os.path.join(tmpPath, "WIKI-ORCL-2010-quandl.csv")) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) - self.assertEquals(bf[instrument][-1].getOpen(), 31.22) - self.assertEquals(bf[instrument][-1].getHigh(), 31.33) - self.assertEquals(bf[instrument][-1].getLow(), 30.93) - self.assertEquals(bf[instrument][-1].getClose(), 31.3) - self.assertEquals(bf[instrument][-1].getVolume(), 11716300) - self.assertEquals(bf[instrument][-1].getPrice(), 31.3) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31)) + self.assertEqual(bf[instrument][-1].getOpen(), 31.22) + self.assertEqual(bf[instrument][-1].getHigh(), 31.33) + self.assertEqual(bf[instrument][-1].getLow(), 30.93) + self.assertEqual(bf[instrument][-1].getClose(), 31.3) + self.assertEqual(bf[instrument][-1].getVolume(), 11716300) + self.assertEqual(bf[instrument][-1].getPrice(), 31.3) finally: shutil.rmtree(tmpPath) @@ -334,13 +334,13 @@ def testCommandLineWeeklyCreatingDir(self): bf.addBarsFromCSV(instrument, os.path.join(tmpPath, "WIKI-AAPL-2010-quandl.csv")) bf.loadAll() - self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) - self.assertEquals(bf[instrument][-1].getOpen(), 325.0) - self.assertEquals(bf[instrument][-1].getHigh(), 325.15) - self.assertEquals(bf[instrument][-1].getLow(), 323.17) - self.assertEquals(bf[instrument][-1].getClose(), 323.6) - self.assertEquals(bf[instrument][-1].getVolume(), 7969900) - self.assertEquals(bf[instrument][-1].getPrice(), 323.6) + self.assertEqual(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26)) + self.assertEqual(bf[instrument][-1].getOpen(), 325.0) + self.assertEqual(bf[instrument][-1].getHigh(), 325.15) + self.assertEqual(bf[instrument][-1].getLow(), 323.17) + self.assertEqual(bf[instrument][-1].getClose(), 323.6) + self.assertEqual(bf[instrument][-1].getVolume(), 7969900) + self.assertEqual(bf[instrument][-1].getPrice(), 323.6) finally: shutil.rmtree(tmpPath) diff --git a/testcases/resample_test.py b/testcases/resample_test.py index c542b4d26..2e3686173 100644 --- a/testcases/resample_test.py +++ b/testcases/resample_test.py @@ -268,7 +268,7 @@ def testResampleNinjaTraderDay(self): self.assertEqual(resampledBarDS[-1].getDateTime(), dt.as_utc(datetime.datetime(2011, 2, 1))) def testResampleBarFeedWithMultipleInstrumentsFails(self): - with self.assertRaisesRegexp(Exception, "Only barfeeds with 1 instrument can be resampled"): + with self. assertRaisesRegex(Exception, "Only barfeeds with 1 instrument can be resampled"): with common.TmpDir() as tmp_path: feed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE) feed.addBarsFromCSV("spy", common.get_data_file_path("nt-spy-minute-2011.csv")) diff --git a/testcases/returns_analyzer_test.py b/testcases/returns_analyzer_test.py index 364187e16..93ff153a2 100644 --- a/testcases/returns_analyzer_test.py +++ b/testcases/returns_analyzer_test.py @@ -45,18 +45,18 @@ def testInvestopedia(self): # http://www.investopedia.com/exam-guide/cfa-level-1/quantitative-methods/discounted-cash-flow-time-weighted-return.asp retTracker = returns.TimeWeightedReturns(200000) retTracker.update(196500) # March 31, 2004 - self.assertEquals(round(retTracker.getLastPeriodReturns(), 4), -0.0175) + self.assertEqual(round(retTracker.getLastPeriodReturns(), 4), -0.0175) retTracker.update(200000) # June 30, 2004 - self.assertEquals(round(retTracker.getLastPeriodReturns(), 4), 0.0178) + self.assertEqual(round(retTracker.getLastPeriodReturns(), 4), 0.0178) retTracker.deposit(20000) retTracker.update(222000) # July 30, 2004 - self.assertEquals(round(retTracker.getLastPeriodReturns(), 2), 0.01) + self.assertEqual(round(retTracker.getLastPeriodReturns(), 2), 0.01) retTracker.update(243000) # Sept. 30, 2004 - self.assertEquals(round(retTracker.getLastPeriodReturns(), 4), 0.0946) + self.assertEqual(round(retTracker.getLastPeriodReturns(), 4), 0.0946) retTracker.deposit(2000) retTracker.update(250000) # Dec. 31, 2004 - self.assertEquals(round(retTracker.getLastPeriodReturns(), 4), 0.0206) - self.assertEquals(round(retTracker.getCumulativeReturns(), 6), 0.128288) + self.assertEqual(round(retTracker.getLastPeriodReturns(), 4), 0.0206) + self.assertEqual(round(retTracker.getCumulativeReturns(), 6), 0.128288) class PosTrackerTestCase(common.TestCase): diff --git a/testcases/strategy_test.py b/testcases/strategy_test.py index f24d927ad..e93b10020 100644 --- a/testcases/strategy_test.py +++ b/testcases/strategy_test.py @@ -116,10 +116,10 @@ def testMarketOrderBuy(self): o = strat.marketOrder(StrategyTestCase.TestInstrument, 1) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.BUY) - self.assertEquals(o.getQuantity(), 1) - self.assertEquals(o.getFilled(), 1) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.BUY) + self.assertEqual(o.getQuantity(), 1) + self.assertEqual(o.getFilled(), 1) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) def testMarketOrderSell(self): @@ -128,10 +128,10 @@ def testMarketOrderSell(self): o = strat.marketOrder(StrategyTestCase.TestInstrument, -2) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.SELL) - self.assertEquals(o.getQuantity(), 2) - self.assertEquals(o.getFilled(), 2) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.SELL) + self.assertEqual(o.getQuantity(), 2) + self.assertEqual(o.getFilled(), 2) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) def testLimitOrderBuy(self): @@ -140,11 +140,11 @@ def testLimitOrderBuy(self): o = strat.limitOrder(StrategyTestCase.TestInstrument, 60, 1, True) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.BUY) - self.assertEquals(o.getAvgFillPrice(), 56.13) - self.assertEquals(o.getQuantity(), 1) - self.assertEquals(o.getFilled(), 1) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.BUY) + self.assertEqual(o.getAvgFillPrice(), 56.13) + self.assertEqual(o.getQuantity(), 1) + self.assertEqual(o.getFilled(), 1) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) def testLimitOrderSell(self): @@ -153,11 +153,11 @@ def testLimitOrderSell(self): o = strat.limitOrder(StrategyTestCase.TestInstrument, 60, -3, False) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.SELL) - self.assertEquals(o.getAvgFillPrice(), 124.62) - self.assertEquals(o.getQuantity(), 3) - self.assertEquals(o.getFilled(), 3) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.SELL) + self.assertEqual(o.getAvgFillPrice(), 124.62) + self.assertEqual(o.getQuantity(), 3) + self.assertEqual(o.getFilled(), 3) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) def testStopOrderBuy(self): @@ -166,11 +166,11 @@ def testStopOrderBuy(self): o = strat.stopOrder(StrategyTestCase.TestInstrument, 100, 1, False) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.BUY) - self.assertEquals(o.getAvgFillPrice(), 124.62) - self.assertEquals(o.getQuantity(), 1) - self.assertEquals(o.getFilled(), 1) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.BUY) + self.assertEqual(o.getAvgFillPrice(), 124.62) + self.assertEqual(o.getQuantity(), 1) + self.assertEqual(o.getFilled(), 1) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) def testStopOrderSell(self): @@ -179,11 +179,11 @@ def testStopOrderSell(self): o = strat.stopOrder(StrategyTestCase.TestInstrument, 55, -2, True) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.SELL) - self.assertEquals(o.getAvgFillPrice(), 55) - self.assertEquals(o.getQuantity(), 2) - self.assertEquals(o.getFilled(), 2) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.SELL) + self.assertEqual(o.getAvgFillPrice(), 55) + self.assertEqual(o.getQuantity(), 2) + self.assertEqual(o.getFilled(), 2) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) self.assertEqual(o.getExecutionInfo().getDateTime(), datetime.datetime(2000, 1, 19)) @@ -193,11 +193,11 @@ def testStopLimitOrderBuy(self): o = strat.stopLimitOrder(StrategyTestCase.TestInstrument, 110, 100, 1, True) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.BUY) - self.assertEquals(o.getAvgFillPrice(), 100) - self.assertEquals(o.getQuantity(), 1) - self.assertEquals(o.getFilled(), 1) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.BUY) + self.assertEqual(o.getAvgFillPrice(), 100) + self.assertEqual(o.getQuantity(), 1) + self.assertEqual(o.getFilled(), 1) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) self.assertEqual(o.getExecutionInfo().getDateTime(), datetime.datetime(2000, 1, 5)) @@ -207,11 +207,11 @@ def testStopLimitOrderSell(self): o = strat.stopLimitOrder(StrategyTestCase.TestInstrument, 100, 110, -2, True) strat.run() self.assertTrue(o.isFilled()) - self.assertEquals(o.getAction(), broker.Order.Action.SELL) - self.assertEquals(o.getAvgFillPrice(), 110) - self.assertEquals(o.getQuantity(), 2) - self.assertEquals(o.getFilled(), 2) - self.assertEquals(o.getRemaining(), 0) + self.assertEqual(o.getAction(), broker.Order.Action.SELL) + self.assertEqual(o.getAvgFillPrice(), 110) + self.assertEqual(o.getQuantity(), 2) + self.assertEqual(o.getFilled(), 2) + self.assertEqual(o.getRemaining(), 0) self.assertEqual(strat.orderUpdatedCalls, 3) self.assertEqual(o.getExecutionInfo().getDateTime(), datetime.datetime(2000, 1, 10)) diff --git a/testcases/technical_atr_test.py b/testcases/technical_atr_test.py index 7aa0ed805..27f9de3aa 100644 --- a/testcases/technical_atr_test.py +++ b/testcases/technical_atr_test.py @@ -67,6 +67,6 @@ def testStockChartsATRAdjusted(self): self.assertEqual(common.safe_round(atrDS[-1], 2), round(expected[i]/2, 2)) def testInvalidDataSeries(self): - with self.assertRaisesRegexp(Exception, "barDataSeries must be a dataseries.bards.BarDataSeries instance"): + with self. assertRaisesRegex(Exception, "barDataSeries must be a dataseries.bards.BarDataSeries instance"): ds = dataseries.SequenceDataSeries() atr.ATR(ds, 14, True) diff --git a/testcases/technical_hurst_test.py b/testcases/technical_hurst_test.py index 03a7a4083..d92ecfe65 100644 --- a/testcases/technical_hurst_test.py +++ b/testcases/technical_hurst_test.py @@ -38,35 +38,35 @@ class TestCase(common.TestCase): def testHurstExpFunRandomWalk(self): values = np.cumsum(np.random.randn(50000)) + 1000 h = hurst.hurst_exp(np.log10(values), 2, 20) - self.assertEquals(round(h, 1), 0.5) + self.assertEqual(round(h, 1), 0.5) def testHurstExpFunTrending(self): values = np.cumsum(np.random.randn(50000)+1) + 1000 h = hurst.hurst_exp(np.log10(values), 2, 20) - self.assertEquals(round(h), 1) + self.assertEqual(round(h), 1) def testHurstExpFunMeanRev(self): values = (np.random.randn(50000)) + 1000 h = hurst.hurst_exp(np.log10(values), 2, 20) - self.assertEquals(round(h), 0) + self.assertEqual(round(h), 0) def testRandomWalk(self): num_values = 10000 values = np.cumsum(np.random.randn(num_values)) + 1000 hds = build_hurst(values, num_values - 10, 2, 20) - self.assertEquals(round(hds[-1], 1), 0.5) - self.assertEquals(round(hds[-2], 1), 0.5) + self.assertEqual(round(hds[-1], 1), 0.5) + self.assertEqual(round(hds[-2], 1), 0.5) def testTrending(self): num_values = 10000 values = np.cumsum(np.random.randn(num_values) + 10) + 1000 hds = build_hurst(values, num_values - 10, 2, 20) - self.assertEquals(round(hds[-1], 1), 1) - self.assertEquals(round(hds[-2], 1), 1) + self.assertEqual(round(hds[-1], 1), 1) + self.assertEqual(round(hds[-2], 1), 1) def testMeanRev(self): num_values = 10000 values = np.random.randn(num_values) + 100 hds = build_hurst(values, num_values - 10, 2, 20) - self.assertEquals(round(hds[-1], 1), 0) - self.assertEquals(round(hds[-2], 1), 0) + self.assertEqual(round(hds[-1], 1), 0) + self.assertEqual(round(hds[-2], 1), 0) diff --git a/testcases/technical_linebreak_test.py b/testcases/technical_linebreak_test.py index f04e0faee..0de2ee5ba 100644 --- a/testcases/technical_linebreak_test.py +++ b/testcases/technical_linebreak_test.py @@ -93,12 +93,12 @@ def testLineBreakBounded(self): self.assertEqual(lineBreak[-1].isBlack(), True) def testInvalidDataSeries(self): - with self.assertRaisesRegexp(Exception, "barDataSeries must be a dataseries.bards.BarDataSeries instance"): + with self. assertRaisesRegex(Exception, "barDataSeries must be a dataseries.bards.BarDataSeries instance"): ds = dataseries.SequenceDataSeries() linebreak.LineBreak(ds, 3, maxLen=2) def testInvalidReversalLines(self): - with self.assertRaisesRegexp(Exception, "reversalLines must be greater than 1"): + with self. assertRaisesRegex(Exception, "reversalLines must be greater than 1"): barFeed = self.__getFeed() linebreak.LineBreak(barFeed[LineBreakTestCase.Instrument], 1, maxLen=2) @@ -106,7 +106,7 @@ def testInvalidMaxLen(self): barFeed = self.__getFeed() lb = linebreak.LineBreak(barFeed[LineBreakTestCase.Instrument], 3, maxLen=4) lb.setMaxLen(3) - with self.assertRaisesRegexp(Exception, "maxLen can't be smaller than reversalLines"): + with self. assertRaisesRegex(Exception, "maxLen can't be smaller than reversalLines"): lb.setMaxLen(2) def testWhiteBlackReversal(self): diff --git a/testcases/technical_trend_test.py b/testcases/technical_trend_test.py index c545a1ad2..44975c0ed 100644 --- a/testcases/technical_trend_test.py +++ b/testcases/technical_trend_test.py @@ -86,5 +86,5 @@ def testTrendWithCustomThresholds_Bounded(self): def testInvalidThreshold(self): seqDS = dataseries.SequenceDataSeries() - with self.assertRaisesRegexp(Exception, "Invalid thresholds"): + with self. assertRaisesRegex(Exception, "Invalid thresholds"): linreg.Trend(seqDS, 10, 0.2, 0.5, 5) diff --git a/testcases/utils_test.py b/testcases/utils_test.py index c9f1dea63..c15568211 100644 --- a/testcases/utils_test.py +++ b/testcases/utils_test.py @@ -39,7 +39,7 @@ def testChangePercentage(self): self.assertEqual(utils.get_change_percentage(1, -1), 2) self.assertEqual(utils.get_change_percentage(-2, -1), -1) self.assertEqual(utils.get_change_percentage(-1.5, -1), -0.5) - with self.assertRaisesRegexp(Exception, "Invalid values"): + with self. assertRaisesRegex(Exception, "Invalid values"): utils.get_change_percentage(-1.5, 0) def testSafeMin(self): @@ -332,9 +332,9 @@ def testTimeStampConversionsWithMicroseconds(self): self.assertEqual(dt.timestamp_to_datetime(dt.datetime_to_timestamp(dateTime), True), dateTime) def testGetFirstMonday(self): - self.assertEquals(dt.get_first_monday(2010), datetime.date(2010, 1, 4)) - self.assertEquals(dt.get_first_monday(2011), datetime.date(2011, 1, 3)) + self.assertEqual(dt.get_first_monday(2010), datetime.date(2010, 1, 4)) + self.assertEqual(dt.get_first_monday(2011), datetime.date(2011, 1, 3)) def testGetLastMonday(self): - self.assertEquals(dt.get_last_monday(2010), datetime.date(2010, 12, 27)) - self.assertEquals(dt.get_last_monday(2011), datetime.date(2011, 12, 26)) + self.assertEqual(dt.get_last_monday(2010), datetime.date(2010, 12, 27)) + self.assertEqual(dt.get_last_monday(2011), datetime.date(2011, 12, 26)) diff --git a/testcases/yahoofeed_test.py b/testcases/yahoofeed_test.py index 48d63560d..54116927f 100644 --- a/testcases/yahoofeed_test.py +++ b/testcases/yahoofeed_test.py @@ -96,15 +96,15 @@ def testInvalidConstruction(self): def testDefaultInstrument(self): barFeed = yahoofeed.Feed() - self.assertEquals(barFeed.getDefaultInstrument(), None) + self.assertEqual(barFeed.getDefaultInstrument(), None) barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv")) - self.assertEquals(barFeed.getDefaultInstrument(), FeedTestCase.TestInstrument) + self.assertEqual(barFeed.getDefaultInstrument(), FeedTestCase.TestInstrument) def testDuplicateBars(self): barFeed = yahoofeed.Feed() barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv")) barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv")) - with self.assertRaisesRegexp(Exception, "Duplicate bars found for.*"): + with self. assertRaisesRegex(Exception, "Duplicate bars found for.*"): barFeed.loadAll() def testBaseBarFeed(self): @@ -114,7 +114,7 @@ def testBaseBarFeed(self): barfeed_test.check_base_barfeed(self, barFeed, True) def testInvalidFrequency(self): - with self.assertRaisesRegexp(Exception, "Invalid frequency.*"): + with self. assertRaisesRegex(Exception, "Invalid frequency.*"): yahoofeed.Feed(frequency=bar.Frequency.MINUTE) def testBaseFeedInterface(self):