复制链接
克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-1763:features","from_node_id":"-331:data"},{"to_node_id":"-2294:instruments","from_node_id":"-312:data"},{"to_node_id":"-1763:instruments","from_node_id":"-312:data"},{"to_node_id":"-7278:input_1","from_node_id":"-1136:data"},{"to_node_id":"-1136:features","from_node_id":"-2149:data"},{"to_node_id":"-1763:user_functions","from_node_id":"-2016:functions"},{"to_node_id":"-2016:input_functions","from_node_id":"-584:functions"},{"to_node_id":"-2294:features","from_node_id":"-2300:data"},{"to_node_id":"-2305:data1","from_node_id":"-2294:data"},{"to_node_id":"-1136:input_data","from_node_id":"-2305:data"},{"to_node_id":"-2305:data2","from_node_id":"-1763:data"}],"nodes":[{"node_id":"-331","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"_v = volume\n_amt = amount\n_num_trd = num_trades\n_c = close\n_h = high\n_l = low\n_o = open\n_tbv = total_bid_volume\n_ret = ret_sim(_c, _o)\n\n# # 高频偏度\n# _RVar = RVar(_ret)\n# RSkew = RSkew(_ret, _RVar)\n\n# 平均单笔成交金额\nAmtPerTrd = where(_num_trd.sum()==0, 1, _amt.sum() / _num_trd.sum())\n\n# 平均单笔流入金额\nAmtPerTrd_InFlow = where((_num_trd*where(_ret>0,1,0)).sum()==0, 1, (_amt*where(_ret>0,1,0)).sum() / (_num_trd*where(_ret>0,1,0)).sum())\n\n# 平均单笔流出金额\nAmtPerTrd_OutFlow = where((_num_trd*where(_ret<0,1,0)).sum()==0, 1, (_amt*where(_ret<0,1,0)).sum() / (_num_trd*where(_ret<0,1,0)).sum())\n\n# 平均单笔流入金额占比\nAmtPerTrd_InFlow_ratio = where(AmtPerTrd==0, 1, AmtPerTrd_InFlow / AmtPerTrd)\n\n# 平均单笔流出金额占比\nAmtPerTrd_OutFlow_ratio = where(AmtPerTrd_OutFlow==0, 1, AmtPerTrd_InFlow / AmtPerTrd_OutFlow)\n\n# 大单资金净流入金额\t\n_AmtPerTrd_avg = _amt.div(_num_trd)\n_anb_1 = where(_AmtPerTrd_avg >= _AmtPerTrd_avg.sort_values(ascending=False).iloc[np.int(240*0.1-1)], _amt*where(_ret>0,1,0), 0).sum()\n_anb_2 = where(_AmtPerTrd_avg >= _AmtPerTrd_avg.sort_values(ascending=False).iloc[np.int(240*0.1-1)], _amt*where(_ret<0,1,0), 0).sum()\nApt_NetinFlow_bigorder = _anb_1 - _anb_2\n\n# 大单资金净流入率\nApt_NetinFlow_bigorder_ratio = where(_amt.sum()==0, 1, Apt_NetinFlow_bigorder / (_amt.sum()))\n\n# 大单驱动涨幅(前10%)\nmom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.1-1)], 1, 0))\n# 大单驱动涨幅(前20%)\nmom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.2-1)], 1, 0))\n# 大单驱动涨幅(前30%)\nmom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.3-1)], 1, 0))\n\n# 趋势强度\n_diff_close = _c.diff().fillna(0).iloc[1:].abs().sum()\ntrend_strength = where(_diff_close==0, 1, _c.iloc[-1] - _c.iloc[0] / _diff_close)\n\n# 日内时点涨幅\ntime_incre_1 = _c.loc[93500] / _c.loc[93100]\ntime_incre_2 = _c.loc[150000] / _c.loc[145100]\ntime_incre_3 = _c.loc[140000] / _c.loc[133100]\n\n# 委买变化量\n_bid_vol_chg = bid_volume1.pct_change().fillna(0)+bid_volume2.pct_change().fillna(0)+bid_volume3.pct_change().fillna(0)+bid_volume4.pct_change().fillna(0)+bid_volume5.pct_change().fillna(0)+bid_volume6.pct_change().fillna(0)+bid_volume7.pct_change().fillna(0)+bid_volume8.pct_change().fillna(0)+bid_volume9.pct_change().fillna(0)+bid_volume10.pct_change().fillna(0)\n# 委卖变化量\n_ask_vol_chg = ask_volume1.pct_change().fillna(0)+ask_volume2.pct_change().fillna(0)+ask_volume3.pct_change().fillna(0)+ask_volume4.pct_change().fillna(0)+ask_volume5.pct_change().fillna(0)+ask_volume6.pct_change().fillna(0)+ask_volume7.pct_change().fillna(0)+ask_volume8.pct_change().fillna(0)+ask_volume9.pct_change().fillna(0)+ask_volume10.pct_change().fillna(0)\n# 净委买变化量 \nnet_bid_vol_chg = _c.mul(_bid_vol_chg.sub(_ask_vol_chg).fillna(0))\n\n# 均价偏差(二次抽取)\nvolu = _v.sum()\nvwap = (_c*_v).sum() / _v.sum()\nvolu_vwap = volu * vwap\n\n# 时间加权平均的相对价格位置(二次抽取)\nhigh1 = _h.max()\nlow1 = _l.min()\ntwap = ((_c.add(_h).add(_l).add(_o)) / 4).mean()\nARPP = get_ARPP(twap, high1, low1)\n\n# 聪明钱因子lnV\n_s1 = (_ret.abs().div(np.log(_v))).sort_values(ascending=False)\n_v1 = _v[_s1.index]\n_c1 = _c[_s1.index]\n_sm1 = ((_v1.cumsum() / _v.sum()) >= 0.2)\nsmart_money1 = ((_v1[_sm1]*_c1[_sm1]).sum() / (_v1[_sm1].sum())) / ((_v*_c).sum() / (_v.sum()))\n\n# 聪明钱因子V\n_s2 = _v.sort_values(ascending=False)\n_v2 = _v[_s2.index]\n_c2 = _c[_s2.index]\n_sm2 = ((_v2.cumsum() / _v.sum()) >= 0.2)\nsmart_money2 = ((_v2[_sm2]*_c2[_sm2]).sum() / (_v2[_sm2].sum())) / ((_v*_c).sum() / (_v.sum()))\n\n# 聪明钱因子rank\n_s3 = (_ret.abs().rank().add(_v.rank())).sort_values(ascending=False)\n_v3 = _v[_s3.index]\n_c3 = _c[_s3.index]\n_sm3 = ((_v3.cumsum() / _v.sum()) >= 0.2)\nsmart_money3 = ((_v3[_sm3]*_c3[_sm3]).sum() / (_v3[_sm3].sum())) / ((_v*_c).sum() / (_v.sum()))\n\n# 18 聪明钱因子rank\n_s4 = (_ret.abs().rank().add(_v.rank())).sort_values(ascending=False)\n_v4 = _v[_s4.index]\n_c4 = _c[_s4.index]\n_sm4 = ((_v4.cumsum() / _v.sum()) >= 0.2)\nsmart_money4 = ((_v4[_sm4]*_c4[_sm4]).sum() / (_v4[_sm4].sum())) / ((_v*_c).sum() / (_v.sum()))\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-331"}],"output_ports":[{"name":"data","node_id":"-331"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-312","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2016-01-03","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2016-12-31","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":" ","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"100","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-312"}],"output_ports":[{"name":"data","node_id":"-312"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-1136","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"def myf_(df, s1, s2):\n x = s1 / s2\n for i in range(x.shape[0]):\n x[i][np.isinf(x[i])] = 0\n return x.apply(lambda x: x.mean(skipna=True)), x.apply(lambda x:x.std(skipna=True)), x.apply(lambda x:x.skew(skipna=True))\n \ndef nanprod(df, x_name, N):\n return df.groupby('instrument')[x_name.name].apply(lambda x: x.rolling(N,1).apply(np.prod))\n\nbigquant_run = {\n 'myf_':myf_,\n 'nanprod':nanprod\n}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-1136"},{"name":"features","node_id":"-1136"}],"output_ports":[{"name":"data","node_id":"-1136"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-2149","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"APB = np.log(nanmean(vwap, 5) / (nansum(volu_vwap, 5) / nansum(volu, 5)))\n\n# ARPP = (twap - high1) / (high1 - low1)\n\n\n# 过去10个日内累计时点涨幅(%)\ntime_zf1 = nanprod(time_incre_1, 10) - 1 \n\n# 过去10个日内累计时点涨幅(%)\ntime_zf2 = nanprod(time_incre_2, 10) - 1 \n\n# 过去10个日内累计时点涨幅(%)\ntime_zf3 = nanprod(time_incre_3, 10) - 1\n\n# 净委买变化率均值\nnet_bid_vol_chg_mean = myf_(net_bid_vol_chg ,market_cap_float_0)[0]\n# 净委买变化率标准差\nnet_bid_vol_chg_std = myf_(net_bid_vol_chg ,market_cap_float_0)[1]\n# 净委买变化率偏度\nnet_bid_vol_chg_skew = myf_(net_bid_vol_chg ,market_cap_float_0)[2]\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2149"}],"output_ports":[{"name":"data","node_id":"-2149"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-2016","module_id":"BigQuantSpace.feature_extractor_user_function.feature_extractor_user_function-v1","parameters":[{"name":"name","value":"get_ARPP","type":"Literal","bound_global_parameter":null},{"name":"func","value":"def bigquant_run(df, twap, high, low):\n if high == low:\n result = 0\n else:\n result = (twap - high) / (high - low)\n \n return result\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_functions","node_id":"-2016"}],"output_ports":[{"name":"functions","node_id":"-2016"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-584","module_id":"BigQuantSpace.feature_extractor_user_function.feature_extractor_user_function-v1","parameters":[{"name":"name","value":"ret_sim","type":"Literal","bound_global_parameter":null},{"name":"func","value":"def bigquant_run(df, close, op):\n res = close.pct_change()\n res.iloc[0] = close.iloc[0] / op.iloc[0] - 1\n return res\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_functions","node_id":"-584"}],"output_ports":[{"name":"functions","node_id":"-584"}],"cacheable":false,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-2300","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"market_cap_float_0\n ","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2300"}],"output_ports":[{"name":"data","node_id":"-2300"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-2294","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-2294"},{"name":"features","node_id":"-2294"}],"output_ports":[{"name":"data","node_id":"-2294"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-2305","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"inner","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-2305"},{"name":"data2","node_id":"-2305"}],"output_ports":[{"name":"data","node_id":"-2305"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-1763","module_id":"BigQuantSpace.feature_extractor_1m.feature_extractor_1m-v2","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"20","type":"Literal","bound_global_parameter":null},{"name":"workers","value":"10","type":"Literal","bound_global_parameter":null},{"name":"parallel_mode","value":"集群","type":"Literal","bound_global_parameter":null},{"name":"table_1m","value":"level2_bar1m_CN_STOCK_A","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-1763"},{"name":"features","node_id":"-1763"},{"name":"user_functions","node_id":"-1763"}],"output_ports":[{"name":"data","node_id":"-1763"}],"cacheable":true,"seq_num":13,"comment":"","comment_collapsed":true},{"node_id":"-7278","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read()\n df = df.drop(['net_bid_vol_chg'], axis=1)\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-7278"},{"name":"input_2","node_id":"-7278"},{"name":"input_3","node_id":"-7278"}],"output_ports":[{"name":"data_1","node_id":"-7278"},{"name":"data_2","node_id":"-7278"},{"name":"data_3","node_id":"-7278"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-331' Position='-124,-238,200,200'/><node_position Node='-312' Position='-363,-330,200,200'/><node_position Node='-1136' Position='-88,116,200,200'/><node_position Node='-2149' Position='61,11,200,200'/><node_position Node='-2016' Position='197,-357,200,200'/><node_position Node='-584' Position='195,-446,200,200'/><node_position Node='-2300' Position='-604,-237,200,200'/><node_position Node='-2294' Position='-545,-109,200,200'/><node_position Node='-2305' Position='-231,11,200,200'/><node_position Node='-1763' Position='-200,-108,200,200'/><node_position Node='-7278' Position='-83.97623443603516,202,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [1]:
    # 本代码由可视化策略环境自动生成 2022年7月1日 21:24
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def m9_func_bigquant_run(df, close, op):
        res = close.pct_change()
        res.iloc[0] = close.iloc[0] / op.iloc[0] - 1
        return res
    
    def m4_func_bigquant_run(df, twap, high, low):
        if high == low:
            result = 0
        else:
            result = (twap - high) / (high - low)
        
        return result
    
    def myf_(df, s1, s2):
        x =  s1 / s2
        for i in range(x.shape[0]):
            x[i][np.isinf(x[i])] = 0
        return x.apply(lambda x: x.mean(skipna=True)), x.apply(lambda x:x.std(skipna=True)), x.apply(lambda x:x.skew(skipna=True))
     
    def nanprod(df, x_name, N):
        return df.groupby('instrument')[x_name.name].apply(lambda x: x.rolling(N,1).apply(np.prod))
    
    m7_user_functions_bigquant_run = {
        'myf_':myf_,
        'nanprod':nanprod
    }
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m3_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read()
        df = df.drop(['net_bid_vol_chg'], axis=1)
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m3_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.input_features.v1(
        features="""_v = volume
    _amt = amount
    _num_trd = num_trades
    _c = close
    _h = high
    _l = low
    _o = open
    _tbv = total_bid_volume
    _ret = ret_sim(_c, _o)
    
    # # 高频偏度
    # _RVar = RVar(_ret)
    # RSkew = RSkew(_ret, _RVar)
    
    # 平均单笔成交金额
    AmtPerTrd = where(_num_trd.sum()==0, 1, _amt.sum() / _num_trd.sum())
    
    # 平均单笔流入金额
    AmtPerTrd_InFlow = where((_num_trd*where(_ret>0,1,0)).sum()==0, 1, (_amt*where(_ret>0,1,0)).sum() / (_num_trd*where(_ret>0,1,0)).sum())
    
    # 平均单笔流出金额
    AmtPerTrd_OutFlow = where((_num_trd*where(_ret<0,1,0)).sum()==0, 1, (_amt*where(_ret<0,1,0)).sum() / (_num_trd*where(_ret<0,1,0)).sum())
    
    # 平均单笔流入金额占比
    AmtPerTrd_InFlow_ratio = where(AmtPerTrd==0, 1, AmtPerTrd_InFlow / AmtPerTrd)
    
    # 平均单笔流出金额占比
    AmtPerTrd_OutFlow_ratio = where(AmtPerTrd_OutFlow==0, 1, AmtPerTrd_InFlow / AmtPerTrd_OutFlow)
    
    # 大单资金净流入金额	
    _AmtPerTrd_avg = _amt.div(_num_trd)
    _anb_1 = where(_AmtPerTrd_avg >= _AmtPerTrd_avg.sort_values(ascending=False).iloc[np.int(240*0.1-1)], _amt*where(_ret>0,1,0), 0).sum()
    _anb_2 = where(_AmtPerTrd_avg >= _AmtPerTrd_avg.sort_values(ascending=False).iloc[np.int(240*0.1-1)], _amt*where(_ret<0,1,0), 0).sum()
    Apt_NetinFlow_bigorder = _anb_1 - _anb_2
    
    # 大单资金净流入率
    Apt_NetinFlow_bigorder_ratio = where(_amt.sum()==0, 1, Apt_NetinFlow_bigorder / (_amt.sum()))
    
    # 大单驱动涨幅(前10%)
    mom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.1-1)], 1, 0))
    # 大单驱动涨幅(前20%)
    mom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.2-1)], 1, 0))
    # 大单驱动涨幅(前30%)
    mom_bigorder = np.prod(1 + _ret*where(_amt >= _amt.sort_values(ascending=False).iloc[np.int(240*0.3-1)], 1, 0))
    
    # 趋势强度
    _diff_close = _c.diff().fillna(0).iloc[1:].abs().sum()
    trend_strength = where(_diff_close==0, 1, _c.iloc[-1] - _c.iloc[0] / _diff_close)
    
    # 日内时点涨幅
    time_incre_1 = _c.loc[93500] / _c.loc[93100]
    time_incre_2 = _c.loc[150000] / _c.loc[145100]
    time_incre_3 = _c.loc[140000] / _c.loc[133100]
    
    # 委买变化量
    _bid_vol_chg = bid_volume1.pct_change().fillna(0)+bid_volume2.pct_change().fillna(0)+bid_volume3.pct_change().fillna(0)+bid_volume4.pct_change().fillna(0)+bid_volume5.pct_change().fillna(0)+bid_volume6.pct_change().fillna(0)+bid_volume7.pct_change().fillna(0)+bid_volume8.pct_change().fillna(0)+bid_volume9.pct_change().fillna(0)+bid_volume10.pct_change().fillna(0)
    # 委卖变化量
    _ask_vol_chg = ask_volume1.pct_change().fillna(0)+ask_volume2.pct_change().fillna(0)+ask_volume3.pct_change().fillna(0)+ask_volume4.pct_change().fillna(0)+ask_volume5.pct_change().fillna(0)+ask_volume6.pct_change().fillna(0)+ask_volume7.pct_change().fillna(0)+ask_volume8.pct_change().fillna(0)+ask_volume9.pct_change().fillna(0)+ask_volume10.pct_change().fillna(0)
    # 净委买变化量 
    net_bid_vol_chg = _c.mul(_bid_vol_chg.sub(_ask_vol_chg).fillna(0))
    
    # 均价偏差(二次抽取)
    volu = _v.sum()
    vwap = (_c*_v).sum() / _v.sum()
    volu_vwap = volu * vwap
    
    # 时间加权平均的相对价格位置(二次抽取)
    high1 = _h.max()
    low1 = _l.min()
    twap = ((_c.add(_h).add(_l).add(_o)) / 4).mean()
    ARPP = get_ARPP(twap, high1, low1)
    
    # 聪明钱因子lnV
    _s1 = (_ret.abs().div(np.log(_v))).sort_values(ascending=False)
    _v1 = _v[_s1.index]
    _c1 = _c[_s1.index]
    _sm1 = ((_v1.cumsum() / _v.sum()) >= 0.2)
    smart_money1 = ((_v1[_sm1]*_c1[_sm1]).sum() / (_v1[_sm1].sum())) / ((_v*_c).sum() / (_v.sum()))
    
    # 聪明钱因子V
    _s2 = _v.sort_values(ascending=False)
    _v2 = _v[_s2.index]
    _c2 = _c[_s2.index]
    _sm2 = ((_v2.cumsum() / _v.sum()) >= 0.2)
    smart_money2 = ((_v2[_sm2]*_c2[_sm2]).sum() / (_v2[_sm2].sum())) / ((_v*_c).sum() / (_v.sum()))
    
    # 聪明钱因子rank
    _s3 = (_ret.abs().rank().add(_v.rank())).sort_values(ascending=False)
    _v3 = _v[_s3.index]
    _c3 = _c[_s3.index]
    _sm3 = ((_v3.cumsum() / _v.sum()) >= 0.2)
    smart_money3 = ((_v3[_sm3]*_c3[_sm3]).sum() / (_v3[_sm3].sum())) / ((_v*_c).sum() / (_v.sum()))
    
    # 18 聪明钱因子rank
    _s4 = (_ret.abs().rank().add(_v.rank())).sort_values(ascending=False)
    _v4 = _v[_s4.index]
    _c4 = _c[_s4.index]
    _sm4 = ((_v4.cumsum() / _v.sum()) >= 0.2)
    smart_money4 = ((_v4[_sm4]*_c4[_sm4]).sum() / (_v4[_sm4].sum())) / ((_v*_c).sum() / (_v.sum()))
    """
    )
    
    m2 = M.instruments.v2(
        start_date='2016-01-03',
        end_date='2016-12-31',
        market='CN_STOCK_A',
        instrument_list=' ',
        max_count=100
    )
    
    m8 = M.input_features.v1(
        features="""APB = np.log(nanmean(vwap, 5) / (nansum(volu_vwap, 5) / nansum(volu, 5)))
    
    # ARPP = (twap - high1) / (high1 - low1)
    
    
    # 过去10个日内累计时点涨幅(%)
    time_zf1 = nanprod(time_incre_1, 10) - 1 
    
    # 过去10个日内累计时点涨幅(%)
    time_zf2 = nanprod(time_incre_2, 10) - 1 
    
    # 过去10个日内累计时点涨幅(%)
    time_zf3 = nanprod(time_incre_3, 10) - 1
    
    # 净委买变化率均值
    net_bid_vol_chg_mean = myf_(net_bid_vol_chg ,market_cap_float_0)[0]
    # 净委买变化率标准差
    net_bid_vol_chg_std = myf_(net_bid_vol_chg ,market_cap_float_0)[1]
    # 净委买变化率偏度
    net_bid_vol_chg_skew = myf_(net_bid_vol_chg ,market_cap_float_0)[2]
    """
    )
    
    m9 = M.feature_extractor_user_function.v1(
        name='ret_sim',
        func=m9_func_bigquant_run
    )
    
    m4 = M.feature_extractor_user_function.v1(
        input_functions=m9.functions,
        name='get_ARPP',
        func=m4_func_bigquant_run
    )
    
    m13 = M.feature_extractor_1m.v2(
        instruments=m2.data,
        features=m1.data,
        user_functions=m4.functions,
        start_date='',
        end_date='',
        before_start_days=20,
        workers=10,
        parallel_mode='集群',
        table_1m='level2_bar1m_CN_STOCK_A'
    )
    
    m10 = M.input_features.v1(
        features="""market_cap_float_0
     """
    )
    
    m11 = M.general_feature_extractor.v7(
        instruments=m2.data,
        features=m10.data,
        start_date='',
        end_date='',
        before_start_days=20
    )
    
    m12 = M.join.v3(
        data1=m11.data,
        data2=m13.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m12.data,
        features=m8.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions=m7_user_functions_bigquant_run
    )
    
    m3 = M.cached.v3(
        input_1=m7.data,
        run=m3_run_bigquant_run,
        post_run=m3_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    In [2]:
    dt = m3.data_1.read()
    dt.shape, dt.date.min(), dt.date.max()
    
    Out[2]:
    ((22738, 33),
     Timestamp('2015-12-14 00:00:00'),
     Timestamp('2016-12-30 00:00:00'))
    In [3]:
    dt.head().T
    
    Out[3]:
    0 1 2 3 4
    date 2015-12-14 00:00:00 2015-12-15 00:00:00 2015-12-16 00:00:00 2015-12-17 00:00:00 2015-12-18 00:00:00
    instrument 000001.SZA 000001.SZA 000001.SZA 000001.SZA 000001.SZA
    market_cap_float_0 142474936320.0 140704333824.0 140350210048.0 142474936320.0 144363585536.0
    AmtPerTrd 32269.765204 28602.394151 33570.530347 32862.838678 29993.821317
    AmtPerTrd_InFlow 30598.153644 31330.597744 34903.597824 34198.441265 30746.696883
    AmtPerTrd_OutFlow 34004.608812 26585.625717 34148.809035 32683.290638 29519.531246
    AmtPerTrd_InFlow_ratio 0.948199 1.095384 1.039709 1.040642 1.025101
    AmtPerTrd_OutFlow_ratio 0.899824 1.178479 1.022103 1.046359 1.041571
    Apt_NetinFlow_bigorder -878660.91 25070892.82 -20895462.87 14169592.77 84003608.74
    Apt_NetinFlow_bigorder_ratio -0.001269 0.057796 -0.044957 0.018407 0.06747
    mom_bigorder 1.020321 0.994986 0.997498 1.014206 1.0409
    trend_strength 7.246961 5.750829 3.614094 4.880348 7.680387
    time_incre_1 1.005119 1.0 0.999167 0.998332 1.001662
    time_incre_2 0.999172 0.998325 1.0 1.00083 0.998366
    time_incre_3 1.008467 0.994162 1.000839 0.996689 1.004075
    volu 58189764 36216035 38962887 63906790 101287374
    vwap 11.898612 11.978948 11.9305 12.045732 12.294527
    volu_vwap 692377425.511013 433829986.974044 464846724.542553 769804036.210394 1245280359.854702
    high1 12.11 12.09 12.01 12.14 12.53
    low1 11.72 11.87 11.88 11.96 12.02
    twap 11.852208 11.980166 11.926948 12.049687 12.252114
    ARPP -0.661005 -0.499244 -0.638866 -0.501738 -0.544874
    smart_money1 1.000408 0.999709 0.999903 1.000036 0.998343
    smart_money2 0.997407 1.000182 0.999879 0.999918 0.997188
    smart_money3 0.998913 1.000376 1.000165 1.000459 0.998495
    smart_money4 0.998913 1.000376 1.000165 1.000459 0.998495
    APB 0.0 0.000783 0.000526 -0.000323 -0.004037
    time_zf1 0.005119 0.005119 0.004282 0.002607 0.004273
    time_zf2 -0.000828 -0.002501 -0.002501 -0.001674 -0.003305
    time_zf3 0.008467 0.00258 0.003421 0.000098 0.004174
    net_bid_vol_chg_mean -0.0 0.0 0.0 -0.0 -0.0
    net_bid_vol_chg_std 0.0 0.0 0.0 0.0 0.0
    net_bid_vol_chg_skew 0.0 0.0 0.0 0.0 0.0
    In [4]:
    dt.isna().sum()
    
    Out[4]:
    date                            0
    instrument                      0
    market_cap_float_0              0
    AmtPerTrd                       0
    AmtPerTrd_InFlow                0
    AmtPerTrd_OutFlow               0
    AmtPerTrd_InFlow_ratio          0
    AmtPerTrd_OutFlow_ratio         0
    Apt_NetinFlow_bigorder          0
    Apt_NetinFlow_bigorder_ratio    0
    mom_bigorder                    0
    trend_strength                  0
    time_incre_1                    0
    time_incre_2                    0
    time_incre_3                    0
    volu                            0
    vwap                            0
    volu_vwap                       0
    high1                           0
    low1                            0
    twap                            0
    ARPP                            0
    smart_money1                    0
    smart_money2                    0
    smart_money3                    0
    smart_money4                    0
    APB                             0
    time_zf1                        0
    time_zf2                        0
    time_zf3                        0
    net_bid_vol_chg_mean            0
    net_bid_vol_chg_std             0
    net_bid_vol_chg_skew            0
    dtype: int64
    In [5]:
    dt.describe().T
    
    Out[5]:
    count mean std min 25% 50% 75% max
    market_cap_float_0 22738.0 1.559707e+10 2.509632e+10 1.612660e+09 4.742342e+09 8.439603e+09 1.643007e+10 2.691087e+11
    AmtPerTrd 22738.0 1.996365e+04 6.855431e+03 5.476133e+03 1.549276e+04 1.862294e+04 2.294858e+04 2.696215e+05
    AmtPerTrd_InFlow 22738.0 2.036080e+04 6.890558e+03 1.000000e+00 1.578851e+04 1.904196e+04 2.350177e+04 1.422190e+05
    AmtPerTrd_OutFlow 22738.0 1.993035e+04 6.680130e+03 1.000000e+00 1.543178e+04 1.868872e+04 2.299972e+04 1.210167e+05
    AmtPerTrd_InFlow_ratio 22738.0 1.022920e+00 9.055563e-02 3.708903e-06 9.823536e-01 1.020436e+00 1.063444e+00 1.800144e+00
    AmtPerTrd_OutFlow_ratio 22738.0 1.871083e+01 1.130425e+03 1.226633e-05 9.528136e-01 1.020307e+00 1.093920e+00 1.422190e+05
    Apt_NetinFlow_bigorder 22738.0 1.551486e+06 3.599750e+07 -5.514014e+08 -3.823921e+06 0.000000e+00 4.351677e+06 3.372045e+09
    Apt_NetinFlow_bigorder_ratio 22738.0 8.162953e-04 5.961950e-02 -4.885676e-01 -3.280559e-02 0.000000e+00 3.370761e-02 8.228435e-01
    mom_bigorder 22738.0 9.977058e-01 3.343597e-02 7.872770e-01 9.815844e-01 9.979595e-01 1.013903e+00 1.482063e+00
    trend_strength 22738.0 1.149375e+01 1.230389e+01 -1.695102e+02 4.134229e+00 7.500741e+00 1.425474e+01 9.271024e+01
    time_incre_1 22738.0 1.000828e+00 7.336821e-03 9.052475e-01 9.973958e-01 1.000000e+00 1.003902e+00 1.068500e+00
    time_incre_2 22738.0 1.000308e+00 4.677055e-03 9.090689e-01 9.984834e-01 1.000000e+00 1.002097e+00 1.095210e+00
    time_incre_3 22738.0 1.000719e+00 9.237425e-03 9.088592e-01 9.969914e-01 1.000000e+00 1.003011e+00 1.111386e+00
    volu 22738.0 1.947976e+07 3.064466e+07 1.145000e+05 5.402651e+06 1.040477e+07 2.153692e+07 1.028373e+09
    vwap 22738.0 1.567714e+01 1.216341e+01 2.921698e+00 8.325346e+00 1.162215e+01 1.798836e+01 9.504253e+01
    volu_vwap 22738.0 2.427310e+08 4.537349e+08 1.188330e+06 7.058027e+07 1.283280e+08 2.554645e+08 2.016327e+10
    high1 22738.0 1.597646e+01 1.241767e+01 2.980000e+00 8.460000e+00 1.185000e+01 1.835750e+01 9.997000e+01
    low1 22738.0 1.536429e+01 1.191581e+01 2.760000e+00 8.160000e+00 1.137000e+01 1.755750e+01 9.145000e+01
    twap 22738.0 1.567412e+01 1.215906e+01 2.926188e+00 8.325172e+00 1.161276e+01 1.800777e+01 9.494520e+01
    ARPP 22738.0 -5.032135e-01 1.268777e-01 -9.980010e-01 -5.886783e-01 -5.076110e-01 -4.232636e-01 0.000000e+00
    smart_money1 22738.0 9.999325e-01 1.153336e-03 9.846634e-01 9.995589e-01 9.999536e-01 1.000308e+00 1.013068e+00
    smart_money2 22738.0 9.997642e-01 1.692821e-03 9.838965e-01 9.991511e-01 9.999050e-01 1.000424e+00 1.011161e+00
    smart_money3 22738.0 1.000031e+00 1.377272e-03 9.812760e-01 9.995771e-01 1.000100e+00 1.000548e+00 1.009949e+00
    smart_money4 22738.0 1.000031e+00 1.377272e-03 9.812760e-01 9.995771e-01 1.000100e+00 1.000548e+00 1.009949e+00
    APB 22738.0 -2.845119e-03 8.674931e-03 -1.215376e-01 -4.191197e-03 -1.493447e-03 -1.141935e-04 3.098126e-01
    time_zf1 22738.0 8.143376e-03 2.239322e-02 -1.623275e-01 -4.529496e-03 5.745685e-03 1.862840e-02 1.717678e-01
    time_zf2 22738.0 3.021891e-03 1.534915e-02 -1.053057e-01 -4.437065e-03 2.903333e-03 1.000558e-02 2.147084e-01
    time_zf3 22738.0 7.187239e-03 2.956758e-02 -1.327122e-01 -8.653244e-03 1.248507e-03 1.410481e-02 1.908171e-01
    net_bid_vol_chg_mean 22738.0 -1.316033e-09 1.262075e-07 -9.926806e-06 -7.578731e-09 7.098413e-10 1.039472e-08 2.917520e-06
    net_bid_vol_chg_std 22738.0 3.002074e-07 9.964944e-07 0.000000e+00 4.984577e-08 1.247956e-07 2.875142e-07 5.106818e-05
    net_bid_vol_chg_skew 22738.0 -4.563942e-02 1.836913e+00 -1.549080e+01 0.000000e+00 0.000000e+00 0.000000e+00 1.549170e+01
    In [6]:
    dt2 = dt.set_index(['date','instrument'])
    dt2.head()
    
    Out[6]:
    market_cap_float_0 AmtPerTrd AmtPerTrd_InFlow AmtPerTrd_OutFlow AmtPerTrd_InFlow_ratio AmtPerTrd_OutFlow_ratio Apt_NetinFlow_bigorder Apt_NetinFlow_bigorder_ratio mom_bigorder trend_strength ... smart_money2 smart_money3 smart_money4 APB time_zf1 time_zf2 time_zf3 net_bid_vol_chg_mean net_bid_vol_chg_std net_bid_vol_chg_skew
    date instrument
    2015-12-14 000001.SZA 1.424749e+11 32269.765204 30598.153644 34004.608812 0.948199 0.899824 -878660.91 -0.001269 1.020321 7.246961 ... 0.997407 0.998913 0.998913 0.000000 0.005119 -0.000828 0.008467 -2.002865e-09 2.649323e-08 0.0
    2015-12-15 000001.SZA 1.407043e+11 28602.394151 31330.597744 26585.625717 1.095384 1.178479 25070892.82 0.057796 0.994986 5.750829 ... 1.000182 1.000376 1.000376 0.000783 0.005119 -0.002501 0.002580 2.002255e-10 4.283766e-09 0.0
    2015-12-16 000001.SZA 1.403502e+11 33570.530347 34903.597824 34148.809035 1.039709 1.022103 -20895462.87 -0.044957 0.997498 3.614094 ... 0.999879 1.000165 1.000165 0.000526 0.004282 -0.002501 0.003421 5.291886e-10 3.839982e-09 0.0
    2015-12-17 000001.SZA 1.424749e+11 32862.838678 34198.441265 32683.290638 1.040642 1.046359 14169592.77 0.018407 1.014206 4.880348 ... 0.999918 1.000459 1.000459 -0.000323 0.002607 -0.001674 0.000098 -5.621170e-11 2.384332e-09 0.0
    2015-12-18 000001.SZA 1.443636e+11 29993.821317 30746.696883 29519.531246 1.025101 1.041571 84003608.74 0.067470 1.040900 7.680387 ... 0.997188 0.998495 0.998495 -0.004037 0.004273 -0.003305 0.004174 -1.427885e-09 1.722706e-08 0.0

    5 rows × 31 columns

    In [7]:
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    In [8]:
    # %%time
    n=4#行数
    m=dt2.shape[1]
    x=m%n
    fig,axes=plt.subplots(n,int((m - x + (n if x else x))/n),figsize=(20, 10))
    axes=axes.reshape((-1,))
    for i in range(dt2.shape[1]):    
        sns.distplot(dt2[dt2.columns[i]],ax=axes[i])
    plt.subplots_adjust(wspace =0.3, hspace =0.3)