code: def calculate_performance(self):
      pt = self.position_tracker
      pos_stats = pt.stats()
      self.ending_value = pos_stats.net_value
      self.ending_exposure = pos_stats.net_exposure
  
      payout = self._get_payout_total(pt.positions)
  
      self.ending_cash = (
          self.starting_cash
          + self.cash_flow
          + self._total_intraperiod_capital_change
          + payout
      )
  
      total_at_end = self.ending_cash + self.ending_value
  
      # If there is a previous subperiod, the performance is calculated
      # from the previous and current subperiods. Otherwise, the performance
      # is calculated based on the start and end values of the whole period
      if self.subperiod_divider:
          starting_cash = (
              self.subperiod_divider.curr_subperiod.starting_cash
          )
          total_at_start = (
              starting_cash
              + self.subperiod_divider.curr_subperiod.starting_value
          )
  
          # Performance for this subperiod
          pnl = total_at_end - total_at_start
          if total_at_start != 0:
              returns = pnl / total_at_start
          else:
              returns = 0.0
  
          # Performance for this whole period
          self.pnl = self.subperiod_divider.prev_subperiod.pnl + pnl
          self.returns = (
              1 + self.subperiod_divider.prev_subperiod.returns
          ) * (1 + returns) - 1
      else:
          total_at_start = self.starting_cash + self.starting_value
          self.pnl = total_at_end - total_at_start
  
          if total_at_start != 0:
              self.returns = self.pnl / total_at_start
          else:
              self.returns = 0.0
  
imports: from __future__ import division
  import logbook
  import numpy
  from collections import namedtuple
  from catalyst.assets import Future
  from six import itervalues, iteritems
  import catalyst.protocol
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 15 for calling the PerformancePeriod obj's underlying member method code with example usage: obj.calculate_performance() without return types