'Calculate the ratios to apply to equities when looking back at pricing
history so that the price is smoothed over the ex_date, when the market
adjusts to the change in equity value due to upcoming dividend.
Returns
DataFrame
A frame in the same format as splits and mergers, with keys
- sid, the id of the equity
- effective_date, the date in seconds on which to apply the ratio.
- ratio, the ratio to apply to backwards looking pricing data.'

def calc_dividend_ratios(self, dividends):

    if ((dividends is None) or dividends.empty):
        return DataFrame(np.array([], dtype=[('sid', uint32), ('effective_date', uint32), ('ratio', float64)]))
    ex_dates = dividends.ex_date.values
    sids = dividends.sid.values
    amounts = dividends.amount.values
    ratios = full(len(amounts), nan)
    equity_daily_bar_reader = self._equity_daily_bar_reader
    effective_dates = full(len(amounts), (-1), dtype=int64)
    calendar = self._calendar
    tz_naive_calendar = calendar.tz_localize(None)
    day_locs = tz_naive_calendar.get_indexer(ex_dates, method='bfill')
    for (i, amount) in enumerate(amounts):
        sid = sids[i]
        ex_date = ex_dates[i]
        day_loc = day_locs[i]
        prev_close_date = calendar[(day_loc - 1)]
        try:
            prev_close = equity_daily_bar_reader.get_value(sid, prev_close_date, 'close')
            if (not isnull(prev_close)):
                ratio = (1.0 - (amount / prev_close))
                ratios[i] = ratio
                effective_dates[i] = ex_date
        except NoDataOnDate:
            logger.warn(("Couldn't    compute    ratio    for    dividend    %s" % {'sid': sid, 'ex_date': ex_date, 'amount': amount}))
            continue
    effective_mask = (effective_dates != (-1))
    effective_dates = effective_dates[effective_mask]
    effective_dates = effective_dates.astype('datetime64[ns]').astype('datetime64[s]').astype(uint32)
    sids = sids[effective_mask]
    ratios = ratios[effective_mask]
    return DataFrame({'sid': sids, 'effective_date': effective_dates, 'ratio': ratios})
