Dividends from a stock you're long simply magically increase your cash position. (To see this, write and backtest an algorithm that calculates every day, or every minute, how many shares, with commissions, it can afford to buy with the cash on hand, buys if greater than zero, and never sells. Then look at the list of transactions. You could also record(cash=context.portfolio.cash)
.) I suppose you could carefully track your cash, and attribute discrepancies to dividends. Likewise, mutatis mutandis, for stocks you're short, where you're charged the dividend amount you must pay to the owner of the shares.