克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-322:features","from_node_id":"-331:data"},{"to_node_id":"-322:instruments","from_node_id":"-312:data"},{"to_node_id":"-322:user_functions","from_node_id":"-584:functions"}],"nodes":[{"node_id":"-331","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"_c = close.loc[93100:145600]\n_o = open.loc[93100:145600]\n_v = volume.loc[93100:145600]\n_c1 = _c.iloc[0::10]\n_v1 = _v.cumsum().iloc[0::10]\n_o1 = _o.iloc[0::10]\n_ret = ret_sim(_c, _o) + 1\n_ret1 = ret_sim(_c1, _o1) + 1\n\n# 改进反转因子(1分钟)\n_w1 = _v / _v.sum()\nRev_vol_1m = (_w1.mul(np.log(_ret))).sum()\n\n\n# 改进反转因子(10分钟)\n_w2 = _v1 / _v1.sum()\nRev_vol_10m = (_w2.mul(np.log(_ret1))).sum()","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":"2014-03-03","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-12-31","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000001.SZA\n000002.SZA\n000005.SZA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"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":"-322","module_id":"BigQuantSpace.feature_extractor_1m.feature_extractor_1m-v1","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":2,"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":"-322"},{"name":"features","node_id":"-322"},{"name":"user_functions","node_id":"-322"}],"output_ports":[{"name":"data","node_id":"-322"}],"cacheable":false,"seq_num":3,"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":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-331' Position='-136,-245,200,200'/><node_position Node='-312' Position='-431.43505859375,-242,200,200'/><node_position Node='-322' Position='-133,-19,200,200'/><node_position Node='-584' Position='181,-246,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [1]:
    # 本代码由可视化策略环境自动生成 2021年7月9日15:19
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def m4_func_bigquant_run(df, close, op):
        res = close.pct_change()
        res.iloc[0] = close.iloc[0] / op.iloc[0] - 1
        return res
    
    
    m1 = M.input_features.v1(
        features="""_c = close.loc[93100:145600]
    _o = open.loc[93100:145600]
    _v = volume.loc[93100:145600]
    _c1 = _c.iloc[0::10]
    _v1 = _v.cumsum().iloc[0::10]
    _o1 = _o.iloc[0::10]
    _ret = ret_sim(_c, _o) + 1
    _ret1 = ret_sim(_c1, _o1) + 1
    
    # 改进反转因子(1分钟)
    _w1 = _v / _v.sum()
    Rev_vol_1m = (_w1.mul(np.log(_ret))).sum()
    
    
    # 改进反转因子(10分钟)
    _w2 = _v1 / _v1.sum()
    Rev_vol_10m = (_w2.mul(np.log(_ret1))).sum()"""
    )
    
    m2 = M.instruments.v2(
        start_date='2014-03-03',
        end_date='2021-12-31',
        market='CN_STOCK_A',
        instrument_list="""000001.SZA
    000002.SZA
    000005.SZA""",
        max_count=0
    )
    
    m4 = M.feature_extractor_user_function.v1(
        name='ret_sim',
        func=m4_func_bigquant_run
    )
    
    m3 = M.feature_extractor_1m.v1(
        instruments=m2.data,
        features=m1.data,
        user_functions=m4.functions,
        start_date='',
        end_date='',
        before_start_days=20,
        workers=2,
        parallel_mode='测试',
        table_1m='level2_bar1m_CN_STOCK_A',
        m_cached=False
    )
    
    In [2]:
    dt = m3.data.read()
    dt.shape, dt.date.min(), dt.date.max()
    
    Out[2]:
    ((729, 4), Timestamp('2020-01-02 00:00:00'), Timestamp('2020-12-31 00:00:00'))
    In [3]:
    dt.head().T
    
    Out[3]:
    0 1 2 3 4
    Rev_vol_1m 0.000453 0.000399 -0.000064 0.000609 -0.000252
    Rev_vol_10m 0.000293 -0.000871 0.00009 0.000122 -0.000043
    date 2020-01-02 00:00:00 2020-01-02 00:00:00 2020-01-02 00:00:00 2020-01-03 00:00:00 2020-01-03 00:00:00
    instrument 000001.SZA 000002.SZA 000005.SZA 000001.SZA 000002.SZA
    In [4]:
    dt.isna().sum()
    
    Out[4]:
    Rev_vol_1m     0
    Rev_vol_10m    0
    date           0
    instrument     0
    dtype: int64
    In [5]:
    dt.describe().T
    
    Out[5]:
    count mean std min 25% 50% 75% max
    Rev_vol_1m 729.0 8.565600e-05 0.000736 -0.002864 -0.000248 0.000008 0.000288 0.00833
    Rev_vol_10m 729.0 -5.184620e-07 0.000599 -0.003332 -0.000325 -0.000021 0.000283 0.00297
    In [6]:
    dt2 = dt.set_index(['date','instrument'])
    dt2.head()
    
    Out[6]:
    Rev_vol_1m Rev_vol_10m
    date instrument
    2020-01-02 000001.SZA 0.000453 0.000293
    000002.SZA 0.000399 -0.000871
    000005.SZA -0.000064 0.000090
    2020-01-03 000001.SZA 0.000609 0.000122
    000002.SZA -0.000252 -0.000043
    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)
    
    In [9]:
    # for i in dt2.columns[:]:
    #     dt2[i].to_hdf(f'XX券商-XXXX研报-{i}.h5', 'fac', mode='w')
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]: