Exemplo n.º 1
0
def proportion_pd_object_intraday(data,
                                  closing_time=pd.DateOffset(hours=23,
                                                             minutes=0,
                                                             seconds=0)):
    """
    Return the proportion of intraday data in a pd.Series or DataFrame

    :param data: the underlying data
    :param closing_time: the time which we are using as a closing time
    :return: float, the proportion of the data.index that matches an intraday timestamp

    So 0 = All daily data, 1= All intraday data
    """

    data_index = data.index
    length_index = len(data_index)

    count_matches = [
        time_matches(index_entry, closing_time) for index_entry in data_index
    ]
    total_matches = sum(count_matches)
    proportion_matching_close = float(total_matches) / float(length_index)
    proportion_intraday = 1 - proportion_matching_close

    return proportion_intraday
Exemplo n.º 2
0
def strip_out_intraday(data,  closing_time = pd.DateOffset(hours=23, minutes=0, seconds=0)):
    """
    Return a pd.Series or DataFrame with only the times matching closing_time
    Used when we have a mix of daily and intraday data, where the daily data has been given a nominal timestamp

    :param data: pd object
    :param closing_time: pdDateOffset with
    :return: pd object
    """

    data_index = data.index
    length_index = len(data_index)

    daily_matches = [time_matches(index_entry, closing_time) for index_entry in data_index]

    return data[daily_matches]
Exemplo n.º 3
0
def proportion_pd_object_intraday(
        data, closing_time=NOTIONAL_CLOSING_TIME_AS_PD_OFFSET):
    """
    Return the proportion of intraday data in a pd.Series or DataFrame

    :param data: the underlying data
    :param closing_time: the time which we are using as a closing time
    :return: float, the proportion of the data.index that matches an intraday timestamp

    So 0 = All daily data, 1= All intraday data
    """

    data_index = data.index
    length_index = len(data_index)

    count_matches = [
        time_matches(index_entry, closing_time) for index_entry in data_index
    ]
    total_matches = sum(count_matches)
    proportion_matching_close = float(total_matches) / float(length_index)
    proportion_intraday = 1 - proportion_matching_close

    return proportion_intraday
Exemplo n.º 4
0
def intraday_date_rows_in_pd_object(pd_object):
    return pd_object[[
        not time_matches(index_entry, NOTIONAL_CLOSING_TIME_AS_PD_OFFSET)
        for index_entry in pd_object.index
    ]]