'Compute a DataFrame representing asset lifetimes for the specified date
range.
Parameters
dates : pd.DatetimeIndex
The dates for which to compute lifetimes.
include_start_date : bool
Whether or not to count the asset as alive on its start_date.
This is useful in a backtesting context where `lifetimes` is being
used to signify "do I have data for this asset as of the morning of
this date?"  For many financial metrics, (e.g. daily close), data
isn\'t available for an asset until the end of the asset\'s first
day.
Returns
lifetimes : pd.DataFrame
A frame of dtype bool with `dates` as index and an Int64Index of
assets as columns.  The value at `lifetimes.loc[date, asset]` will
be True iff `asset` existed on `date`.  If `include_start_date` is
False, then lifetimes.loc[date, asset] will be false when date ==
asset.start_date.
See Also
numpy.putmask
zipline.pipeline.engine.SimplePipelineEngine._compute_root_mask'

def lifetimes(self, dates, include_start_date):

    if (self._asset_lifetimes is None):
        self._asset_lifetimes = self._compute_asset_lifetimes()
    lifetimes = self._asset_lifetimes
    raw_dates = as_column(dates.asi8)
    if include_start_date:
        mask = (lifetimes.start <= raw_dates)
    else:
        mask = (lifetimes.start < raw_dates)
    mask &= (raw_dates <= lifetimes.end)
    return pd.DataFrame(mask, index=dates, columns=lifetimes.sid)
