code: def calculate_capital_changes(self, dt, emission_rate, is_interday,
                                    portfolio_value_adjustment=0.0):
          
          try:
              capital_change = self.capital_changes[dt]
          except KeyError:
              return
  
          self._sync_last_sale_prices()
          if capital_change['type'] == 'target':
              target = capital_change['value']
              capital_change_amount = (
                  target -
                  (
                      self.portfolio.portfolio_value -
                      portfolio_value_adjustment
                  )
              )
  
              log.info('Processing capital change to target %s at %s. Capital '
                       'change delta is %s' % (target, dt,
                                               capital_change_amount))
          elif capital_change['type'] == 'delta':
              target = None
              capital_change_amount = capital_change['value']
              log.info('Processing capital change of delta %s at %s'
                       % (capital_change_amount, dt))
          else:
              log.error("Capital change %s does not indicate a valid type "
                        "('target' or 'delta')" % capital_change)
              return
  
          self.capital_change_deltas.update({dt: capital_change_amount})
          self.metrics_tracker.capital_change(capital_change_amount)
  
          yield {
              'capital_change':
                  {'date': dt,
                   'type': 'cash',
                   'target': target,
                   'delta': capital_change_amount}
          }
docs: If there is a capital change for a given dt, this means the the change
          occurs before `handle_data` on the given dt. In the case of the
          change being a target value, the change will be computed on the
          portfolio value according to prices at the given dt
  
          `portfolio_value_adjustment`, if specified, will be removed from the
          portfolio_value of the cumulative performance when calculating deltas
          from target capital changes.