def pay_dividends(self, next_trading_day):
        """
        Returns a cash payment based on the dividends that should be paid out
        according to the accumulated bookkeeping of earned, unpaid, and stock
        dividends.
        """
        net_cash_payment = 0.0

        try:
            payments = self._unpaid_dividends[next_trading_day]
            # Mark these dividends as paid by dropping them from our unpaid
            del self._unpaid_dividends[next_trading_day]
        except KeyError:
            payments = []

        # representing the fact that we're required to reimburse the owner of
        # the stock for any dividends paid while borrowing.
        for payment in payments:
            net_cash_payment += payment['amount']

        # Add stock for any stock dividends paid.  Again, the values here may
        # be negative in the case of short positions.
        try:
            stock_payments = self._unpaid_stock_dividends[next_trading_day]
        except KeyError:
            stock_payments = []

        for stock_payment in stock_payments:
            payment_asset = stock_payment['payment_asset']
            share_count = stock_payment['share_count']
            # note we create a Position for stock dividend if we don't
            # already own the asset
            if payment_asset in self.positions:
                position = self.positions[payment_asset]
            else:
                position = self.positions[payment_asset] = Position(
                    payment_asset,
                )

            position.amount += share_count

        return net_cash_payment
def pay_dividends ( self , next_trading_day ) : net_cash_payment = 0.0 try : payments = self . _unpaid_dividends [ next_trading_day ] del self . _unpaid_dividends [ next_trading_day ] except KeyError : payments = [ ] for payment in payments : net_cash_payment += payment [ 'amount' ] try : stock_payments = self . _unpaid_stock_dividends [ next_trading_day ] except KeyError : stock_payments = [ ] for stock_payment in stock_payments : payment_asset = stock_payment [ 'payment_asset' ] share_count = stock_payment [ 'share_count' ] if payment_asset in self . positions : position = self . positions [ payment_asset ] else : position = self . positions [ payment_asset ] = Position ( payment_asset , ) position . amount += share_count return net_cash_payment
Returns a cash payment based on the dividends that should be paid out
        according to the accumulated bookkeeping of earned, unpaid, and stock
        dividends.