克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-162:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-162:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-59:input_ds","SourceOutputPortId":"-162:data"},{"DestinationInputPortId":"-117:input_ds","SourceOutputPortId":"-162:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-12-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000001.SZA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nopen\nclose\nhigh\nlow\namount","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-162","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_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":"-162"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-162"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-162","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-59","ModuleId":"BigQuantSpace.Tplot.Tplot-v1","ModuleParameters":[{"Name":"x","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"low","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"title","Value":"开盘价折线图","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"spline","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_options","Value":"{'chart':{'height': 500}}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-59"}],"OutputPortsInternal":[],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"绘制开盘价折线图","CommentCollapsed":false},{"Id":"-117","ModuleId":"BigQuantSpace.Tplot.Tplot-v1","ModuleParameters":[{"Name":"x","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"open,high,low,close,amount","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"title","Value":"K线图","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"candlestick","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_options","Value":"{'series': [{},{'type': 'column'}]}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-117"}],"OutputPortsInternal":[],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"绘制K线图","CommentCollapsed":false}],"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='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='230,4,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='550,11,200,200'/><NodePosition Node='-162' Position='389,110,200,200'/><NodePosition Node='-59' Position='215,208,200,200'/><NodePosition Node='-117' Position='567,208,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]:
    # 本代码由可视化策略环境自动生成 2021年10月15日22:27
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2015-12-01',
        market='CN_STOCK_A',
        instrument_list='000001.SZA',
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    open
    close
    high
    low
    amount"""
    )
    
    m2 = M.use_datasource.v1(
        instruments=m1.data,
        features=m3.data,
        datasource_id='bar1d_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m10 = M.Tplot.v1(
        input_ds=m2.data,
        x='date',
        y='low',
        title='开盘价折线图',
        chart_type='spline',
        chart_options={'chart':{'height': 500}}
    )
    
    m4 = M.Tplot.v1(
        input_ds=m2.data,
        x='date',
        y='open,high,low,close,amount',
        title='K线图',
        chart_type='candlestick',
        chart_options={'series': [{},{'type': 'column'}]}
    )
    
    In [3]:
    df = m2.data.read_df().set_index('date')
    df.head()
    
    Out[3]:
    instrument high open low close amount
    date
    2015-01-05 000001.SZA 1156.754150 1136.148560 1108.437622 1138.280273 4.565388e+09
    2015-01-06 000001.SZA 1164.570068 1126.201050 1104.885010 1121.227295 3.453446e+09
    2015-01-07 000001.SZA 1124.780029 1105.595581 1087.121582 1099.911255 2.634796e+09
    2015-01-08 000001.SZA 1106.306030 1101.332275 1058.700073 1062.963257 2.128003e+09
    2015-01-09 000001.SZA 1127.622192 1058.700073 1045.199829 1071.489746 3.835378e+09
    In [5]:
    T.plot(df[['low']], title='最低价格', chart_type='spline')
    
    In [9]:
    T.plot(df[['open', 'high', 'low', 'close', 'amount']],
           # 设置图表title和高度;'series': [{},{'type': 'column'}] 设置第二个数据系列(即 amount)显示类型为柱状图(column)
           options={'chart': { 'height': 800}, 'series': [{},{'type': 'column'}]}, 
           title="股票数据分析",
           stock=True, 
           candlestick=True)
    

    绘制多个曲线

    In [10]:
    df = DataSource('bar1d_CN_STOCK_A').read(instruments=['000010.SZA','600010.SHA'],start_date='2019-01-01')
    close_series = pd.pivot_table(df,index='date', columns='instrument', values='close')
    close_series.head(5)
    
    Out[10]:
    instrument 000010.SZA 600010.SHA
    date
    2019-01-02 35.340519 12.173035
    2019-01-03 35.340519 12.338655
    2019-01-04 35.771503 12.587084
    2019-01-07 36.633465 12.587084
    2019-01-08 36.310230 12.504273
    In [11]:
    df.set_index(['date','instrument'])['close'].unstack().head(5)
    
    Out[11]:
    instrument 000010.SZA 600010.SHA
    date
    2019-01-02 35.340519 12.173035
    2019-01-03 35.340519 12.338655
    2019-01-04 35.771503 12.587084
    2019-01-07 36.633465 12.587084
    2019-01-08 36.310230 12.504273
    In [12]:
    T.plot(close_series)
    

    批量绘制多个K线

    In [14]:
    df = DataSource('bar1d_CN_STOCK_A').read(instruments=['000010.SZA','600010.SHA','000021.SZA'],start_date='2019-01-01').set_index('date')
    for k in df.instrument.unique():   
        T.plot(df[df.instrument==k][['open', 'high', 'low', 'close']], candlestick=True, title=k)