Ejemplo n.º 1
0
def get_vals_for_dates(zip_date_index_with_vals,
                       vals,
                       date_invervals,
                       dates):
    return pd.DataFrame({
        0: get_values_for_date_ranges(zip_date_index_with_vals,
                                      vals[0],
                                      date_invervals[0],
                                      dates),
        1: get_values_for_date_ranges(zip_date_index_with_vals,
                                      vals[1],
                                      date_invervals[1],
                                      dates),
        2: get_values_for_date_ranges(zip_date_index_with_vals,
                                      vals[2],
                                      date_invervals[2],
                                      dates),
        # Assume the latest of 2 cash values is used if we find out about 2
        # announcements that happened on the same day for the same sid.
        3: get_values_for_date_ranges(zip_date_index_with_vals,
                                      vals[3],
                                      date_invervals[3],
                                      dates),
        4: zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
    }, index=dates)
Ejemplo n.º 2
0
    def get_sids_to_frames(self,
                           zip_date_index_with_vals,
                           vals,
                           date_intervals,
                           dates):
        """
        Construct a DataFrame that maps sid to the expected values for the
        given dates.

        Parameters
        ----------
        zip_date_index_with_vals: callable
            A function that returns a series of `vals` repeated based on the
            number of days in the date interval for each val, indexed by the
            dates in `dates`.
        vals: iterable
            An iterable with values that correspond to each interval in
            `date_intervals`.
        date_intervals: list
            A list of date intervals for each sid that correspond to values in
            `vals`.
        dates: DatetimeIndex
            The dates which will serve as the index for each Series for each
            sid in the DataFrame.
        """
        frame = pd.DataFrame({sid: get_values_for_date_ranges(
            zip_date_index_with_vals,
            vals[sid],
            date_intervals[sid],
            dates
        ) for sid in self.get_sids()[:-1]})
        frame[self.get_sids()[-1]] = zip_date_index_with_vals(
            dates, ['NaN'] * len(dates)
        )
        return frame
Ejemplo n.º 3
0
    def get_sids_to_frames(self, zip_date_index_with_vals, vals,
                           date_intervals, dates):
        """
        Construct a DataFrame that maps sid to the expected values for the
        given dates.

        Parameters
        ----------
        zip_date_index_with_vals: callable
            A function that returns a series of `vals` repeated based on the
            number of days in the date interval for each val, indexed by the
            dates in `dates`.
        vals: iterable
            An iterable with values that correspond to each interval in
            `date_intervals`.
        date_intervals: list
            A list of date intervals for each sid that correspond to values in
            `vals`.
        dates: DatetimeIndex
            The dates which will serve as the index for each Series for each
            sid in the DataFrame.
        """
        frame = pd.DataFrame({
            sid:
            get_values_for_date_ranges(zip_date_index_with_vals, vals[sid],
                                       date_intervals[sid], dates)
            for sid in self.get_sids()[:-1]
        })
        frame[self.get_sids()[-1]] = zip_date_index_with_vals(
            dates, ['NaN'] * len(dates))
        return frame
Ejemplo n.º 4
0
def get_expected_previous_values(zip_date_index_with_vals,
                                 dates,
                                 vals_for_date_intervals):
    return pd.DataFrame({
        0: get_values_for_date_ranges(zip_date_index_with_vals,
                                      vals_for_date_intervals,
                                      date_intervals,
                                      dates),
        1: zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
    }, index=dates)
Ejemplo n.º 5
0
 def get_expected_previous_event_dates(self, dates):
     return pd.DataFrame(
         {
             0:
             get_values_for_date_ranges(zip_with_dates, prev_dates[0],
                                        prev_date_intervals[0], dates),
             1:
             get_values_for_date_ranges(zip_with_dates, prev_dates[1],
                                        prev_date_intervals[1], dates),
             2:
             get_values_for_date_ranges(zip_with_dates, prev_dates[2],
                                        prev_date_intervals[2], dates),
             3:
             get_values_for_date_ranges(zip_with_dates, prev_dates[3],
                                        prev_date_intervals[3], dates),
             4:
             zip_with_dates(dates, ['NaT'] * len(dates)),
         },
         index=dates)
Ejemplo n.º 6
0
 def get_expected_previous_event_dates(self, dates):
     return pd.DataFrame({
         0: get_values_for_date_ranges(zip_with_dates,
                                       prev_dates[0],
                                       prev_date_intervals[0],
                                       dates),
         1: get_values_for_date_ranges(zip_with_dates,
                                       prev_dates[1],
                                       prev_date_intervals[1],
                                       dates),
         2: get_values_for_date_ranges(zip_with_dates,
                                       prev_dates[2],
                                       prev_date_intervals[2],
                                       dates),
         3: get_values_for_date_ranges(zip_with_dates,
                                       prev_dates[3],
                                       prev_date_intervals[3],
                                       dates),
         4: zip_with_dates(dates, ['NaT'] * len(dates)),
     }, index=dates)
Ejemplo n.º 7
0
def get_expected_previous_values(zip_date_index_with_vals, dates,
                                 vals_for_date_intervals):
    return pd.DataFrame(
        {
            0:
            get_values_for_date_ranges(zip_date_index_with_vals,
                                       vals_for_date_intervals, date_intervals,
                                       dates),
            1:
            zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
        },
        index=dates)
Ejemplo n.º 8
0
def get_vals_for_dates(zip_date_index_with_vals, vals, date_invervals, dates):
    return pd.DataFrame(
        {
            0:
            get_values_for_date_ranges(zip_date_index_with_vals, vals[0],
                                       date_invervals[0], dates),
            1:
            get_values_for_date_ranges(zip_date_index_with_vals, vals[1],
                                       date_invervals[1], dates),
            2:
            get_values_for_date_ranges(zip_date_index_with_vals, vals[2],
                                       date_invervals[2], dates),
            # Assume the latest of 2 cash values is used if we find out about 2
            # announcements that happened on the same day for the same sid.
            3:
            get_values_for_date_ranges(zip_date_index_with_vals, vals[3],
                                       date_invervals[3], dates),
            4:
            zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
        },
        index=dates)
Ejemplo n.º 9
0
    def get_sids_to_frames(self,
                           zip_date_index_with_vals,
                           vals,
                           date_intervals,
                           dates,
                           dtype_name,
                           missing_dtype):
        """
        Construct a DataFrame that maps sid to the expected values for the
        given dates.

        Parameters
        ----------
        zip_date_index_with_vals: callable
            A function that returns a series of `vals` repeated based on the
            number of days in the date interval for each val, indexed by the
            dates in `dates`.
        vals: iterable
            An iterable with values that correspond to each interval in
            `date_intervals`.
        date_intervals: list
            A list of date intervals for each sid that correspond to values in
            `vals`.
        dates: DatetimeIndex
            The dates which will serve as the index for each Series for each
            sid in the DataFrame.
        dtype_name: str
            The name of the dtype of the values in `vals`.
        missing_dtype: str
            The name of the value that should be used as the missing value
            for the dtype of `vals` - e.g., 'NaN' for floats.
        """
        frame = pd.DataFrame({sid: get_values_for_date_ranges(
            zip_date_index_with_vals,
            vals[sid],
            pd.DatetimeIndex(list(zip(*date_intervals[sid]))[0]),
            pd.DatetimeIndex(list(zip(*date_intervals[sid]))[1]),
            dates
        ).astype(dtype_name) for sid in self.get_sids()[:-1]})
        frame[self.get_sids()[-1]] = zip_date_index_with_vals(
            dates, [missing_dtype] * len(dates)
        ).astype(dtype_name)
        return frame
Ejemplo n.º 10
0
    def get_sids_to_frames(self, zip_date_index_with_vals, vals,
                           date_intervals, dates, dtype_name, missing_dtype):
        """
        Construct a DataFrame that maps sid to the expected values for the
        given dates.

        Parameters
        ----------
        zip_date_index_with_vals: callable
            A function that returns a series of `vals` repeated based on the
            number of days in the date interval for each val, indexed by the
            dates in `dates`.
        vals: iterable
            An iterable with values that correspond to each interval in
            `date_intervals`.
        date_intervals: list
            A list of date intervals for each sid that correspond to values in
            `vals`.
        dates: DatetimeIndex
            The dates which will serve as the index for each Series for each
            sid in the DataFrame.
        dtype_name: str
            The name of the dtype of the values in `vals`.
        missing_dtype: str
            The name of the value that should be used as the missing value
            for the dtype of `vals` - e.g., 'NaN' for floats.
        """
        frame = pd.DataFrame({
            sid: get_values_for_date_ranges(
                zip_date_index_with_vals, vals[sid],
                pd.DatetimeIndex(list(zip(*date_intervals[sid]))[0]),
                pd.DatetimeIndex(list(zip(*date_intervals[sid]))[1]),
                dates).astype(dtype_name)
            for sid in self.get_sids()[:-1]
        })
        frame[self.get_sids()[-1]] = zip_date_index_with_vals(
            dates, [missing_dtype] * len(dates)).astype(dtype_name)
        return frame