def _compute_busday_offsets(announcement_dates): """ Compute expected business day offsets from a DataFrame of announcement dates. """ # Column-vector of dates on which factor `compute` will be called. raw_call_dates = announcement_dates.index.values.astype( 'datetime64[D]')[:, None] # 2D array of dates containining expected nexg announcement. raw_announce_dates = ( announcement_dates.values.astype('datetime64[D]')) # Set NaTs to 0 temporarily because busday_count doesn't support NaT. # We fill these entries with NaNs later. whereNaT = raw_announce_dates == NaTD raw_announce_dates[whereNaT] = make_datetime64D(0) # The abs call here makes it so that we can use this function to # compute offsets for both next and previous earnings (previous # earnings offsets come back negative). expected = abs( np.busday_count(raw_call_dates, raw_announce_dates).astype(float)) expected[whereNaT] = np.nan return pd.DataFrame( data=expected, columns=announcement_dates.columns, index=announcement_dates.index, )
def _compute_busday_offsets(announcement_dates): """ Compute expected business day offsets from a DataFrame of announcement dates. """ # Column-vector of dates on which factor `compute` will be called. raw_call_dates = announcement_dates.index.values.astype( 'datetime64[D]' )[:, None] # 2D array of dates containining expected nexg announcement. raw_announce_dates = ( announcement_dates.values.astype('datetime64[D]') ) # Set NaTs to 0 temporarily because busday_count doesn't support NaT. # We fill these entries with NaNs later. whereNaT = raw_announce_dates == NaTD raw_announce_dates[whereNaT] = make_datetime64D(0) # The abs call here makes it so that we can use this function to # compute offsets for both next and previous earnings (previous # earnings offsets come back negative). expected = abs(np.busday_count( raw_call_dates, raw_announce_dates ).astype(float)) expected[whereNaT] = np.nan return pd.DataFrame( data=expected, columns=announcement_dates.columns, index=announcement_dates.index, )