code: def update_portfolio(self):
          
          if not self._dirty_portfolio:
              return
  
          portfolio = self._portfolio
          pt = self.position_tracker
  
          portfolio.positions = pt.get_positions()
          position_stats = pt.stats
  
          portfolio.positions_value = position_value = (
              position_stats.net_value
          )
          portfolio.positions_exposure = position_stats.net_exposure
          self._cash_flow(self._get_payout_total(pt.positions))
  
          start_value = portfolio.portfolio_value
  
          # update the new starting value
          portfolio.portfolio_value = end_value = portfolio.cash + position_value
  
          pnl = end_value - start_value
          if start_value != 0:
              returns = pnl / start_value
          else:
              returns = 0.0
  
          portfolio.pnl += pnl
          portfolio.returns = (
              (1 + portfolio.returns) *
              (1 + returns) -
              1
          )
  
          # the portfolio has been fully synced
          self._dirty_portfolio = False
docs: Force a computation of the current portfolio state.