克隆策略

    {"description":"实验创建于2018/6/27","graph":{"edges":[{"to_node_id":"-927:input_1","from_node_id":"-915:data"},{"to_node_id":"-949:input_1","from_node_id":"-927:data_1"},{"to_node_id":"-961:input_1","from_node_id":"-949:data_1"}],"nodes":[{"node_id":"-961","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 \n tmp01=input_1.read_pickle()\n \n ad = {\n \"instruments\":tmp01,\n \"start_date\":\"2021-11-16\",\n \"end_date\":T.live_run_param('trading_date', \"2021-11-16\")\n #\"end_date\":\"2021-08-04\"\n }\n \n print(444444444444)\n # 这一段代码,结合超参搜索就会爆出错误\n # ERROR: moduleinvoker: module name: cached, module version: v3, trackeback: AssertionError: daemonic processes are not allowed to have children_\n # 在勾选 不显示日志之后,才会出现\n DataSource('bar5m_CN_STOCK_A').read(tmp01 ,start_date='2021-11-05',end_date='2021-11-16',fields=['close','volume'])\n print(333333333333)\n \n data_1 = DataSource.write_pickle(ad)\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":"-961"},{"name":"input_2","node_id":"-961"},{"name":"input_3","node_id":"-961"}],"output_ports":[{"name":"data_1","node_id":"-961"},{"name":"data_2","node_id":"-961"},{"name":"data_3","node_id":"-961"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-7324","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"b","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-7324"}],"output_ports":[{"name":"data","node_id":"-7324"}],"cacheable":true,"seq_num":55,"comment":"","comment_collapsed":true},{"node_id":"-715","module_id":"BigQuantSpace.hyper_parameter_search.hyper_parameter_search-v1","parameters":[{"name":"param_grid_builder","value":"def bigquant_run():\n param_grid = {}\n\n param_grid['m30.features'] = [['a']]\n param_grid['m55.features'] = [['a'],['b']]\n \n \n return param_grid","type":"Literal","bound_global_parameter":null},{"name":"scoring","value":"def bigquant_run(result):\n score = result.get('m54').read_raw_perf()['algorithm_period_return'].dropna().tail(1)[0]\n return {'score':score}\n","type":"Literal","bound_global_parameter":null},{"name":"search_algorithm","value":"网格搜索","type":"Literal","bound_global_parameter":null},{"name":"search_iterations","value":"1","type":"Literal","bound_global_parameter":null},{"name":"random_state","value":"","type":"Literal","bound_global_parameter":null},{"name":"workers","value":"2","type":"Literal","bound_global_parameter":null},{"name":"worker_distributed_run","value":"False","type":"Literal","bound_global_parameter":null},{"name":"worker_silent","value":"True","type":"Literal","bound_global_parameter":null},{"name":"run_now","value":"True","type":"Literal","bound_global_parameter":null},{"name":"bq_graph","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"bq_graph_port","node_id":"-715"},{"name":"input_1","node_id":"-715"},{"name":"input_2","node_id":"-715"},{"name":"input_3","node_id":"-715"}],"output_ports":[{"name":"result","node_id":"-715"}],"cacheable":false,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-3292","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"a","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-3292"}],"output_ports":[{"name":"data","node_id":"-3292"}],"cacheable":true,"seq_num":30,"comment":"","comment_collapsed":true},{"node_id":"-915","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2017-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-08-17","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":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-915"}],"output_ports":[{"name":"data","node_id":"-915"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-927","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 tmp01=input_1.read_pickle()\n \n df = pd.DataFrame()\n \n # print(tmp01['instruments'])\n \n df['instrument'] = tmp01['instruments']\n df['date'] = datetime.datetime.strptime(tmp01['start_date'], '%Y-%m-%d')\n \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":"-927"},{"name":"input_2","node_id":"-927"},{"name":"input_3","node_id":"-927"}],"output_ports":[{"name":"data_1","node_id":"-927"},{"name":"data_2","node_id":"-927"},{"name":"data_3","node_id":"-927"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-949","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 = pd.DataFrame({'data': [1, 2, 3]})\n \n tmp02=input_1.read_df()\n \n ins = tmp02['instrument'].values.tolist()\n \n data_1 = DataSource.write_pickle(ins)\n \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":"-949"},{"name":"input_2","node_id":"-949"},{"name":"input_3","node_id":"-949"}],"output_ports":[{"name":"data_1","node_id":"-949"},{"name":"data_2","node_id":"-949"},{"name":"data_3","node_id":"-949"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-961' Position='1625.2354736328125,-551.9535827636719,200,200'/><node_position Node='-7324' Position='1649.1824951171875,51.960166931152344,200,200'/><node_position Node='-715' Position='1404.7735595703125,-257.01493072509766,200,200'/><node_position Node='-3292' Position='1634.1575927734375,-22.695732682943344,200,200'/><node_position Node='-915' Position='1563.8856201171875,-855.1177368164062,200,200'/><node_position Node='-927' Position='1661.1981201171875,-763.5481567382812,200,200'/><node_position Node='-949' Position='1655.4766845703125,-661.8018188476562,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [194]:
    # 本代码由可视化策略环境自动生成 2021年11月19日 16:55
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m3_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        tmp01=input_1.read_pickle()
        
        df = pd.DataFrame()
        
        # print(tmp01['instruments'])
        
        df['instrument'] = tmp01['instruments']
        df['date'] = datetime.datetime.strptime(tmp01['start_date'], '%Y-%m-%d')
        
        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
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m5_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
    #     df = pd.DataFrame({'data': [1, 2, 3]})
        
        tmp02=input_1.read_df()
        
        ins = tmp02['instrument'].values.tolist()
        
        data_1 = DataSource.write_pickle(ins)
        
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m5_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m6_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        
        tmp01=input_1.read_pickle()
        
        ad = {
        "instruments":tmp01,
        "start_date":"2021-11-16",
        "end_date":T.live_run_param('trading_date', "2021-11-16")
            #"end_date":"2021-08-04"
        }
        
        print(444444444444)
        # 这一段代码,结合超参搜索就会爆出错误
        # ERROR: moduleinvoker: module name: cached, module version: v3, trackeback: AssertionError: daemonic processes are not allowed to have children_
        # 在勾选 不显示日志之后,才会出现
        DataSource('bar5m_CN_STOCK_A').read(tmp01 ,start_date='2021-11-05',end_date='2021-11-16',fields=['close','volume'])
        print(333333333333)
        
        data_1 = DataSource.write_pickle(ad)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m6_post_run_bigquant_run(outputs):
        return outputs
    
    
    g = T.Graph({
    
        'm55': 'M.input_features.v1',
        'm55.features': 'b',
    
        'm30': 'M.input_features.v1',
        'm30.features': 'a',
    
        'm2': 'M.instruments.v2',
        'm2.start_date': '2017-01-01',
        'm2.end_date': '2021-08-17',
        'm2.market': 'CN_STOCK_A',
        'm2.instrument_list': '',
        'm2.max_count': 0,
    
        'm3': 'M.cached.v3',
        'm3.input_1': T.Graph.OutputPort('m2.data'),
        'm3.run': m3_run_bigquant_run,
        'm3.post_run': m3_post_run_bigquant_run,
        'm3.input_ports': '',
        'm3.params': '{}',
        'm3.output_ports': '',
    
        'm5': 'M.cached.v3',
        'm5.input_1': T.Graph.OutputPort('m3.data_1'),
        'm5.run': m5_run_bigquant_run,
        'm5.post_run': m5_post_run_bigquant_run,
        'm5.input_ports': '',
        'm5.params': '{}',
        'm5.output_ports': '',
    
        'm6': 'M.cached.v3',
        'm6.input_1': T.Graph.OutputPort('m5.data_1'),
        'm6.run': m6_run_bigquant_run,
        'm6.post_run': m6_post_run_bigquant_run,
        'm6.input_ports': '',
        'm6.params': '{}',
        'm6.output_ports': '',
    })
    
    # g.run({})
    
    
    def m18_param_grid_builder_bigquant_run():
        param_grid = {}
    
        param_grid['m30.features'] =  [['a']]
        param_grid['m55.features'] =  [['a'],['b']]
        
        
        return param_grid
    def m18_scoring_bigquant_run(result):
        score = result.get('m54').read_raw_perf()['algorithm_period_return'].dropna().tail(1)[0]
        return {'score':score}
    
    
    m18 = M.hyper_parameter_search.v1(
        param_grid_builder=m18_param_grid_builder_bigquant_run,
        scoring=m18_scoring_bigquant_run,
        search_algorithm='网格搜索',
        search_iterations=1,
        workers=2,
        worker_distributed_run=False,
        worker_silent=True,
        run_now=True,
        bq_graph=g
    )
    
    [CV 1/1; 1/2] START m30.features=['a'], m55.features=['a']......................
    [CV 1/1; 2/2] START m30.features=['a'], m55.features=['b']......................
    444444444444444444444444
    
    
    Fitting 1 folds for each of 2 candidates, totalling 2 fits
    [Parallel(n_jobs=2)]: Using backend MultiprocessingBackend with 2 concurrent workers.
    [CV 1/1; 2/2] END ....m30.features=['a'], m55.features=['b']; total time=   0.2s[CV 1/1; 1/2] END ....m30.features=['a'], m55.features=['a']; total time=   0.2s
    
    [Parallel(n_jobs=2)]: Done   1 tasks      | elapsed:    0.2s
    [Parallel(n_jobs=2)]: Done   2 out of   2 | elapsed:    0.2s remaining:    0.0s
    [Parallel(n_jobs=2)]: Done   2 out of   2 | elapsed:    0.2s finished
    
    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-194-4b43e2542103> in <module>
        123 
        124 
    --> 125 m18 = M.hyper_parameter_search.v1(
        126     param_grid_builder=m18_param_grid_builder_bigquant_run,
        127     scoring=m18_scoring_bigquant_run,
    
    RuntimeError: Cannot clone object <biglearning.module2.modules.hyper_parameter_search.v1.graphestimator.GraphEstimator object at 0x7f884900ab20>, as the constructor either does not set or modifies parameter m30.features