in_csi300_0取数规则疑问?


(pivotll) #1

为什么in_csi300_0取出来的股票不是300只? 取股票代码里面还会有T00018.SHA这是什么代码?


(iQuant) #2

你好,是这样的,in_csi300_0是表明该股票当时是否存在沪深300指数成分的一个特征,如果你取的是一段时间的数据,那么可能数量不是300,因为沪深300指数成分会定期调整,有的股票会选进来,有的股票会选出去。

T00018.SHA这个代码可以不用管。我们会移除该代码,属于历史遗留问题。


(pivotll) #3

如果要选取某个日期,某指数的成分股怎么获取。是否属于该指数,作为每日因子并入因子分析。能不能给一个300的例子,保证每天300成分股都是完整的。


(iQuant) #4

可否再具体地介绍下你的目的,这样方便我们理解。获取某天某指数成分可以参考如下代码:

克隆策略

    {"Description":"实验创建于3/13/2018","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-2117:input_1","SourceOutputPortId":"-2121:data"}],"ModuleNodes":[{"Id":"-2117","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n data = input_1.read_pickle()\n date = data['start_date']\n df = D.history_data(D.instruments(date, date),date,date,fields=['in_csi300'])\n# 获取沪深300的成分股股票列表 中证500:in_csi500,中证800:in_csi800 参考文档说明\n hs300 = list(set(df[df['in_csi300']==1]['instrument']))\n data_1 = DataSource.write_pickle(hs300)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-2117"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-2117"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-2117"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-2117","OutputType":null},{"Name":"data_2","NodeId":"-2117","OutputType":null},{"Name":"data_3","NodeId":"-2117","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-2121","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-03-13","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-03-13","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-2121"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-2121","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"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='-2117' Position='139,171,200,200'/><NodePosition Node='-2121' Position='62,89,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 [1]:
    # 本代码由可视化策略环境自动生成 2018年3月13日 22:41
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m2 = M.instruments.v2(
        start_date='2018-03-13',
        end_date='2018-03-13',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m1_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        data = input_1.read_pickle()
        date = data['start_date']
        df = D.history_data(D.instruments(date, date),date,date,fields=['in_csi300'])
    # 获取沪深300的成分股股票列表  中证500:in_csi500,中证800:in_csi800  参考文档说明
        hs300 = list(set(df[df['in_csi300']==1]['instrument']))
        data_1 = DataSource.write_pickle(hs300)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    m1 = M.cached.v3(
        input_1=m2.data,
        run=m1_run_bigquant_run
    )
    
    [2018-03-13 22:39:18.709731] INFO: bigquant: instruments.v2 开始运行..
    [2018-03-13 22:39:18.723321] INFO: bigquant: 命中缓存
    [2018-03-13 22:39:18.729724] INFO: bigquant: instruments.v2 运行完成[0.019994s].
    [2018-03-13 22:39:18.756428] INFO: bigquant: cached.v3 开始运行..
    [2018-03-13 22:39:19.151044] INFO: bigquant: cached.v3 运行完成[0.394612s].
    
    In [3]:
    m1.data_1.read_pickle()[:10]
    
    Out[3]:
    ['600018.SHA',
     '600739.SHA',
     '002500.SZA',
     '600886.SHA',
     '601216.SHA',
     '600271.SHA',
     '600010.SHA',
     '002252.SZA',
     '002841.SZA',
     '600015.SHA']