复制链接
克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-202:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-209:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-202:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-53:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-209:input_data","from_node_id":"-202:data"},{"to_node_id":"-184:input_data","from_node_id":"-209:data"},{"to_node_id":"-53:options_data","from_node_id":"-1575:data"},{"to_node_id":"-1575:input_data","from_node_id":"-184:data"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nma1=mean(close_0,5)\nma2=mean(close_0,10)\nma3=mean(close_0,20)\nv_mean=mean(volume_0,5)\nt1=where(((close_0>=ma1) & (close_0>=ma2) & (close_0>=ma3)),1,0)\nt2=where(((close_1<shift(ma1,1)) & (close_1<shift(ma2,1)) & (close_1<shift(ma3,1))),1,0)\nt3=where(volume_0>=3*v_mean,1,0)\nt4=where((close_0-low_0)/(high_0-low_0)>0.7,1,0)\nsignal=where((min(t1,t2,t3,t4)==1),1,0)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2022-01-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2022-11-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-202","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"30","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-202"},{"name":"features","node_id":"-202"}],"output_ports":[{"name":"data","node_id":"-202"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-209","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-209"},{"name":"features","node_id":"-209"}],"output_ports":[{"name":"data","node_id":"-209"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-53","module_id":"BigQuantSpace.trade.trade-v4","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"initialize","value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n context.mydata = context.options['data'].read_df()\n context.mydata = context.mydata[context.mydata.signal==1]\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 回测引擎:每日数据处理函数,每天执行一次\n today = data.current_dt.strftime('%Y-%m-%d') # 日期\n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表和对应的最新市值\n stock_hold_now = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.portfolio.positions.items()}\n hold_num=len(stock_hold_now)\n \n # 每日买入金额不超过总资产额一半\n cash_for_buy = min(context.portfolio.cash,context.portfolio.portfolio_value*0.5)\n \n now_data = context.mydata[context.mydata.date==today]\n if len(now_data)>10:\n now_data=now_data.iloc[0:10]\n elif len(now_data)==0: \n return\n# display(now_data)\n buy_stock = now_data.instrument.unique()\n sell_stock = stock_hold_now.keys()\n\n # 卖出\n for instrument in sell_stock:\n if data.can_trade(context.symbol(instrument)):\n context.order_target_percent(context.symbol(instrument), 0)\n\n # 买入\n stock_to_buy_num = len(buy_stock)\n print(today,buy_stock)\n for instrument in buy_stock:\n # 使用当日可用现金等资金比例下单买入\n cash = cash_for_buy / stock_to_buy_num\n if data.can_trade(context.symbol(instrument)):\n # 整百下单\n current_price = data.current(context.symbol(instrument), 'price')\n amount = math.floor(cash / current_price / 100) * 100\n context.order(context.symbol(instrument), amount)\n \n","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"","type":"Literal","bound_global_parameter":null},{"name":"volume_limit","value":0.025,"type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"open","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"close","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":1000000,"type":"Literal","bound_global_parameter":null},{"name":"auto_cancel_non_tradable_orders","value":"True","type":"Literal","bound_global_parameter":null},{"name":"data_frequency","value":"daily","type":"Literal","bound_global_parameter":null},{"name":"price_type","value":"真实价格","type":"Literal","bound_global_parameter":null},{"name":"product_type","value":"股票","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-53"},{"name":"options_data","node_id":"-53"},{"name":"history_ds","node_id":"-53"},{"name":"benchmark_ds","node_id":"-53"},{"name":"trading_calendar","node_id":"-53"}],"output_ports":[{"name":"raw_perf","node_id":"-53"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-1575","module_id":"BigQuantSpace.dropnan.dropnan-v2","parameters":[],"input_ports":[{"name":"input_data","node_id":"-1575"},{"name":"features","node_id":"-1575"}],"output_ports":[{"name":"data","node_id":"-1575"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-184","module_id":"BigQuantSpace.chinaa_stock_filter.chinaa_stock_filter-v1","parameters":[{"name":"index_constituent_cond","value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%8150%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%8150%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B2%AA%E6%B7%B1300%22%2C%22displayValue%22%3A%22%E6%B2%AA%E6%B7%B1300%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81500%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81500%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81800%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81800%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%81180%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%81180%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81100%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81100%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B7%B1%E8%AF%81100%22%2C%22displayValue%22%3A%22%E6%B7%B1%E8%AF%81100%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%811000%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%811000%22%2C%22selected%22%3Afalse%7D%5D%7D","type":"Literal","bound_global_parameter":null},{"name":"board_cond","value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E6%B7%B1%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22displayValue%22%3A%22%E6%B7%B1%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%88%9B%E4%B8%9A%E6%9D%BF%22%2C%22displayValue%22%3A%22%E5%88%9B%E4%B8%9A%E6%9D%BF%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E7%A7%91%E5%88%9B%E6%9D%BF%22%2C%22displayValue%22%3A%22%E7%A7%91%E5%88%9B%E6%9D%BF%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%8C%97%E4%BA%A4%E6%89%80%22%2C%22displayValue%22%3A%22%E5%8C%97%E4%BA%A4%E6%89%80%22%2C%22selected%22%3Afalse%7D%5D%7D","type":"Literal","bound_global_parameter":null},{"name":"industry_cond","value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E4%BA%A4%E9%80%9A%E8%BF%90%E8%BE%93%22%2C%22displayValue%22%3A%22%E4%BA%A4%E9%80%9A%E8%BF%90%E8%BE%93%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%BC%91%E9%97%B2%E6%9C%8D%E5%8A%A1%22%2C%22displayValue%22%3A%22%E4%BC%91%E9%97%B2%E6%9C%8D%E5%8A%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%BC%A0%E5%AA%92%2F%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1%22%2C%22displayValue%22%3A%22%E4%BC%A0%E5%AA%92%2F%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%85%AC%E7%94%A8%E4%BA%8B%E4%B8%9A%22%2C%22displayValue%22%3A%22%E5%85%AC%E7%94%A8%E4%BA%8B%E4%B8%9A%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%86%9C%E6%9E%97%E7%89%A7%E6%B8%94%22%2C%22displayValue%22%3A%22%E5%86%9C%E6%9E%97%E7%89%A7%E6%B8%94%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%8C%96%E5%B7%A5%22%2C%22displayValue%22%3A%22%E5%8C%96%E5%B7%A5%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%8C%BB%E8%8D%AF%E7%94%9F%E7%89%A9%22%2C%22displayValue%22%3A%22%E5%8C%BB%E8%8D%AF%E7%94%9F%E7%89%A9%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%95%86%E4%B8%9A%E8%B4%B8%E6%98%93%22%2C%22displayValue%22%3A%22%E5%95%86%E4%B8%9A%E8%B4%B8%E6%98%93%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%9B%BD%E9%98%B2%E5%86%9B%E5%B7%A5%22%2C%22displayValue%22%3A%22%E5%9B%BD%E9%98%B2%E5%86%9B%E5%B7%A5%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%AE%B6%E7%94%A8%E7%94%B5%E5%99%A8%22%2C%22displayValue%22%3A%22%E5%AE%B6%E7%94%A8%E7%94%B5%E5%99%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%BB%BA%E7%AD%91%E6%9D%90%E6%96%99%2F%E5%BB%BA%E7%AD%91%E5%BB%BA%E6%9D%90%22%2C%22displayValue%22%3A%22%E5%BB%BA%E7%AD%91%E6%9D%90%E6%96%99%2F%E5%BB%BA%E7%AD%91%E5%BB%BA%E6%9D%90%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%BB%BA%E7%AD%91%E8%A3%85%E9%A5%B0%22%2C%22displayValue%22%3A%22%E5%BB%BA%E7%AD%91%E8%A3%85%E9%A5%B0%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%88%BF%E5%9C%B0%E4%BA%A7%22%2C%22displayValue%22%3A%22%E6%88%BF%E5%9C%B0%E4%BA%A7%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9C%89%E8%89%B2%E9%87%91%E5%B1%9E%22%2C%22displayValue%22%3A%22%E6%9C%89%E8%89%B2%E9%87%91%E5%B1%9E%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9C%BA%E6%A2%B0%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E6%9C%BA%E6%A2%B0%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B1%BD%E8%BD%A6%2F%E4%BA%A4%E8%BF%90%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E6%B1%BD%E8%BD%A6%2F%E4%BA%A4%E8%BF%90%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%94%B5%E5%AD%90%22%2C%22displayValue%22%3A%22%E7%94%B5%E5%AD%90%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%94%B5%E6%B0%94%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E7%94%B5%E6%B0%94%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%BA%BA%E7%BB%87%E6%9C%8D%E8%A3%85%22%2C%22displayValue%22%3A%22%E7%BA%BA%E7%BB%87%E6%9C%8D%E8%A3%85%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%BB%BC%E5%90%88%22%2C%22displayValue%22%3A%22%E7%BB%BC%E5%90%88%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E8%AE%A1%E7%AE%97%E6%9C%BA%22%2C%22displayValue%22%3A%22%E8%AE%A1%E7%AE%97%E6%9C%BA%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E8%BD%BB%E5%B7%A5%E5%88%B6%E9%80%A0%22%2C%22displayValue%22%3A%22%E8%BD%BB%E5%B7%A5%E5%88%B6%E9%80%A0%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%80%9A%E4%BF%A1%22%2C%22displayValue%22%3A%22%E9%80%9A%E4%BF%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%87%87%E6%8E%98%22%2C%22displayValue%22%3A%22%E9%87%87%E6%8E%98%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%92%A2%E9%93%81%22%2C%22displayValue%22%3A%22%E9%92%A2%E9%93%81%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%93%B6%E8%A1%8C%22%2C%22displayValue%22%3A%22%E9%93%B6%E8%A1%8C%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%9D%9E%E9%93%B6%E9%87%91%E8%9E%8D%22%2C%22displayValue%22%3A%22%E9%9D%9E%E9%93%B6%E9%87%91%E8%9E%8D%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%A3%9F%E5%93%81%E9%A5%AE%E6%96%99%22%2C%22displayValue%22%3A%22%E9%A3%9F%E5%93%81%E9%A5%AE%E6%96%99%22%2C%22selected%22%3Afalse%7D%5D%7D","type":"Literal","bound_global_parameter":null},{"name":"st_cond","value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%AD%A3%E5%B8%B8%22%2C%22displayValue%22%3A%22%E6%AD%A3%E5%B8%B8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22ST%22%2C%22displayValue%22%3A%22ST%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22*ST%22%2C%22displayValue%22%3A%22*ST%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9A%82%E5%81%9C%E4%B8%8A%E5%B8%82%22%2C%22displayValue%22%3A%22%E6%9A%82%E5%81%9C%E4%B8%8A%E5%B8%82%22%2C%22selected%22%3Afalse%7D%5D%7D","type":"Literal","bound_global_parameter":null},{"name":"delist_cond","value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%80%80%E5%B8%82%22%2C%22displayValue%22%3A%22%E9%80%80%E5%B8%82%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%9D%9E%E9%80%80%E5%B8%82%22%2C%22displayValue%22%3A%22%E9%9D%9E%E9%80%80%E5%B8%82%22%2C%22selected%22%3Atrue%7D%5D%7D","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-184"}],"output_ports":[{"name":"data","node_id":"-184"},{"name":"left_data","node_id":"-184"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='1191,112.05697631835938,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='875,116,200,200'/><node_position Node='-202' Position='1064,222,200,200'/><node_position Node='-209' Position='1063,293,200,200'/><node_position Node='-53' Position='980,507,200,200'/><node_position Node='-1575' Position='1053,434,200,200'/><node_position Node='-184' Position='1068,359,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [35]:
    # 本代码由可视化策略环境自动生成 2022年11月5日 15:13
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m3_initialize_bigquant_run(context):
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        context.mydata = context.options['data'].read_df()
        context.mydata = context.mydata[context.mydata.signal==1]
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m3_handle_data_bigquant_run(context, data):
        # 回测引擎:每日数据处理函数,每天执行一次
        today = data.current_dt.strftime('%Y-%m-%d') # 日期
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表和对应的最新市值
        stock_hold_now = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.portfolio.positions.items()}
        hold_num=len(stock_hold_now)
        
        # 每日买入金额不超过总资产额一半
        cash_for_buy = min(context.portfolio.cash,context.portfolio.portfolio_value*0.5)
        
        now_data = context.mydata[context.mydata.date==today]
        if len(now_data)>10:
            now_data=now_data.iloc[0:10]
        elif len(now_data)==0: 
            return
    #     display(now_data)
        buy_stock = now_data.instrument.unique()
        sell_stock = stock_hold_now.keys()
    
        # 卖出
        for instrument in sell_stock:
            if data.can_trade(context.symbol(instrument)):
                context.order_target_percent(context.symbol(instrument), 0)
    
        # 买入
        stock_to_buy_num = len(buy_stock)
        print(today,buy_stock)
        for instrument in buy_stock:
            # 使用当日可用现金等资金比例下单买入
            cash = cash_for_buy / stock_to_buy_num
            if data.can_trade(context.symbol(instrument)):
                # 整百下单
                current_price = data.current(context.symbol(instrument), 'price')
                amount = math.floor(cash / current_price / 100) * 100
                context.order(context.symbol(instrument), amount)
      
    
    
    m1 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    ma1=mean(close_0,5)
    ma2=mean(close_0,10)
    ma3=mean(close_0,20)
    v_mean=mean(volume_0,5)
    t1=where(((close_0>=ma1) & (close_0>=ma2) & (close_0>=ma3)),1,0)
    t2=where(((close_1<shift(ma1,1)) & (close_1<shift(ma2,1)) & (close_1<shift(ma3,1))),1,0)
    t3=where(volume_0>=3*v_mean,1,0)
    t4=where((close_0-low_0)/(high_0-low_0)>0.7,1,0)
    signal=where((min(t1,t2,t3,t4)==1),1,0)"""
    )
    
    m2 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2022-01-01'),
        end_date=T.live_run_param('trading_date', '2022-11-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m7 = M.general_feature_extractor.v7(
        instruments=m2.data,
        features=m1.data,
        start_date='',
        end_date='',
        before_start_days=30
    )
    
    m8 = M.derived_feature_extractor.v3(
        input_data=m7.data,
        features=m1.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m5 = M.chinaa_stock_filter.v1(
        input_data=m8.data,
        index_constituent_cond=['全部'],
        board_cond=['上证主板', '深证主板', '创业板'],
        industry_cond=['全部'],
        st_cond=['正常'],
        delist_cond=['非退市'],
        output_left_data=False
    )
    
    m4 = M.dropnan.v2(
        input_data=m5.data
    )
    
    m3 = M.trade.v4(
        instruments=m2.data,
        options_data=m4.data,
        start_date='',
        end_date='',
        initialize=m3_initialize_bigquant_run,
        handle_data=m3_handle_data_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='真实价格',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark='000300.HIX'
    )
    
    2022-01-04 ['300303.SZA']
    2022-01-11 ['301078.SZA']
    2022-01-12 ['300933.SZA']
    2022-01-17 ['000158.SZA']
    2022-01-18 ['600315.SHA']
    2022-01-24 ['603839.SHA']
    2022-01-25 ['601069.SHA']
    2022-01-26 ['603955.SHA']
    2022-02-07 ['300284.SZA' '300330.SZA']
    2022-02-14 ['301007.SZA']
    2022-02-15 ['002703.SZA']
    2022-02-16 ['000755.SZA' '300946.SZA']
    2022-02-18 ['300738.SZA']
    2022-02-21 ['603558.SHA']
    2022-02-23 ['000532.SZA' '000987.SZA' '300706.SZA']
    2022-02-24 ['000659.SZA']
    2022-02-25 ['002040.SZA' '002679.SZA' '601008.SHA' '601188.SHA']
    2022-03-02 ['600639.SHA']
    2022-03-07 ['001206.SZA' '601811.SHA']
    2022-03-09 ['600186.SHA' '601368.SHA']
    2022-03-10 ['600829.SHA' '603015.SHA']
    2022-03-16 ['002666.SZA']
    2022-03-17 ['003018.SZA']
    2022-03-18 ['300234.SZA' '603578.SHA']
    2022-03-23 ['300423.SZA']
    2022-03-25 ['300582.SZA']
    2022-03-28 ['300793.SZA']
    2022-03-30 ['300801.SZA']
    
    2022-04-08 ['600243.SHA']
    2022-04-11 ['300240.SZA' '600073.SHA']
    2022-04-12 ['000848.SZA']
    2022-04-14 ['300218.SZA']
    2022-04-15 ['300991.SZA']
    2022-04-19 ['300411.SZA']
    2022-04-20 ['000008.SZA' '605138.SHA']
    2022-04-22 ['002763.SZA' '300840.SZA' '300879.SZA' '603221.SHA']
    2022-04-25 ['300062.SZA' '300564.SZA' '600805.SHA' '600909.SHA']
    2022-04-26 ['600578.SHA']
    2022-05-25 ['000931.SZA']
    2022-06-08 ['600023.SHA']
    2022-06-09 ['600610.SHA']
    2022-06-15 ['002445.SZA']
    2022-06-20 ['002798.SZA']
    2022-06-24 ['600620.SHA']
    2022-06-27 ['300027.SZA']
    2022-07-01 ['600310.SHA' '605162.SHA']
    2022-07-05 ['600935.SHA']
    2022-07-06 ['002589.SZA']
    2022-07-07 ['000751.SZA']
    2022-07-11 ['300006.SZA' '301075.SZA']
    2022-07-13 ['002115.SZA' '002134.SZA']
    2022-07-15 ['000021.SZA' '300319.SZA' '301196.SZA']
    2022-07-18 ['300262.SZA' '300740.SZA']
    2022-07-22 ['600509.SHA']
    2022-07-25 ['301193.SZA']
    2022-07-26 ['002306.SZA']
    2022-07-29 ['601619.SHA']
    2022-08-01 ['300720.SZA']
    2022-08-02 ['000505.SZA' '600127.SHA']
    2022-08-03 ['000691.SZA']
    2022-08-05 ['601990.SHA']
    2022-08-11 ['600070.SHA']
    2022-08-19 ['002280.SZA' '603680.SHA']
    2022-08-22 ['300950.SZA' '605507.SHA']
    2022-08-23 ['000589.SZA' '000597.SZA' '002319.SZA']
    2022-08-24 ['600482.SHA' '603991.SHA' '603992.SHA']
    
    2022-08-26 ['300530.SZA']
    2022-08-29 ['003020.SZA' '300622.SZA' '301042.SZA']
    2022-08-30 ['300134.SZA']
    2022-09-01 ['000514.SZA']
    2022-09-02 ['300045.SZA']
    2022-09-05 ['600722.SHA']
    2022-09-06 ['300082.SZA']
    2022-09-09 ['002589.SZA' '301033.SZA' '600836.SHA' '601990.SHA']
    2022-09-14 ['300715.SZA' '301077.SZA']
    2022-09-15 ['300536.SZA' '600192.SHA' '603269.SHA']
    2022-09-16 ['002197.SZA' '002701.SZA' '002819.SZA']
    2022-09-19 ['300758.SZA']
    2022-09-23 ['605336.SHA']
    2022-09-26 ['000036.SZA' '002394.SZA']
    2022-10-10 ['300967.SZA' '600186.SHA']
    2022-10-11 ['300684.SZA' '600369.SHA']
    2022-10-12 ['603042.SHA']
    2022-10-21 ['600644.SHA']
    2022-10-25 ['002790.SZA' '300675.SZA']
    2022-10-26 ['000531.SZA']
    
    • 收益率-4.18%
    • 年化收益率-5.26%
    • 基准收益率-26.44%
    • 阿尔法0.14
    • 贝塔0.4
    • 夏普比率-0.08
    • 胜率0.47
    • 盈亏比1.21
    • 收益波动率33.62%
    • 信息比率0.07
    • 最大回撤25.8%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-0166f97b92ad42718a3bc2705babed30"}/bigcharts-data-end