class_docstr: A :class:`pyalgotrade.stratanalyzer.StrategyAnalyzer` that records the profit/loss
  and returns of every completed trade.
  
  .. note::
      This analyzer operates on individual completed trades.
      For example, lets say you start with a $1000 cash, and then you buy 1 share of XYZ
      for $10 and later sell it for $20:
  
          * The trade's profit was $10.
          * The trade's return is 100%, even though your whole portfolio went from $1000 to $1020, a 2% return.
code: def __updatePosTracker(self, posTracker, price, commission, quantity):
      currentShares = posTracker.getPosition()
  
      if currentShares > 0:  # Current position is long
          if quantity > 0:  # Increase long position
              posTracker.buy(quantity, price, commission)
          else:
              newShares = currentShares + quantity
              if newShares == 0:  # Exit long.
                  posTracker.sell(currentShares, price, commission)
                  self.__updateTrades(posTracker)
              elif newShares > 0:  # Sell some shares.
                  posTracker.sell(quantity * -1, price, commission)
              else:  # Exit long and enter short. Use proportional commissions.
                  proportionalCommission = (
                      commission * currentShares / float(quantity * -1)
                  )
                  posTracker.sell(
                      currentShares, price, proportionalCommission
                  )
                  self.__updateTrades(posTracker)
                  proportionalCommission = (
                      commission * newShares / float(quantity)
                  )
                  posTracker.sell(
                      newShares * -1, price, proportionalCommission
                  )
      elif currentShares < 0:  # Current position is short
          if quantity < 0:  # Increase short position
              posTracker.sell(quantity * -1, price, commission)
          else:
              newShares = currentShares + quantity
              if newShares == 0:  # Exit short.
                  posTracker.buy(currentShares * -1, price, commission)
                  self.__updateTrades(posTracker)
              elif newShares < 0:  # Re-buy some shares.
                  posTracker.buy(quantity, price, commission)
              else:  # Exit short and enter long. Use proportional commissions.
                  proportionalCommission = (
                      commission * currentShares * -1 / float(quantity)
                  )
                  posTracker.buy(
                      currentShares * -1, price, proportionalCommission
                  )
                  self.__updateTrades(posTracker)
                  proportionalCommission = (
                      commission * newShares / float(quantity)
                  )
                  posTracker.buy(
                      newShares, price, proportionalCommission
                  )
      elif quantity > 0:
          posTracker.buy(quantity, price, commission)
      else:
          posTracker.sell(quantity * -1, price, commission)
  
imports: from pyalgotrade import stratanalyzer
  from pyalgotrade import broker
  from pyalgotrade.stratanalyzer import returns
  import numpy
label_desc: Use image node_id 3 for calling the Trades obj's underlying member method code with example usage: obj.__updatePosTracker(posTracker, price, commission, quantity) without return types