怎么显示5分钟内的RSI指标特征


(cash01) #1

我想建立一个当日波段操作策略,取RSI 5分钟的RSI指标,做判断买入卖出,有谁知道怎么写吗?


(达达) #2

参考下面这个例子,可以在自定义模块中做resample把分钟线转为5分钟K线,然后计算RSI

克隆策略

    {"Description":"实验创建于2018/10/16","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-1442:instruments","SourceOutputPortId":"-25:data"},{"DestinationInputPortId":"-1483:input_1","SourceOutputPortId":"-25:data"},{"DestinationInputPortId":"-1473:features","SourceOutputPortId":"-1468:data"},{"DestinationInputPortId":"-1632:input_data","SourceOutputPortId":"-1473:data"},{"DestinationInputPortId":"-1473:input_data","SourceOutputPortId":"-1483:data_1"},{"DestinationInputPortId":"-1442:options_data","SourceOutputPortId":"-1632:data"}],"ModuleNodes":[{"Id":"-25","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-04-20 09:01:00","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-05-20 15:15:00","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"600010.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-25"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-25","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-1442","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n\n instrument_symbol = context.symbol(context.instruments[0]) # 交易标的\n curr_position = context.portfolio.positions[instrument_symbol].amount # 持仓数量\n \n if context.index < 5: # 日内数据超过窗口范围后才开始交易\n context.index += 1\n return\n \n # 获取当前分钟的买卖信号\n today_date=data.current_dt.strftime('%Y-%m-%d %H:%M:%S')\n try:\n buy_condition = context.buy_condition[today_date]\n except:\n buy_condition = 0\n \n try: \n sell_condition=context.sell_condition[today_date]\n except:\n sell_condition = 0\n \n \n # 如果当前没有仓位,且大于通道价格上限,long开仓\n if curr_position == 0 and buy_condition>0:\n context.order_target(instrument_symbol, 100)\n elif curr_position >= 0 and sell_condition>0:\n context.order_target(instrument_symbol, 0)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n df = context.options['data'].read_df()\n df['date']=df['date'].apply(lambda x:x.strftime('%Y-%m-%d %H:%M:%S'))\n df.set_index('date',inplace=True)\n context.buy_condition=df['buy_condition']\n context.sell_condition=df['sell_condition']\n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 设置是否是结算模式\n context.set_need_settle(False)\n context.set_commission(PerOrder(buy_cost=0.0013, sell_cost=0.0023, min_cost=5))\n # 当日分钟K线数量记录变量初始化\n context.index = 1\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":"50000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"minute","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-1442"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-1442"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-1442"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark","NodeId":"-1442"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-1442"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-1442","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-1468","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nbuy_condition=where(ta_rsi(close,14)>60,1,0)\nsell_condition=where(ta_rsi(close,14)<40,1,0)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-1468"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1468","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-1473","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":"-1473"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-1473"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1473","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-1483","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,before_days):\n # 示例代码如下。在这里编写您的代码\n start_date=input_1.read_pickle()['start_date']\n end_date=input_1.read_pickle()['end_date']\n ins=input_1.read_pickle()['instruments'][0]\n df = DataSource('bar1m_'+ins).read(start_date=start_date,end_date=end_date,fields=['open','close','high','low'])\n df['adjust_factor']=1.0\n df=df.set_index('date').resample('5min',how='last').dropna().reset_index()\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\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":"{'before_days':1}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-1483"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-1483"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-1483"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-1483","OutputType":null},{"Name":"data_2","NodeId":"-1483","OutputType":null},{"Name":"data_3","NodeId":"-1483","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-1632","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-1632"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1632","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"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='-25' Position='-54,0,200,200'/><NodePosition Node='-1442' Position='8,463.80303955078125,200,200'/><NodePosition Node='-1468' Position='551,32,200,200'/><NodePosition Node='-1473' Position='362,230,200,200'/><NodePosition Node='-1483' Position='95,134,200,200'/><NodePosition Node='-1632' Position='344,325,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 [165]:
    # 本代码由可视化策略环境自动生成 2018年12月20日 15:14
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m4_run_bigquant_run(input_1, input_2, input_3,before_days):
        # 示例代码如下。在这里编写您的代码
        start_date=input_1.read_pickle()['start_date']
        end_date=input_1.read_pickle()['end_date']
        ins=input_1.read_pickle()['instruments'][0]
        df = DataSource('bar1m_'+ins).read(start_date=start_date,end_date=end_date,fields=['open','close','high','low'])
        df['adjust_factor']=1.0
        df=df.set_index('date').resample('5min',how='last').dropna().reset_index()
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m4_post_run_bigquant_run(outputs):
        return outputs
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m3_handle_data_bigquant_run(context, data):
    
        instrument_symbol = context.symbol(context.instruments[0]) # 交易标的
        curr_position = context.portfolio.positions[instrument_symbol].amount # 持仓数量
        
        if context.index < 5: # 日内数据超过窗口范围后才开始交易
            context.index += 1
            return
        
        # 获取当前分钟的买卖信号
        today_date=data.current_dt.strftime('%Y-%m-%d %H:%M:%S')
        try:
            buy_condition = context.buy_condition[today_date]
        except:
            buy_condition = 0
        
        try:    
            sell_condition=context.sell_condition[today_date]
        except:
            sell_condition = 0
            
        
        # 如果当前没有仓位,且大于通道价格上限,long开仓
        if curr_position == 0 and buy_condition>0:
            context.order_target(instrument_symbol, 100)
        elif curr_position >= 0 and sell_condition>0:
            context.order_target(instrument_symbol, 0)
    # 回测引擎:准备数据,只执行一次
    def m3_prepare_bigquant_run(context):
        df = context.options['data'].read_df()
        df['date']=df['date'].apply(lambda x:x.strftime('%Y-%m-%d %H:%M:%S'))
        df.set_index('date',inplace=True)
        context.buy_condition=df['buy_condition']
        context.sell_condition=df['sell_condition']
    
    
    # 回测引擎:初始化函数,只执行一次
    def m3_initialize_bigquant_run(context):
       # 设置是否是结算模式
        context.set_need_settle(False)
        context.set_commission(PerOrder(buy_cost=0.0013, sell_cost=0.0023, min_cost=5))
        # 当日分钟K线数量记录变量初始化
        context.index = 1
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m3_before_trading_start_bigquant_run(context, data):
        pass
    
    
    m2 = M.instruments.v2(
        start_date='2018-04-20 09:01:00',
        end_date='2018-05-20 15:15:00',
        market='CN_STOCK_A',
        instrument_list='600010.SHA',
        max_count=0
    )
    
    m4 = M.cached.v3(
        input_1=m2.data,
        run=m4_run_bigquant_run,
        post_run=m4_post_run_bigquant_run,
        input_ports='',
        params='{\'before_days\':1}',
        output_ports='',
        m_cached=False
    )
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    buy_condition=where(ta_rsi(close,14)>60,1,0)
    sell_condition=where(ta_rsi(close,14)<40,1,0)
    """
    )
    
    m6 = M.derived_feature_extractor.v3(
        input_data=m4.data_1,
        features=m5.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m7 = M.dropnan.v1(
        input_data=m6.data
    )
    
    m3 = M.trade.v4(
        instruments=m2.data,
        options_data=m7.data,
        start_date='',
        end_date='',
        handle_data=m3_handle_data_bigquant_run,
        prepare=m3_prepare_bigquant_run,
        initialize=m3_initialize_bigquant_run,
        before_trading_start=m3_before_trading_start_bigquant_run,
        volume_limit=0,
        order_price_field_buy='open',
        order_price_field_sell='open',
        capital_base=50000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='minute',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False
    )
    
    [2018-12-20 15:14:20.422661] INFO: bigquant: instruments.v2 开始运行..
    [2018-12-20 15:14:20.427494] INFO: bigquant: 命中缓存
    [2018-12-20 15:14:20.428477] INFO: bigquant: instruments.v2 运行完成[0.005843s].
    [2018-12-20 15:14:20.437095] INFO: bigquant: cached.v3 开始运行..
    [2018-12-20 15:14:22.257914] INFO: bigquant: cached.v3 运行完成[1.820819s].
    [2018-12-20 15:14:22.260302] INFO: bigquant: input_features.v1 开始运行..
    [2018-12-20 15:14:22.263941] INFO: bigquant: 命中缓存
    [2018-12-20 15:14:22.264759] INFO: bigquant: input_features.v1 运行完成[0.004482s].
    [2018-12-20 15:14:22.267254] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2018-12-20 15:14:22.293911] INFO: derived_feature_extractor: 提取完成 buy_condition=where(ta_rsi(close,14)>60,1,0), 0.006s
    [2018-12-20 15:14:22.302202] INFO: derived_feature_extractor: 提取完成 sell_condition=where(ta_rsi(close,14)<40,1,0), 0.007s
    [2018-12-20 15:14:22.322704] INFO: derived_feature_extractor: /data, 950
    [2018-12-20 15:14:22.350524] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.083216s].
    [2018-12-20 15:14:22.353964] INFO: bigquant: dropnan.v1 开始运行..
    [2018-12-20 15:14:22.406025] INFO: dropnan: /data, 950/950
    [2018-12-20 15:14:22.415086] INFO: dropnan: 行数: 950/950
    [2018-12-20 15:14:22.417452] INFO: bigquant: dropnan.v1 运行完成[0.063464s].
    [2018-12-20 15:14:22.432799] INFO: bigquant: backtest.v8 开始运行..
    [2018-12-20 15:14:22.436445] INFO: bigquant: biglearning backtest:V8.1.6
    [2018-12-20 15:14:22.466042] INFO: bigquant: product_type:stock by specified
    [2018-12-20 15:14:23.656272] INFO: bigquant: 读取股票行情完成:18240
    [2018-12-20 15:14:23.673111] INFO: algo: TradingAlgorithm V1.3.7
    [2018-12-20 15:14:24.546692] INFO: algo: trading transform...
    [2018-12-20 15:14:42.779899] INFO: Performance: Simulated 19 trading days out of 19.
    [2018-12-20 15:14:42.781020] INFO: Performance: first open: 2018-04-20 09:30:00+00:00
    [2018-12-20 15:14:42.781894] INFO: Performance: last close: 2018-05-18 15:00:00+00:00
    
    • 收益率-0.15%
    • 年化收益率-1.97%
    • 基准收益率2.39%
    • 阿尔法-0.05
    • 贝塔0.0
    • 夏普比率-29.01
    • 胜率0.43
    • 盈亏比0.22
    • 收益波动率0.17%
    • 信息比率-0.14
    • 最大回撤0.15%
    [2018-12-20 15:14:45.167289] INFO: bigquant: backtest.v8 运行完成[22.734496s].
    

    (cash01) #3

    以300170为例,策略跑出来的5分钟的low,high,close和同花顺以5分钟为k线跑出来的值不匹配,包括RSI强弱指标值



    (blsm001) #4

    m4中的分钟转换label有问题错位了,设置一下label=‘right’

    df=df.set_index('date').resample('5min',how='last',closed='right',label='right').dropna().reset_index()
    

    (cash01) #5

    image
    image
    还是有差异。。。


    (blsm001) #6

    之前的例子我这跑着好像是对的,你看看呢

    克隆策略

      {"Description":"实验创建于2018/10/16","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-1483:input_1","SourceOutputPortId":"-25:data"}],"ModuleNodes":[{"Id":"-25","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-10-17 09:00:00","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-10-18 15:15:00","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"300170.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":"-25"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-25","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-1483","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,before_days):\n # 示例代码如下。在这里编写您的代码\n start_date=input_1.read_pickle()['start_date']\n end_date=input_1.read_pickle()['end_date']\n ins=input_1.read_pickle()['instruments'][0]\n df = DataSource('bar1m_'+ins).read(start_date=start_date,end_date=end_date,fields=['open','close','high','low'])\n df['adjust_factor']=1.0\n df=df.set_index('date').resample('5min',how='last',closed='right',label='right').dropna().reset_index()\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\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":"{'before_days':1}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-1483"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-1483"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-1483"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-1483","OutputType":null},{"Name":"data_2","NodeId":"-1483","OutputType":null},{"Name":"data_3","NodeId":"-1483","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"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='-25' Position='-54,-1.8381576538085938,200,200'/><NodePosition Node='-1483' Position='95,134,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]:
      # 本代码由可视化策略环境自动生成 2019年10月23日 11:36
      # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
      
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m4_run_bigquant_run(input_1, input_2, input_3,before_days):
          # 示例代码如下。在这里编写您的代码
          start_date=input_1.read_pickle()['start_date']
          end_date=input_1.read_pickle()['end_date']
          ins=input_1.read_pickle()['instruments'][0]
          df = DataSource('bar1m_'+ins).read(start_date=start_date,end_date=end_date,fields=['open','close','high','low'])
          df['adjust_factor']=1.0
          df=df.set_index('date').resample('5min',how='last',closed='right',label='right').dropna().reset_index()
          data_1 = DataSource.write_df(df)
          return Outputs(data_1=data_1, data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m4_post_run_bigquant_run(outputs):
          return outputs
      
      
      m2 = M.instruments.v2(
          start_date='2019-10-17 09:00:00',
          end_date='2019-10-18 15:15:00',
          market='CN_STOCK_A',
          instrument_list='300170.SZA',
          max_count=0,
          m_cached=False
      )
      
      m4 = M.cached.v3(
          input_1=m2.data,
          run=m4_run_bigquant_run,
          post_run=m4_post_run_bigquant_run,
          input_ports='',
          params='{\'before_days\':1}',
          output_ports='',
          m_cached=False
      )
      
      In [4]:
      m4.data_1.read_df()
      
      Out[4]:
      date instrument close high open low adjust_factor
      0 2019-10-17 09:35:00 300170.SZA 10.00 10.06 10.06 10.00 1.0
      1 2019-10-17 09:40:00 300170.SZA 10.13 10.14 10.07 10.07 1.0
      2 2019-10-17 09:45:00 300170.SZA 10.21 10.21 10.19 10.19 1.0
      3 2019-10-17 09:50:00 300170.SZA 10.30 10.30 10.27 10.27 1.0
      4 2019-10-17 09:55:00 300170.SZA 10.26 10.29 10.28 10.26 1.0
      5 2019-10-17 10:00:00 300170.SZA 10.30 10.30 10.28 10.28 1.0
      6 2019-10-17 10:05:00 300170.SZA 10.31 10.32 10.32 10.30 1.0
      7 2019-10-17 10:10:00 300170.SZA 10.30 10.30 10.29 10.29 1.0
      8 2019-10-17 10:15:00 300170.SZA 10.27 10.28 10.27 10.26 1.0
      9 2019-10-17 10:20:00 300170.SZA 10.27 10.27 10.27 10.26 1.0
      10 2019-10-17 10:25:00 300170.SZA 10.23 10.24 10.22 10.21 1.0
      11 2019-10-17 10:30:00 300170.SZA 10.20 10.21 10.21 10.20 1.0
      12 2019-10-17 10:35:00 300170.SZA 10.26 10.26 10.26 10.25 1.0
      13 2019-10-17 10:40:00 300170.SZA 10.25 10.25 10.24 10.23 1.0
      14 2019-10-17 10:45:00 300170.SZA 10.24 10.24 10.24 10.23 1.0
      15 2019-10-17 10:50:00 300170.SZA 10.20 10.22 10.22 10.19 1.0
      16 2019-10-17 10:55:00 300170.SZA 10.19 10.20 10.20 10.16 1.0
      17 2019-10-17 11:00:00 300170.SZA 10.15 10.16 10.16 10.14 1.0
      18 2019-10-17 11:05:00 300170.SZA 10.18 10.19 10.18 10.17 1.0
      19 2019-10-17 11:10:00 300170.SZA 10.19 10.20 10.20 10.18 1.0
      20 2019-10-17 11:15:00 300170.SZA 10.22 10.22 10.20 10.20 1.0
      21 2019-10-17 11:20:00 300170.SZA 10.21 10.21 10.20 10.20 1.0
      22 2019-10-17 11:25:00 300170.SZA 10.22 10.22 10.22 10.20 1.0
      23 2019-10-17 11:30:00 300170.SZA 10.21 10.21 10.20 10.20 1.0
      24 2019-10-17 13:05:00 300170.SZA 10.24 10.25 10.24 10.24 1.0
      25 2019-10-17 13:10:00 300170.SZA 10.24 10.24 10.24 10.23 1.0
      26 2019-10-17 13:15:00 300170.SZA 10.23 10.24 10.24 10.23 1.0
      27 2019-10-17 13:20:00 300170.SZA 10.22 10.23 10.22 10.21 1.0
      28 2019-10-17 13:25:00 300170.SZA 10.22 10.25 10.24 10.22 1.0
      29 2019-10-17 13:30:00 300170.SZA 10.21 10.23 10.23 10.21 1.0
      ... ... ... ... ... ... ... ...
      66 2019-10-18 11:05:00 300170.SZA 10.31 10.31 10.31 10.30 1.0
      67 2019-10-18 11:10:00 300170.SZA 10.31 10.31 10.31 10.30 1.0
      68 2019-10-18 11:15:00 300170.SZA 10.29 10.30 10.30 10.28 1.0
      69 2019-10-18 11:20:00 300170.SZA 10.26 10.26 10.26 10.23 1.0
      70 2019-10-18 11:25:00 300170.SZA 10.24 10.26 10.25 10.24 1.0
      71 2019-10-18 11:30:00 300170.SZA 10.25 10.26 10.25 10.23 1.0
      72 2019-10-18 13:05:00 300170.SZA 10.22 10.23 10.22 10.22 1.0
      73 2019-10-18 13:10:00 300170.SZA 10.20 10.22 10.20 10.19 1.0
      74 2019-10-18 13:15:00 300170.SZA 10.17 10.20 10.19 10.16 1.0
      75 2019-10-18 13:20:00 300170.SZA 10.15 10.18 10.17 10.15 1.0
      76 2019-10-18 13:25:00 300170.SZA 10.17 10.17 10.17 10.16 1.0
      77 2019-10-18 13:30:00 300170.SZA 10.15 10.15 10.15 10.14 1.0
      78 2019-10-18 13:35:00 300170.SZA 10.16 10.16 10.16 10.15 1.0
      79 2019-10-18 13:40:00 300170.SZA 10.17 10.18 10.18 10.17 1.0
      80 2019-10-18 13:45:00 300170.SZA 10.17 10.18 10.18 10.16 1.0
      81 2019-10-18 13:50:00 300170.SZA 10.12 10.13 10.12 10.11 1.0
      82 2019-10-18 13:55:00 300170.SZA 10.15 10.16 10.13 10.13 1.0
      83 2019-10-18 14:00:00 300170.SZA 10.15 10.16 10.16 10.15 1.0
      84 2019-10-18 14:05:00 300170.SZA 10.15 10.15 10.15 10.14 1.0
      85 2019-10-18 14:10:00 300170.SZA 10.13 10.15 10.15 10.13 1.0
      86 2019-10-18 14:15:00 300170.SZA 10.10 10.11 10.11 10.10 1.0
      87 2019-10-18 14:20:00 300170.SZA 10.04 10.10 10.09 10.00 1.0
      88 2019-10-18 14:25:00 300170.SZA 10.09 10.09 10.09 10.08 1.0
      89 2019-10-18 14:30:00 300170.SZA 10.13 10.15 10.14 10.13 1.0
      90 2019-10-18 14:35:00 300170.SZA 10.12 10.14 10.14 10.12 1.0
      91 2019-10-18 14:40:00 300170.SZA 10.13 10.13 10.13 10.12 1.0
      92 2019-10-18 14:45:00 300170.SZA 10.12 10.14 10.14 10.12 1.0
      93 2019-10-18 14:50:00 300170.SZA 10.17 10.17 10.15 10.15 1.0
      94 2019-10-18 14:55:00 300170.SZA 10.16 10.16 10.15 10.14 1.0
      95 2019-10-18 15:00:00 300170.SZA 10.15 10.16 10.16 10.15 1.0

      96 rows × 7 columns