测试分享

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

(think) #1
克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-136:input_2","SourceOutputPortId":"-114:data"},{"DestinationInputPortId":"-150:options_data","SourceOutputPortId":"-136:data_1"},{"DestinationInputPortId":"-150:instruments","SourceOutputPortId":"-136:data_2"},{"DestinationInputPortId":"-150:handle_bar_functions","SourceOutputPortId":"-169:functions"},{"DestinationInputPortId":"-136:input_1","SourceOutputPortId":"-122:data_1"},{"DestinationInputPortId":"-150:initialize_functions","SourceOutputPortId":"-2148:functions"}],"ModuleNodes":[{"Id":"-114","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"instruments_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2019-02-14","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-02-14","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-114"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-114"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-114","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"股票代码和名称,用于抽取微博中的股票代码","CommentCollapsed":false},{"Id":"-136","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(weibo_ds, instrument_ds):\n import re\n cards = weibo_ds.read_pickle()\n instrument_df = instrument_ds.read_df()\n log = T.BigLogger('微博解析')\n log.info('解析用户微博 ..')\n\n blog_cards = [c for c in cards if c['card_type'] == 9 and 'title' not in c['mblog']]\n\n names = list(instrument_df['name'])\n instruments = list(instrument_df['instrument'])\n\n keywords = {}\n for i in range(len(instrument_df)):\n name = instrument_df['name'].iloc[i]\n instrument = instrument_df['instrument'].iloc[i]\n keywords[name.strip('*')] = instrument\n keywords[instrument[:-4]] = instrument\n stock_re = re.compile('|'.join(keywords.keys()))\n\n items = []\n now_year = datetime.datetime.now().year\n for card in blog_cards:\n mblog = card['mblog']\n text = mblog['raw_text'] if 'raw_text' in mblog else mblog['text']\n created_at = mblog['created_at']\n # 跳过近期的微博,比如 2小时前这样的,用处不大\n if '-' not in created_at:\n continue\n if len(created_at) < 10:\n created_at = '%s-%s' % (now_year, created_at)\n stocks = stock_re.findall(text)\n stocks = set([keywords[stock] for stock in stocks])\n for stock in stocks:\n items.append([created_at, stock])\n\n df = pd.DataFrame(items, columns=['date', 'instrument'])\n df['date'] = pd.to_datetime(df['date'])\n\n data_ds = DataSource.write_df(df)\n\n data = {\n 'start_date': df['date'].min().strftime('%Y-%m-%d'),\n 'instruments': list(set(df['instrument'])),\n 'end_date': df['date'].max().strftime('%Y-%m-%d'),\n }\n output_instrument_ds = DataSource.write_pickle(data)\n\n log.info('共有 %s 条股票推荐, start_date=%s, end_date=%s, instruments=%s' % (\n len(df),\n data['start_date'],\n data['end_date'],\n len(data['instruments'])\n ))\n\n return Outputs(data_1=data_ds, data_2=output_instrument_ds)\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":"-136"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-136"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-136"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-136","OutputType":null},{"Name":"data_2","NodeId":"-136","OutputType":null},{"Name":"data_3","NodeId":"-136","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"抽取用户微博中提到的股票代码","CommentCollapsed":false},{"Id":"-150","ModuleId":"BigQuantSpace.tradex.tradex-v1","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 # curr_data:用于当前handle_bar,各处理函数可以用 curr_data 传递数据\n context.curr_data = {}\n if 'handle_bar_functions' in context.options:\n for func in context.options['handle_bar_functions']:\n if not func(context, data):\n # 如果有处理函数返回False,则表示跳过后续执行\n return\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n if 'initialize_functions' in context.options:\n for func in context.options['initialize_functions']:\n if not func(context):\n # 如果有处理函数返回False,则表示跳过后续执行\n return\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.0001","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":"1000000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","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":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark","NodeId":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"initialize_functions","NodeId":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"handle_bar_functions","NodeId":"-150"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-150"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-150","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-169","ModuleId":"BigQuantSpace.trade_func_customized_buy.trade_func_customized_buy-v1","ModuleParameters":[{"Name":"func","Value":"# 用户自定义买入函数\ndef bigquant_run(context, data, input_1, input_2, param_1, param_2, param_3):\n hold_days = int(param_1)\n assert hold_days > 0\n\n def minus_trading_days(date, delta_days):\n # 向前多取一些数据\n start_date = date - pd.to_timedelta(delta_days + 30, unit='D')\n try:\n trading_days = context.trading_days\n except Exception:\n trading_days = D.trading_days(start_date=start_date.strftime('%Y-%m-%d'))\n trading_days.set_index('date', inplace=True)\n context.trading_days = trading_days\n i = trading_days.index.searchsorted(date) - delta_days\n if i < 0:\n i = 0\n return trading_days.index[i]\n data_start_date = minus_trading_days(data.current_dt.date(), hold_days - 1).strftime('%Y-%m-%d')\n data_end_date = data.current_dt.strftime('%Y-%m-%d')\n\n # 等量持有最近hold_days个交易日推荐的股票\n if 'data_df' not in context.options:\n context.options['data_df'] = context.options['data'].read_df()\n date_col = context.options['data_df']['date']\n df = context.options['data_df'][(date_col >= data_start_date) & (date_col <= data_end_date)]\n # 应该持有的股票\n to_hold_instruments = set(df['instrument'])\n\n # 卖出不再持有的\n for e, p in context.portfolio.positions.items():\n if e.symbol not in to_hold_instruments:\n # 平仓\n context.order_target(e, 0)\n\n # 平衡:等量持有股票\n for instrument in to_hold_instruments:\n context.order_target_percent(context.symbol(instrument), 1.0 / len(to_hold_instruments))\n\n # 返回True,如果返回 False,之后的函数将跳过\n return True\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"param_1","Value":"10","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"param_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"param_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_functions","NodeId":"-169"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-169"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-169"}],"OutputPortsInternal":[{"Name":"functions","NodeId":"-169","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":2,"Comment":"等量持有最近给定天数(param_1)推荐的股票","CommentCollapsed":false},{"Id":"-122","ModuleId":"BigQuantSpace.weibo_user_posts_fetcher.weibo_user_posts_fetcher-v12","ModuleParameters":[{"Name":"user_name","Value":"但斌","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"count","Value":"13600","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cookie_sub","Value":"_2A25xbl7wDeRhGeVP7FMQ9SzEyj6IHXVSkWK4rDV6PUJbktAKLRDVkW1NTPR2k3qXfX231UQyj4gSDIECS_CL7Glx","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"since_id","Value":"--","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-122","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"爬取用户微博","CommentCollapsed":false},{"Id":"-384","ModuleId":"BigQuantSpace.hyper_run.hyper_run-v1","ModuleParameters":[{"Name":"run","Value":"def bigquant_run(bq_graph, inputs):\n g = bq_graph\n\n results = []\n for hold_days in [1, 5, 10, 20]:\n print('---------- 持有 %s 个交易日' % hold_days)\n parameters = {'m2.param_1': hold_days}\n results.append(g.run(parameters))\n\n return results\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"run_now","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bq_graph","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"bq_graph_port","NodeId":"-384"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-384"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-384"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-384"}],"OutputPortsInternal":[{"Name":"result","NodeId":"-384","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":3,"Comment":"计算持有不同个交易日的收益情况","CommentCollapsed":false},{"Id":"-2148","ModuleId":"BigQuantSpace.trade_func_set_commission.trade_func_set_commission-v1","ModuleParameters":[{"Name":"mode","Value":"订单/PerOrder","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"buy_cost","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sell_cost","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_cost","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_functions","NodeId":"-2148"}],"OutputPortsInternal":[{"Name":"functions","NodeId":"-2148","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":6,"Comment":"这里只看大V股票推荐能力,每天会重新平衡持仓。设置手续费为0,不考虑手续费影响","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='-114' Position='719,-193,200,200'/><NodePosition Node='-136' Position='495,-44,200,200'/><NodePosition Node='-150' Position='681,161,200,200'/><NodePosition Node='-169' Position='1067,12,200,200'/><NodePosition Node='-122' Position='381,-191,200,200'/><NodePosition Node='-384' Position='588,264,200,200'/><NodePosition Node='-2148' Position='1065,-136,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 [ ]:
    # 本代码由可视化策略环境自动生成 2019年2月19日 11:30
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 用户自定义买入函数
    def m2_func_bigquant_run(context, data, input_1, input_2, param_1, param_2, param_3):
        hold_days = int(param_1)
        assert hold_days > 0
    
        def minus_trading_days(date, delta_days):
            # 向前多取一些数据
            start_date = date - pd.to_timedelta(delta_days + 30, unit='D')
            try:
                trading_days = context.trading_days
            except Exception:
                trading_days = D.trading_days(start_date=start_date.strftime('%Y-%m-%d'))
                trading_days.set_index('date', inplace=True)
                context.trading_days = trading_days
            i = trading_days.index.searchsorted(date) - delta_days
            if i < 0:
                i = 0
            return trading_days.index[i]
        data_start_date = minus_trading_days(data.current_dt.date(), hold_days - 1).strftime('%Y-%m-%d')
        data_end_date = data.current_dt.strftime('%Y-%m-%d')
    
        # 等量持有最近hold_days个交易日推荐的股票
        if 'data_df' not in context.options:
            context.options['data_df'] = context.options['data'].read_df()
        date_col = context.options['data_df']['date']
        df = context.options['data_df'][(date_col >= data_start_date) & (date_col <= data_end_date)]
        # 应该持有的股票
        to_hold_instruments = set(df['instrument'])
    
        # 卖出不再持有的
        for e, p in context.portfolio.positions.items():
            if e.symbol not in to_hold_instruments:
                # 平仓
                context.order_target(e, 0)
    
        # 平衡:等量持有股票
        for instrument in to_hold_instruments:
            context.order_target_percent(context.symbol(instrument), 1.0 / len(to_hold_instruments))
    
        # 返回True,如果返回 False,之后的函数将跳过
        return True
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m10_run_bigquant_run(weibo_ds, instrument_ds):
        import re
        cards = weibo_ds.read_pickle()
        instrument_df = instrument_ds.read_df()
        log = T.BigLogger('微博解析')
        log.info('解析用户微博 ..')
    
        blog_cards = [c for c in cards if c['card_type'] == 9 and 'title' not in c['mblog']]
    
        names = list(instrument_df['name'])
        instruments = list(instrument_df['instrument'])
    
        keywords = {}
        for i in range(len(instrument_df)):
            name = instrument_df['name'].iloc[i]
            instrument = instrument_df['instrument'].iloc[i]
            keywords[name.strip('*')] = instrument
            keywords[instrument[:-4]] = instrument
        stock_re = re.compile('|'.join(keywords.keys()))
    
        items = []
        now_year = datetime.datetime.now().year
        for card in blog_cards:
            mblog = card['mblog']
            text = mblog['raw_text'] if 'raw_text' in mblog else mblog['text']
            created_at = mblog['created_at']
            # 跳过近期的微博,比如 2小时前这样的,用处不大
            if '-' not in created_at:
                continue
            if len(created_at) < 10:
                created_at = '%s-%s' % (now_year, created_at)
            stocks = stock_re.findall(text)
            stocks = set([keywords[stock] for stock in stocks])
            for stock in stocks:
                items.append([created_at, stock])
    
        df = pd.DataFrame(items, columns=['date', 'instrument'])
        df['date'] = pd.to_datetime(df['date'])
    
        data_ds = DataSource.write_df(df)
    
        data = {
            'start_date': df['date'].min().strftime('%Y-%m-%d'),
            'instruments': list(set(df['instrument'])),
            'end_date': df['date'].max().strftime('%Y-%m-%d'),
        }
        output_instrument_ds = DataSource.write_pickle(data)
    
        log.info('共有 %s 条股票推荐, start_date=%s, end_date=%s, instruments=%s' % (
            len(df),
            data['start_date'],
            data['end_date'],
            len(data['instruments'])
        ))
    
        return Outputs(data_1=data_ds, data_2=output_instrument_ds)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m10_post_run_bigquant_run(outputs):
        return outputs
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m1_handle_data_bigquant_run(context, data):
        # curr_data:用于当前handle_bar,各处理函数可以用 curr_data 传递数据
        context.curr_data = {}
        if 'handle_bar_functions' in context.options:
            for func in context.options['handle_bar_functions']:
                if not func(context, data):
                    # 如果有处理函数返回False,则表示跳过后续执行
                    return
    
    # 回测引擎:准备数据,只执行一次
    def m1_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    def m1_initialize_bigquant_run(context):
        if 'initialize_functions' in context.options:
            for func in context.options['initialize_functions']:
                if not func(context):
                    # 如果有处理函数返回False,则表示跳过后续执行
                    return
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m1_before_trading_start_bigquant_run(context, data):
        pass
    
    
    g = T.Graph({
    
        'm4': 'M.use_datasource.v1',
        'm4.datasource_id': 'instruments_CN_STOCK_A',
        'm4.start_date': '2019-02-14',
        'm4.end_date': '2019-02-14',
    
        'm2': 'M.trade_func_customized_buy.v1',
        'm2.func': m2_func_bigquant_run,
        'm2.param_1': '10',
        'm2.param_2': '',
        'm2.param_3': '',
    
        'm5': 'M.weibo_user_posts_fetcher.v12',
        'm5.user_name': '但斌',
        'm5.count': 13600,
        'm5.cookie_sub': '_2A25xbl7wDeRhGeVP7FMQ9SzEyj6IHXVSkWK4rDV6PUJbktAKLRDVkW1NTPR2k3qXfX231UQyj4gSDIECS_CL7Glx',
        'm5.since_id': '--',
    
        'm10': 'M.cached.v3',
        'm10.input_1': T.Graph.OutputPort('m5.data_1'),
        'm10.input_2': T.Graph.OutputPort('m4.data'),
        'm10.run': m10_run_bigquant_run,
        'm10.post_run': m10_post_run_bigquant_run,
        'm10.input_ports': '',
        'm10.params': '{}',
        'm10.output_ports': '',
    
        'm6': 'M.trade_func_set_commission.v1',
        'm6.mode': '订单/PerOrder',
        'm6.buy_cost': 0,
        'm6.sell_cost': 0,
        'm6.min_cost': 0,
    
        'm1': 'M.tradex.v1',
        'm1.instruments': T.Graph.OutputPort('m10.data_2'),
        'm1.initialize_functions': T.Graph.OutputPort('m6.functions'),
        'm1.handle_bar_functions': T.Graph.OutputPort('m2.functions'),
        'm1.options_data': T.Graph.OutputPort('m10.data_1'),
        'm1.start_date': '',
        'm1.end_date': '',
        'm1.handle_data': m1_handle_data_bigquant_run,
        'm1.prepare': m1_prepare_bigquant_run,
        'm1.initialize': m1_initialize_bigquant_run,
        'm1.before_trading_start': m1_before_trading_start_bigquant_run,
        'm1.volume_limit': 0.0001,
        'm1.order_price_field_buy': 'open',
        'm1.order_price_field_sell': 'open',
        'm1.capital_base': 1000000,
        'm1.auto_cancel_non_tradable_orders': True,
        'm1.data_frequency': 'daily',
        'm1.price_type': '后复权',
        'm1.product_type': '股票',
        'm1.plot_charts': True,
        'm1.backtest_only': False,
    })
    
    # g.run({})
    
    
    def m3_run_bigquant_run(bq_graph, inputs):
        g = bq_graph
    
        results = []
        for hold_days in [1, 5, 10, 20]:
            print('---------- 持有 %s 个交易日' % hold_days)
            parameters = {'m2.param_1': hold_days}
            results.append(g.run(parameters))
    
        return results
    
    
    m3 = M.hyper_run.v1(
        run=m3_run_bigquant_run,
        run_now=True,
        bq_graph=g
    )
    
    ---------- 持有 1 个交易日
    
    • 收益率23.28%
    • 年化收益率44.97%
    • 基准收益率-4.41%
    • 阿尔法0.44
    • 贝塔0.86
    • 夏普比率1.52
    • 胜率0.54
    • 盈亏比1.46
    • 收益波动率24.5%
    • 信息比率0.19
    • 最大回撤7.29%
    ---------- 持有 5 个交易日
    
    • 收益率4.63%
    • 年化收益率8.37%
    • 基准收益率-4.41%
    • 阿尔法0.16
    • 贝塔0.91
    • 夏普比率0.33
    • 胜率0.48
    • 盈亏比1.3
    • 收益波动率24.12%
    • 信息比率0.08
    • 最大回撤15.55%
    ---------- 持有 10 个交易日
    
    • 收益率1.62%
    • 年化收益率2.88%
    • 基准收益率-4.41%
    • 阿尔法0.11
    • 贝塔0.99
    • 夏普比率0.12
    • 胜率0.49
    • 盈亏比0.97
    • 收益波动率25.17%
    • 信息比率0.06
    • 最大回撤16.24%
    ---------- 持有 20 个交易日
    
    In [15]:
    print(1232)
    
    1232
    
    In [ ]: