code: def earn_dividends(self, cash_dividends, stock_dividends):
          
          for cash_dividend in cash_dividends:
              self._dirty_stats = True  # only mark dirty if we pay a dividend
  
              # Store the earned dividends so that they can be paid on the
              # dividends' pay_dates.
              div_owed = self.positions[cash_dividend.asset].earn_dividend(
                  cash_dividend,
              )
              try:
                  self._unpaid_dividends[cash_dividend.pay_date].append(div_owed)
              except KeyError:
                  self._unpaid_dividends[cash_dividend.pay_date] = [div_owed]
  
          for stock_dividend in stock_dividends:
              self._dirty_stats = True  # only mark dirty if we pay a dividend
  
              div_owed = self.positions[
                  stock_dividend.asset
              ].earn_stock_dividend(stock_dividend)
              try:
                  self._unpaid_stock_dividends[stock_dividend.pay_date].append(
                      div_owed,
                  )
              except KeyError:
                  self._unpaid_stock_dividends[stock_dividend.pay_date] = [
                      div_owed,
                  ]
docs: Given a list of dividends whose ex_dates are all the next trading
          day, calculate and store the cash and/or stock payments to be paid on
          each dividend's pay date.
  
          Parameters
          ----------
          cash_dividends : iterable of (asset, amount, pay_date) namedtuples
  
          stock_dividends: iterable of (asset, payment_asset, ratio, pay_date)
              namedtuples.