def testSeparateAndCombined(self):
        posA = returns.PositionTracker(broker.IntegerTraits())
        posA.buy(11, 10)
        posA.sell(11, 30)
        self.assertEqual(posA.getPnL(), 20*11)
        self.assertEqual(posA.getReturn(), 2)

        posB = returns.PositionTracker(broker.IntegerTraits())
        posB.sell(100, 1.1)
        posB.buy(100, 1)
        self.assertEqual(round(posB.getPnL(), 2), 100*0.1)
        self.assertEqual(round(posB.getReturn(), 2), 0.09)

        combinedPos = returns.PositionTracker(broker.IntegerTraits())
        combinedPos.buy(11, 10)
        combinedPos.sell(11, 30)
        combinedPos.sell(100, 1.1)
        combinedPos.buy(100, 1)
        self.assertEqual(round(combinedPos.getReturn(), 6), 2.090909)
        # The return of the combined position is less than the two returns combined
        # because when the second position gets opened the amount of cash not invested is greater
        # than that of posB alone.
        self.assertLess(round(combinedPos.getReturn(), 6), (1-(1+posA.getReturn())*(1+posB.getReturn())))
dataset/ETHPy150Open gbeced/pyalgotrade/testcases/returns_analyzer_test.py/PosTrackerTestCase.testSeparateAndCombined/swapped operands of `-`