沪深300和中证500等核心指数涨收益对比

策略分享
标签: #<Tag:0x00007f20d0839cb0>

(ingeno) #1

原理和用到的模块:

完整代码

克隆策略

    {"Description":"实验创建于2019/1/10","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-25:input_data","SourceOutputPortId":"-6:data"},{"DestinationInputPortId":"-6:instruments","SourceOutputPortId":"-12:data"},{"DestinationInputPortId":"-25:features","SourceOutputPortId":"-20:data"},{"DestinationInputPortId":"-73:input_data","SourceOutputPortId":"-25:data"},{"DestinationInputPortId":"-44:input_data","SourceOutputPortId":"-73:data_1"}],"ModuleNodes":[{"Id":"-6","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_index_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-6"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-12","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-31","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000016.HIX\n399330.ZIX\n000905.HIX\n000906.HIX","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-12"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-20","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_1 = close / shift(close, 1)\nreturn_5 = close / shift(close, 5)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-20"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-20","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-25","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-25"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-25"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-25","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-44","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-44"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-73","ModuleId":"BigQuantSpace.pandas_pivot_table.pandas_pivot_table-v1","ModuleParameters":[{"Name":"index","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"columns","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"values","Value":"return_1,return_5","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"flat","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-73"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-73","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='-6' Position='143.32717895507812,189.85855102539062,200,200'/><NodePosition Node='-12' Position='145,93.90283203125,200,200'/><NodePosition Node='-20' Position='485.17706298828125,191.6113510131836,200,200'/><NodePosition Node='-25' Position='351,289,200,200'/><NodePosition Node='-44' Position='353.2200927734375,454.9630126953125,200,200'/><NodePosition Node='-73' Position='353.41314697265625,375.22998046875,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [2]:
    # 本代码由可视化策略环境自动生成 2019年1月11日 14:09
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m2 = M.instruments.v2(
        start_date='2018-01-01',
        end_date='2018-12-31',
        market='CN_STOCK_A',
        instrument_list="""000016.HIX
    399330.ZIX
    000905.HIX
    000906.HIX""",
        max_count=0
    )
    
    m1 = M.use_datasource.v1(
        instruments=m2.data,
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    return_1 = close / shift(close, 1)
    return_5 = close / shift(close, 5)
    """
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m11 = M.pandas_pivot_table.v1(
        input_data=m4.data,
        index='date',
        columns='instrument',
        values='return_1,return_5',
        flat=False
    )
    
    m6 = M.plot_dataframe.v1(
        input_data=m11.data_1,
        title='',
        chart_type='line',
        x='',
        y='',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    [2019-01-11 14:05:41.836474] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-11 14:05:42.000904] INFO: bigquant: 命中缓存
    [2019-01-11 14:05:42.004424] INFO: bigquant: instruments.v2 运行完成[0.185085s].
    [2019-01-11 14:05:42.101887] INFO: bigquant: use_datasource.v1 开始运行..
    [2019-01-11 14:05:42.902498] INFO: bigquant: use_datasource.v1 运行完成[0.800586s].
    [2019-01-11 14:05:42.992688] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-11 14:05:42.999800] INFO: bigquant: 命中缓存
    [2019-01-11 14:05:43.000764] INFO: bigquant: input_features.v1 运行完成[0.00808s].
    [2019-01-11 14:05:43.102753] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-11 14:05:43.289748] INFO: derived_feature_extractor: 提取完成 return_1 = close / shift(close, 1), 0.078s
    [2019-01-11 14:05:43.294520] INFO: derived_feature_extractor: 提取完成 return_5 = close / shift(close, 5), 0.004s
    [2019-01-11 14:05:43.338529] INFO: derived_feature_extractor: /data, 972
    [2019-01-11 14:05:43.370921] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.268173s].
    [2019-01-11 14:05:43.703368] INFO: bigquant: pandas_pivot_table.v1 开始运行..
    [2019-01-11 14:05:43.813539] INFO: bigquant: pandas_pivot_table.v1 运行完成[0.110172s].