Пример #1
0
def select_sampling_indices(dates, frequency):
    """
    Choose entries from ``dates`` to use for downsampling at ``frequency``.

    Parameters
    ----------
    dates : pd.DatetimeIndex
        Dates from which to select sample choices.
    {frequency}

    Returns
    -------
    indices : np.array[int64]
        An array condtaining indices of dates on which samples should be taken.

        The resulting index will always include 0 as a sample index, and it
        will include the first date of each subsequent year/quarter/month/week,
        as determined by ``frequency``.

    Notes
    -----
    This function assumes that ``dates`` does not have large gaps.

    In particular, it assumes that the maximum distance between any two entries
    in ``dates`` is never greater than a year, which we rely on because we use
    ``np.diff(dates.<frequency>)`` to find dates where the sampling
    period has changed.
    """
    if frequency == "week_start":
        # dates.week is deprecated, uses dates.isocalendar().week
        dates = dates.isocalendar()

    return changed_locations(_dt_to_period[frequency](dates),
                             include_first=True)
Пример #2
0
def select_sampling_indices(dates, frequency):
    """
    Choose entries from ``dates`` to use for downsampling at ``frequency``.

    Parameters
    ----------
    dates : pd.DatetimeIndex
        Dates from which to select sample choices.
    {frequency}

    Returns
    -------
    indices : np.array[int64]
        An array condtaining indices of dates on which samples should be taken.

        The resulting index will always include 0 as a sample index, and it
        will include the first date of each subsequent year/quarter/month/week,
        as determined by ``frequency``.

    Notes
    -----
    This function assumes that ``dates`` does not have large gaps.

    In particular, it assumes that the maximum distance between any two entries
    in ``dates`` is never greater than a year, which we rely on because we use
    ``np.diff(dates.<frequency>)`` to find dates where the sampling
    period has changed.
    """
    return changed_locations(
        _dt_to_period[frequency](dates),
        include_first=True
    )
Пример #3
0
 def compute(self, today, assets, out, sales, asof_date):
     # 原始数据已经reindex全部季度,所以只需要单个资产的asof_date
     idx = changed_locations(asof_date.T[0], include_first=True)[1:]
     adj = quarterly_multiplier(asof_date[idx])
     # 将各季度调整为年销售额,然后再平均
     res = np.multiply(sales[idx], adj).mean()
     # 收入单位为万元
     out[:] = res * 10000