code: def trade_signals_handler(self, signals):
          '''
          Process buy and sell signals from the simulation
          '''
          alloc = {}
  
          if signals['buy'] or signals['sell']:
              # Compute the optimal portfolio allocation,
              # Using user defined function
              try:
                  alloc, e_ret, e_risk = self.optimize(
                      self.date, signals['buy'], signals['sell'],
                      self._optimizer_parameters)
              except Exception, error:
                  raise PortfolioOptimizationFailed(
                      reason=error, date=self.date, data=signals)
          return _remove_useless_orders(allocf trade_signals_handler(self, signals):
          '''
          Process buy and sell signals from the simulation
          '''
          alloc = {}
  
          if signals['buy'] or signals['sell']:
              # Compute the optimal portfolio allocation,
              # Using user defined function
              try:
                  alloc, e_ret, e_risk = self.optimize(
                      self.date, signals['buy'], signals['sell'],
                      self._optimizer_parameters)
              except Exception, error:
                  raise PortfolioOptimizationFailed(
                      reason=error, date=self.date, data=signals)
          return _remove_useless_orders(alloc)
docs: Process buy and sell signals from the simulation