分钟线回测的时候的gap

def QA_util_time_gap(time, gap, methods, type_):
    '分钟线回测的时候的gap'
    min_len = int(240 / int(str(type_).split('min')[0]))
    day_gap = math.ceil(gap / min_len)

    if methods in ['>', 'gt']:
        data = pd.concat(
            [
                pd.DataFrame(QA_util_make_min_index(day,
                                                    type_))
                for day in trade_date_sse[trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ):trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) + day_gap + 1]
            ]
        ).reset_index()
        return np.asarray(
            data[data[0] > time].head(gap)[0].apply(lambda x: str(x))
        ).tolist()[-1]
    elif methods in ['>=', 'gte']:
        data = pd.concat(
            [
                pd.DataFrame(QA_util_make_min_index(day,
                                                    type_))
                for day in trade_date_sse[trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ):trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) + day_gap + 1]
            ]
        ).reset_index()

        return np.asarray(
            data[data[0] >= time].head(gap)[0].apply(lambda x: str(x))
        ).tolist()[-1]
    elif methods in ['<', 'lt']:
        data = pd.concat(
            [
                pd.DataFrame(QA_util_make_min_index(day,
                                                    type_))
                for day in trade_date_sse[trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) - day_gap:trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) + 1]
            ]
        ).reset_index()

        return np.asarray(
            data[data[0] < time].tail(gap)[0].apply(lambda x: str(x))
        ).tolist()[0]
    elif methods in ['<=', 'lte']:
        data = pd.concat(
            [
                pd.DataFrame(QA_util_make_min_index(day,
                                                    type_))
                for day in trade_date_sse[trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) - day_gap:trade_date_sse.index(
                    str(
                        datetime.datetime.strptime(time,
                                                   '%Y-%m-%d %H:%M:%S').date()
                    )
                ) + 1]
            ]
        ).reset_index()

        return np.asarray(
            data[data[0] <= time].tail(gap)[0].apply(lambda x: str(x))
        ).tolist()[0]
    elif methods in ['==', '=', 'eq']:
        return time