コード例 #1
0
def get_indicator_rr_table(**kwargs):

    trade_data = kwargs['trade_data']
    indicator_name = kwargs['indicator_name']
    strategy_class = kwargs['strategy_class']
    long_pnl_field = kwargs['long_pnl_field']
    short_pnl_field = kwargs['short_pnl_field']

    if 'num_buckets' in kwargs.keys():
        num_buckets = kwargs['num_buckets']
    else:
        num_buckets = 9

    trade_data = trade_data[
        (np.isfinite(trade_data[long_pnl_field].values.astype(np.float64)))
        & (np.isfinite(trade_data[short_pnl_field].values.astype(np.float64)))
        & (np.isfinite(trade_data[indicator_name].values.astype(np.float64)))]

    signal_correlation = sigut.get_signal_correlation(
        strategy_class=strategy_class, signal_name=indicator_name)
    ascending_q = True if signal_correlation < 0 else False

    bucket_data_output = su.bucket_data(data_input=trade_data,
                                        bucket_var=indicator_name,
                                        num_buckets=num_buckets,
                                        ascending_q=ascending_q)
    bucket_data_list = bucket_data_output['bucket_data_list']
    bucket_limits = bucket_data_output['bucket_limits']

    mean_pnl_list = []
    reward_risk_list = []

    for i in range(num_buckets):

        bucket_data = bucket_data_list[i]

        if i <= (num_buckets / 2):
            signed_pnl = bucket_data[long_pnl_field]
        else:
            signed_pnl = bucket_data[short_pnl_field]

        stats_output = get_summary_stats(signed_pnl.values.astype(np.float64))
        mean_pnl_list.append(stats_output['mean_pnl'])
        reward_risk_list.append(stats_output['reward_risk'])

    if ascending_q:
        indicator_ulimit = np.append(bucket_limits, np.NAN)
    else:
        indicator_ulimit = np.append(np.NAN, bucket_limits)

    return pd.DataFrame.from_items([('indicator_ulimit', indicator_ulimit),
                                    ('mean_pnl', mean_pnl_list),
                                    ('reward_risk', reward_risk_list)])
コード例 #2
0
def get_indicator_rr_table(**kwargs):

    trade_data = kwargs['trade_data']
    indicator_name = kwargs['indicator_name']
    strategy_class = kwargs['strategy_class']
    long_pnl_field = kwargs['long_pnl_field']
    short_pnl_field = kwargs['short_pnl_field']

    if 'num_buckets' in kwargs.keys():
        num_buckets = kwargs['num_buckets']
    else:
        num_buckets = 9

    trade_data = trade_data[(np.isfinite(trade_data[long_pnl_field])) & (np.isfinite(trade_data[short_pnl_field]))]

    signal_correlation = sigut.get_signal_correlation(strategy_class=strategy_class,signal_name=indicator_name)
    ascending_q = True if signal_correlation<0 else False

    bucket_data_output = su.bucket_data(data_input=trade_data, bucket_var=indicator_name, num_buckets=num_buckets,ascending_q=ascending_q)
    bucket_data_list = bucket_data_output['bucket_data_list']
    bucket_limits = bucket_data_output['bucket_limits']

    mean_pnl_list = []
    reward_risk_list = []

    for i in range(num_buckets):

        bucket_data = bucket_data_list[i]

        if i <= (num_buckets/2):
            signed_pnl = bucket_data[long_pnl_field]
        else:
            signed_pnl = bucket_data[short_pnl_field]

        stats_output = get_summary_stats(signed_pnl.values)
        mean_pnl_list.append(stats_output['mean_pnl'])
        reward_risk_list.append(stats_output['reward_risk'])

    if ascending_q:
        indicator_ulimit = np.append(bucket_limits, np.NAN)
    else:
        indicator_ulimit = np.append(np.NAN,bucket_limits)

    return pd.DataFrame.from_items([('indicator_ulimit', indicator_ulimit),
                         ('mean_pnl', mean_pnl_list),
                         ('reward_risk',reward_risk_list)])
コード例 #3
0
def get_indicator_rr_double_table(**kwargs):

    trade_data = kwargs['trade_data']
    indicator_list = kwargs['indicator_list']
    strategy_class = kwargs['strategy_class']
    long_pnl_field = kwargs['long_pnl_field']
    short_pnl_field = kwargs['short_pnl_field']

    #print(indicator_list)

    if 'num_buckets' in kwargs.keys():
        num_buckets = kwargs['num_buckets']
    else:
        num_buckets = 3

    trade_data = trade_data[
        (np.isfinite(trade_data[long_pnl_field].values.astype(np.float64)))
        & (np.isfinite(trade_data[short_pnl_field].values.astype(np.float64)))
        &
        (np.isfinite(trade_data[indicator_list[0]].values.astype(np.float64)))
        &
        (np.isfinite(trade_data[indicator_list[1]].values.astype(np.float64)))]

    signal_correlation1 = sigut.get_signal_correlation(
        strategy_class=strategy_class, signal_name=indicator_list[0])
    signal_correlation2 = sigut.get_signal_correlation(
        strategy_class=strategy_class, signal_name=indicator_list[1])

    ascending_q1 = True if signal_correlation1 < 0 else False
    ascending_q2 = True if signal_correlation2 < 0 else False

    bucket_data_output = su.bucket_data(data_input=trade_data,
                                        bucket_var=indicator_list[0],
                                        num_buckets=num_buckets,
                                        ascending_q=ascending_q1)
    bucket_data_list1 = bucket_data_output['bucket_data_list']

    if ascending_q1:
        bucket_limits1_full = np.repeat(
            np.append(bucket_data_output['bucket_limits'], np.NAN),
            num_buckets)
    else:
        bucket_limits1_full = np.repeat(
            np.append(np.NAN, bucket_data_output['bucket_limits']),
            num_buckets)

    bucket_limits2_full = np.empty([1, 0])

    mean_pnl_list = []
    reward_risk_list = []

    for i in range(len(bucket_data_list1)):
        bucket_data_output = su.bucket_data(data_input=bucket_data_list1[i],
                                            bucket_var=indicator_list[1],
                                            num_buckets=num_buckets,
                                            ascending_q=ascending_q2)
        bucket_data_list2 = bucket_data_output['bucket_data_list']
        bucket_limits2 = bucket_data_output['bucket_limits']

        if ascending_q2:
            bucket_limits2_full = np.append(bucket_limits2_full,
                                            np.append(bucket_limits2, np.NAN))
        else:
            bucket_limits2_full = np.append(bucket_limits2_full,
                                            np.append(np.NAN, bucket_limits2))

        for j in range(len(bucket_data_list2)):

            if i <= (num_buckets / 2):
                signed_pnl = bucket_data_list2[j][long_pnl_field]
            else:
                signed_pnl = bucket_data_list2[j][short_pnl_field]

            stats_output = get_summary_stats(signed_pnl.values)
            mean_pnl_list.append(stats_output['mean_pnl'])
            reward_risk_list.append(stats_output['reward_risk'])

    return pd.DataFrame.from_items([('indicator1_ulimit', bucket_limits1_full),
                                    ('indicator2_ulimit', bucket_limits2_full),
                                    ('mean_pnl', mean_pnl_list),
                                    ('reward_risk', reward_risk_list)])
コード例 #4
0
def get_indicator_rr_double_table(**kwargs):

    trade_data = kwargs['trade_data']
    indicator_list = kwargs['indicator_list']
    strategy_class = kwargs['strategy_class']
    long_pnl_field = kwargs['long_pnl_field']
    short_pnl_field = kwargs['short_pnl_field']

    if 'num_buckets' in kwargs.keys():
        num_buckets = kwargs['num_buckets']
    else:
        num_buckets = 3

    trade_data = trade_data[(np.isfinite(trade_data[long_pnl_field])) & (np.isfinite(trade_data[short_pnl_field]))]

    signal_correlation1 = sigut.get_signal_correlation(strategy_class=strategy_class,signal_name=indicator_list[0])
    signal_correlation2 = sigut.get_signal_correlation(strategy_class=strategy_class,signal_name=indicator_list[1])

    ascending_q1 = True if signal_correlation1<0 else False
    ascending_q2 = True if signal_correlation2<0 else False

    bucket_data_output = su.bucket_data(data_input=trade_data, bucket_var=indicator_list[0],
                                        num_buckets=num_buckets, ascending_q=ascending_q1)
    bucket_data_list1 = bucket_data_output['bucket_data_list']

    if ascending_q1:
        bucket_limits1_full = np.repeat(np.append(bucket_data_output['bucket_limits'], np.NAN), num_buckets)
    else:
        bucket_limits1_full = np.repeat(np.append(np.NAN,bucket_data_output['bucket_limits']), num_buckets)


    bucket_limits2_full = np.empty([1, 0])

    mean_pnl_list = []
    reward_risk_list = []

    for i in range(len(bucket_data_list1)):
        bucket_data_output = su.bucket_data(data_input=bucket_data_list1[i],
                                            bucket_var=indicator_list[1],
                                            num_buckets=num_buckets,
                                            ascending_q=ascending_q2)
        bucket_data_list2 = bucket_data_output['bucket_data_list']
        bucket_limits2 = bucket_data_output['bucket_limits']

        if ascending_q2:
            bucket_limits2_full = np.append(bucket_limits2_full,
                                            np.append(bucket_limits2, np.NAN))
        else:
            bucket_limits2_full = np.append(bucket_limits2_full,
                                            np.append(np.NAN,bucket_limits2))

        for j in range(len(bucket_data_list2)):

            if i <= (num_buckets/2):
                signed_pnl = bucket_data_list2[j][long_pnl_field]
            else:
                signed_pnl = bucket_data_list2[j][short_pnl_field]

            stats_output = get_summary_stats(signed_pnl.values)
            mean_pnl_list.append(stats_output['mean_pnl'])
            reward_risk_list.append(stats_output['reward_risk'])

    return pd.DataFrame.from_items([('indicator1_ulimit', bucket_limits1_full),
                                 ('indicator2_ulimit', bucket_limits2_full),
                                  ('mean_pnl', mean_pnl_list),
                                 ('reward_risk',reward_risk_list)])