国庆长假前后A股收益分析

cached
plot_dataframe
use_datasource
bar1d_index_cn_stock_a
filter
标签: #<Tag:0x00007f5b9208ff58> #<Tag:0x00007f5b9208fd00> #<Tag:0x00007f5b9208fb98> #<Tag:0x00007f5b9208fa58> #<Tag:0x00007f5b9208f918>

(iQuant) #1

分析国庆长假前后A股收益(以沪深300 000300.HIX 计算),能看到有一定的趋势存在。

2019年70周年国庆A股走势会怎样呢?

本文主要是用来展示数据和模块的使用,不代表任何投资建议。

克隆策略

    {"Description":"实验创建于2019/9/10","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-341:input_data","SourceOutputPortId":"-334:data"},{"DestinationInputPortId":"-350:input_1","SourceOutputPortId":"-341:data"},{"DestinationInputPortId":"-357:input_data","SourceOutputPortId":"-350:data_1"}],"ModuleNodes":[{"Id":"-334","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":"2005-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-11-01","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-334"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-334"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-334","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-341","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"instrument=='000300.HIX'","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_left_data","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-341"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-341","OutputType":null},{"Name":"left_data","NodeId":"-341","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-350","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 df = input_1.read()\n cols = [\n (-15, '节前15个交易日'),\n (-10, '节前10个交易日'),\n (-5, '节前5个交易日'),\n (-1, '节前1个交易日'),\n (1, '节后1个交易日'),\n (5, '节后5个交易日'),\n (10, '节后10个交易日'),\n (15, '节后15个交易日'),\n ]\n df = df[['date', 'open', 'close']]\n for days, name in cols:\n if days < 0:\n df[name] = df['close'].shift(1) / df.open.shift(-days) - 1\n else:\n df[name] = df['close'].shift(-days + 1) / df['open'] - 1\n del df['open']\n del df['close']\n\n dates = df['date'].searchsorted([pd.to_datetime('%s-10-01' % i) for i in \\\n range(df['date'].min().year, df['date'].max().year + 1)])\n df = df.iloc[dates]\n\n data_1 = DataSource.write_df(df)\n\n return Outputs(data_1=data_1)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-350"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-350"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-350"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-350","OutputType":null},{"Name":"data_2","NodeId":"-350","OutputType":null},{"Name":"data_3","NodeId":"-350","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-357","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"国庆长假前后A股市场收益","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"column","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 600\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":"-357"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":4,"IsPartOfPartialRun":null,"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='-334' Position='292,101,200,200'/><NodePosition Node='-341' Position='291,211,200,200'/><NodePosition Node='-350' Position='291.4086608886719,321.0032958984375,200,200'/><NodePosition Node='-357' Position='290.74090576171875,424.0066223144531,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 [100]:
    # 本代码由可视化策略环境自动生成 2019年9月10日 14:47
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m3_run_bigquant_run(input_1, input_2, input_3):
        df = input_1.read()
        cols = [
            (-15, '节前15个交易日'),
            (-10, '节前10个交易日'),
            (-5, '节前5个交易日'),
            (-1, '节前1个交易日'),
            (1, '节后1个交易日'),
            (5, '节后5个交易日'),
            (10, '节后10个交易日'),
            (15, '节后15个交易日'),
        ]
        df = df[['date', 'open', 'close']]
        for days, name in cols:
            if days < 0:
                df[name] = df['close'].shift(1) / df.open.shift(-days) - 1
            else:
                df[name] = df['close'].shift(-days + 1) / df['open'] - 1
        del df['open']
        del df['close']
    
        dates = df['date'].searchsorted([pd.to_datetime('%s-10-01' % i) for i in \
                                         range(df['date'].min().year, df['date'].max().year + 1)])
        df = df.iloc[dates]
    
        data_1 = DataSource.write_df(df)
    
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m3_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.use_datasource.v1(
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='2005-01-01',
        end_date='2018-11-01'
    )
    
    m2 = M.filter.v3(
        input_data=m1.data,
        expr='instrument==\'000300.HIX\'',
        output_left_data=False
    )
    
    m3 = M.cached.v3(
        input_1=m2.data,
        run=m3_run_bigquant_run,
        post_run=m3_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m4 = M.plot_dataframe.v1(
        input_data=m3.data_1,
        title='国庆长假前后A股市场收益',
        chart_type='column',
        x='date',
        y='',
        options={
        'chart': {
            'height': 600
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )