'Returns a cash payment based on the dividends that should be paid out
according to the accumulated bookkeeping of earned, unpaid, and stock
dividends.'

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:
        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
