Пример #1
0
def cal_obj(signal, name, period, quantile):
    obj = SignalDigger(
    )  #SignalDigger实体化,下面调用它的方法process_signal_before_analysis
    obj.process_signal_before_analysis(
        signal,  #因子数据
        price=price,  #价格数据
        n_quantiles=quantile,  #百分位
        period=period,  #持有周期
        can_enter=can_enter,  #能买入
        can_exit=can_exit,  #能卖出
        group=group,  #行业分类表格
        mask=mask  #指数成分的过滤
    )
    obj.create_full_report()  #创建一个完整的report
    return obj
Пример #2
0
def analyze_signal(dv, signal_name, output_format='pdf'):
    # Step.2 calculate mask (to mask those ill data points)
    mask_sus = dv.get_ts('suspended')
    mask_index_member = dv.get_ts('not_index_member')
    mask_limit_reached = dv.get_ts('limit_reached')
    mask_all = np.logical_or(
        mask_sus, np.logical_or(mask_index_member, mask_limit_reached))

    signal = dv.get_ts(signal_name)  # avoid look-ahead bias
    price = dv.get_ts('close_adj')
    price_bench = dv.data_benchmark

    # Step.4 analyze!
    my_period = 5
    obj = SignalDigger(output_folder='../../output/test_signal',
                       output_format=output_format)
    obj.process_signal_before_analysis(
        signal,
        price=price,
        mask=mask_all,
        n_quantiles=5,
        period=my_period,
        benchmark_price=price_bench,
    )
    res = obj.create_full_report()
Пример #3
0
def analyze_signal():
    # --------------------------------------------------------------------------------
    # Step.1 load dataview
    dv = DataView()
    dv.load_dataview(dataview_folder)

    # --------------------------------------------------------------------------------
    # Step.2 calculate mask (to mask those ill data points)
    trade_status = dv.get_ts('trade_status')
    mask_sus = trade_status == u'停牌'.encode('utf-8')

    df_index_member = dv.get_ts('index_member')
    mask_index_member = ~(df_index_member > 0)

    dv.add_formula('limit_reached',
                   'Abs((open - Delay(close, 1)) / Delay(close, 1)) > 0.095',
                   is_quarterly=False)
    df_limit_reached = dv.get_ts('limit_reached')
    mask_limit_reached = df_limit_reached > 0

    mask_all = np.logical_or(
        mask_sus, np.logical_or(mask_index_member, mask_limit_reached))

    # --------------------------------------------------------------------------------
    # Step.3 get signal, benchmark and price data
    # dv.add_formula('illi_daily', '(high - low) * 1000000000 / turnover', is_quarterly=False)
    # dv.add_formula('illi', 'Ewma(illi_daily, 11)', is_quarterly=False)

    # dv.add_formula('size', 'Log(float_mv)', is_quarterly=False)
    # dv.add_formula('value', '-1.0/pb', is_quarterly=False)
    # dv.add_formula('liquidity', 'Ts_Mean(volume, 22) / float_mv', is_quarterly=False)
    dv.add_formula('divert',
                   '- Correlation(vwap_adj, volume, 10)',
                   is_quarterly=False)

    signal = dv.get_ts('divert').shift(1, axis=0)  # avoid look-ahead bias
    price = dv.get_ts('close_adj')
    price_bench = dv.data_benchmark

    # Step.4 analyze!
    my_period = 5
    obj = SignalDigger(output_folder='../../output/test_signal',
                       output_format='pdf')
    obj.process_signal_before_analysis(
        signal,
        price=price,
        mask=mask_all,
        n_quantiles=5,
        period=my_period,
        benchmark_price=price_bench,
    )
    res = obj.create_full_report()
Пример #4
0
def test_analyze_signal():
    # --------------------------------------------------------------------------------
    # Step.1 load dataview
    dv = DataView()
    dv.load_dataview(dataview_folder)

    mask = mask_index_member(dv)
    can_enter, can_exit = limit_up_down(dv)

    # --------------------------------------------------------------------------------
    # Step.3 get signal, benchmark and price data
    dv.add_formula('divert',
                   '- Correlation(vwap_adj, volume, 10)',
                   is_quarterly=False,
                   add_data=True)

    signal = dv.get_ts('divert')
    price = dv.get_ts('close_adj')
    price_bench = dv.data_benchmark

    # Step.4 analyze!
    my_period = 5
    obj = SignalDigger(output_folder='../output/test_signal',
                       output_format='pdf')
    obj.process_signal_before_analysis(
        signal=signal,
        price=price,
        high=dv.get_ts("high_adj"),  # 可为空
        low=dv.get_ts("low_adj"),  # 可为空
        group=dv.get_ts("sw1"),
        n_quantiles=5,  # quantile分类数
        mask=mask,  # 过滤条件
        can_enter=can_enter,  # 是否能进场
        can_exit=can_exit,  # 是否能出场
        period=my_period,  # 持有期
        benchmark_price=price_bench,  # 基准价格 可不传入,持有期收益(return)计算为绝对收益
        commission=0.0008,
    )
    signal_data = obj.signal_data
    result = analysis(signal_data, is_event=False, period=my_period)
    ic = pfm.calc_signal_ic(signal_data, by_group=True)
    mean_ic_by_group = pfm.mean_information_coefficient(ic, by_group=True)
    plotting.plot_ic_by_group(mean_ic_by_group)
    res = obj.create_full_report()
Пример #5
0
def analyze_signal(dv, signal_name, output_format='pdf'):
    # Step.2 calculate mask (to mask those ill data points)
    mask_sus = dv.get_ts('suspended')
    mask_index_member = dv.get_ts('not_index_member')
    mask_limit_reached = dv.get_ts('limit_reached')
    mask_all = np.logical_or(mask_sus, np.logical_or(mask_index_member, mask_limit_reached))

    signal = dv.get_ts(signal_name).shift(1, axis=0)  # avoid look-ahead bias
    price = dv.get_ts('close_adj')
    price_bench = dv.data_benchmark

    # Step.4 analyze!
    my_period = 5
    obj = SignalDigger(output_folder='../../output/test_signal',
                       output_format=output_format)
    obj.process_signal_before_analysis(signal, price=price,
                                       mask=mask_all,
                                       n_quantiles=5, period=my_period,
                                       benchmark_price=price_bench,
                                       )
    res = obj.create_full_report()
Пример #6
0
def test_analyze_signal():
    # --------------------------------------------------------------------------------
    # Step.1 load dataview
    dv = DataView()
    dv.load_dataview(dataview_folder)

    # --------------------------------------------------------------------------------
    # Step.2 calculate mask (to mask those ill data points)
    trade_status = dv.get_ts('trade_status')
    mask_sus = trade_status == u'停牌'

    df_index_member = dv.get_ts('index_member')
    mask_index_member = ~(df_index_member > 0)

    dv.add_formula('limit_reached', 'Abs((open - Delay(close, 1)) / Delay(close, 1)) > 0.095', is_quarterly=False)
    df_limit_reached = dv.get_ts('limit_reached')
    mask_limit_reached = df_limit_reached > 0

    mask_all = np.logical_or(mask_sus, np.logical_or(mask_index_member, mask_limit_reached))

    # --------------------------------------------------------------------------------
    # Step.3 get signal, benchmark and price data
    dv.add_formula('divert', '- Correlation(vwap_adj, volume, 10)', is_quarterly=False)
    
    signal = dv.get_ts('divert').shift(1, axis=0)  # avoid look-ahead bias
    price = dv.get_ts('close_adj')
    price_bench = dv.data_benchmark

    # Step.4 analyze!
    my_period = 5
    obj = SignalDigger(output_folder='../output/test_signal', output_format='pdf')
    obj.process_signal_before_analysis(signal, price=price,
                                       mask=mask_all,
                                       n_quantiles=5, period=my_period,
                                       benchmark_price=price_bench,
                                       )
    res = obj.create_full_report()