{"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"-339:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"to_node_id":"-339:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-346:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-362:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-213:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-355:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-2576:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"to_node_id":"-390:data1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"to_node_id":"-355:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-374:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-2158:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-346:input_data","from_node_id":"-339:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","from_node_id":"-346:data"},{"to_node_id":"-362:input_data","from_node_id":"-355:data"},{"to_node_id":"-2171:data2","from_node_id":"-362:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","from_node_id":"-213:model"},{"to_node_id":"-213:training_ds","from_node_id":"-2576:data"},{"to_node_id":"-374:options_data","from_node_id":"-390:data"},{"to_node_id":"-2158:features","from_node_id":"-956:data"},{"to_node_id":"-2178:features","from_node_id":"-956:data"},{"to_node_id":"-2178:input_data","from_node_id":"-2158:data"},{"to_node_id":"-440:input_1","from_node_id":"-2165:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","from_node_id":"-2171:data"},{"to_node_id":"-390:data2","from_node_id":"-2171:data"},{"to_node_id":"-2165:input_data","from_node_id":"-2178:data"},{"to_node_id":"-2171:data1","from_node_id":"-440:data_1"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2017-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-01-01","type":"Literal","bound_global_parameter":null},{"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-8"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","module_id":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","parameters":[{"name":"label_expr","value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html\n# 添加benchmark_99】【前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -3) / shift(open, -1)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.SHA","type":"Literal","bound_global_parameter":null},{"name":"drop_na_label","value":"True","type":"Literal","bound_global_parameter":null},{"name":"cast_label_int","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nclose_0/mean(close_0,5)\nclose_0/mean(close_0,10)\nclose_0/mean(close_0,20)\nclose_0/open_0\nopen_0/mean(close_0,5)\nopen_0/mean(close_0,10)\nopen_0/mean(close_0,20)\navg_turn_0/avg_turn_5\navg_turn_0/avg_turn_10\nmf_net_pct_main_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":3,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"inner","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"name":"data2","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","module_id":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","parameters":[{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"model","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"output_ports":[{"name":"predictions","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"name":"m_lazy_run","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-01-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2022-04-28","type":"Literal","bound_global_parameter":"交易日期"},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"300505.SZA\n002226.SZA","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":9,"comment":"预测数据,用于回测和模拟","comment_collapsed":false},{"node_id":"-339","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":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-339"},{"name":"features","node_id":"-339"}],"output_ports":[{"name":"data","node_id":"-339"}],"cacheable":true,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"-346","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":"-346"},{"name":"features","node_id":"-346"}],"output_ports":[{"name":"data","node_id":"-346"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-355","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":"258","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-355"},{"name":"features","node_id":"-355"}],"output_ports":[{"name":"data","node_id":"-355"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-362","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":"True","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":"-362"},{"name":"features","node_id":"-362"}],"output_ports":[{"name":"data","node_id":"-362"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-374","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 context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n #context.stock_count = 1\n context.stock_count = 10\n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n #context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, context.stock_count)])\n context.stock_weights = [1/context.stock_count for k in range(context.stock_count)] #半仓买入,每只股票等资金分配\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.2\n context.options['hold_days'] = 5\n\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"def getMa(today,context,instruments):\n # 加载原始数据\n import datetime\n stock_raw_data = D.history_data(instruments, today+datetime.timedelta(days=-40), today, ['date','close','low'])\n #print('11111',stock_raw_data)\n stock_raw_data=stock_raw_data.iloc[-20:] \n #stock_raw_data=stock_raw_data[:55]\n #print('22222',stock_raw_data)\n sumMa=0\n lastClose=0\n for index,row in stock_raw_data.iterrows():\n #print(index,row)\n sumMa += row['close']\n lastClose=row['close']\n \n # 包含多个周期均线值的股票数据\n # stock_ma_data = stock_raw_data.groupby('instrument').apply(ma_calculate)\n return [sumMa/20,lastClose]\n\n\n\n# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n #context.ranker_prediction.set_index('date')\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n today = data.current_dt.strftime('%Y-%m-%d')\n # 当日可用资金\n cash_for_buy = context.portfolio.cash\n \n # 获取当日买入列表,每天选取context.stock_count只\n buy_list=[]\n buy1_list = list(ranker_prediction[ranker_prediction.my1 == 1].instrument[:30])\n buy2_list = list(ranker_prediction[ranker_prediction.my2== 1].instrument[:10])\n print(today, '--买一选股-buy1_list==',buy1_list,'===买二选股-buy2_list:', len(buy2_list),buy2_list,)\n if len(buy1_list) > 0 :\n buy_list.append(buy1_list)\n if len(buy2_list) > 0 :\n buy_list.append(buy2_list)\n \n # 获取当前持仓资金\n stock_hold_now = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items() if p.amount>0} \n\n equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}\n \n # 需要卖出的股票:已有持仓中不在买入列表的股票\n #stock_to_sell = [ i for i in stock_hold_now if i not in buy_list ]\n stock_to_sell = [ i for i in stock_hold_now ]\n #stock_to_buy = [ i for i in buy_list if i not in stock_hold_now ]\n stock_to_buy1 = [] # [ i for i in buy1_list ] 只测试my2\n stock_to_buy2 = [ i for i in buy2_list ]\n \n #print(today,' 选股stock_to_buy: ',len(stock_to_buy),' 个: ',stock_to_buy)\n #print(today,' context.ranker_prediction ==: ',context.ranker_prediction)\n # print('ranker_prediction.dtypes',ranker_prediction.dtypes)\n\n # 处理一阳穿多线的买二准备 \n # for i, instrument in enumerate(stock_to_buy):\n # print(today, i,instrument )\n # dfinstrument=ranker_prediction[ranker_prediction.instrument==instrument]\n # junxians=list(dfinstrument['junxian'])\n # junxian=junxians[0]\n #print(today, i ,' junxian==',junxian)\n # if(junxian==1):\n # 通过标签赋值\n # dfinstrument.loc[0,'isReadyBuy2'] = 1\n #dfinstrument.loc[0,'date'] = '2022-03-25'\n # dfinstrument[dfinstrument['date'] == today] =str(today) + str(datetime.timedelta(days=1))\n #dfinstrument[dfinstrument['date'] == today] = (today.date()+datetime.timedelta(days=1)).strftime('%Y-%m-%d')\n #再处理非交易日和2天后数据也还有该条数据的问题\n # print(today,' append dfinstrument ',dfinstrument)\n # dfinstrument.set_index('date')\n # context.ranker_prediction.append(dfinstrument)\n\n \n # print(today,' after context.ranker_prediction ==: ',context.ranker_prediction) \n \n #stocks=len(stock_hold_now) #?\n stocksBuy1N=0\n stocksBuy2N=0\n stockBuy1_hold_now=[] \n stockBuy2_hold_now=[] \n # 卖出列表进行卖出操作\n if len(stock_to_sell)>0:\n for instrument in stock_to_sell:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n cur_position = context.portfolio.positions[sid].amount # 持仓\n if cur_position > 0 and data.can_trade(sid):\n instruments=[]\n instruments.append(instrument) \n #ri10=getMa(data.current_dt,context,instruments)\n #print('df after get ma 55==',ri55)\n try :\n a=getMa(data.current_dt,context,instruments)\n ri20=a[0]\n lastClose=a[1]\n except :\n ri20=0\n lastClose=0\n #print(instrument,today,'ma10===',ri10,'lastClose===',lastClose)\n \n stock_market_price = data.current(context.symbol(instrument), 'price') # 最新市场价格\n stock_market_today_high = data.current(context.symbol(instrument), 'high') #今日最高价 \n stock_market_today_close = data.current(context.symbol(instrument), 'close') #今日收盘价\n last_sale_date = equities[instrument].last_sale_date # 上次交易日期\n last_cost_price = equities[instrument].cost_basis # 上次交易金额\n delta_days = data.current_dt - last_sale_date \n hold_days = delta_days.days # 持仓天数\n # 最高收益\n #high_return = (highclose_price_since_buy-last_cost_price)/last_cost_price\n \n target_return = stock_market_today_close/last_cost_price\n #\n isBuy1=stock_hold_now[instrument]/context.portfolio.portfolio_value\n #print(instrument,' isBuy1 or buy2 ==',isBuy1)\n if isBuy1< 1/30 : #处理买一订单,买一股票池300,持仓10天轮动,每天30只\n \n if hold_days>=10 :\n context.order_target(sid, 0)\n print(today,'买一超期卖出 :','收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n #stocks = stocks-1\n #elif target_return>=1.15 :\n # context.order_target(sid, 0)\n # print(today,'盈利卖出 :','收益: ',target_return,sid)\n # cash_for_buy += stock_hold_now[instrument]\n # stocks = stocks-1\n #elif lastClose<ri10 :\n # context.order_target(sid, 0)\n # print(today,' 跌破10日线止损卖出 ri10=:',ri10,' 收益: ',target_return,sid)\n # cash_for_buy += stock_hold_now[instrument]\n # stocks = stocks-1\n elif target_return<=0.92 :\n context.order_target(sid, 0)\n print(today,'买一止损卖出 :','收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n #stocks = stocks-1\n else:\n stockBuy1_hold_now.append(instrument)\n stocksBuy1N=stocksBuy1N+1\n else : #处理买二订单\n stockBuy2_hold_now.append(instrument)\n if hold_days>=5 :\n context.order_target(sid, 0)\n print(today,'买二超期卖出 :','收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n #stocks = stocks-1\n elif target_return>=1.1 :\n context.order_target(sid, 0)\n print(today,'买二盈利卖出 :','收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n #stocks = stocks-1\n elif lastClose<ri20 :\n context.order_target(sid, 0)\n print(today,' 买二跌破20日线止损卖出 ri20=:',ri20,' 收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n #stocks = stocks-1\n elif target_return<=0.95 :\n context.order_target(sid, 0)\n print(today,'买二止损卖出 :','收益: ',target_return,sid)\n cash_for_buy += stock_hold_now[instrument]\n # stocks = stocks-1\n else:\n stockBuy2_hold_now.append(instrument)\n stocksBuy2N=stocksBuy2N+1 \n \n #context.order_target_percent(sid, 0) # 全部卖出\n # 如果是早盘买早盘卖,卖出的资金可以用于买股票,此时应将下面的注释打开,卖出股票时更新可用现金;\n # 如果是早盘买尾盘卖,则卖出时不需更新可用现金,因为尾盘卖出股票所得现金无法使用\n #cash_for_buy += stock_hold_now[instrument]\n \n # 买入列表执行买操作\n #if len(stock_to_buy)>0:\n # for instrument,weight in zip(stock_to_buy,context.stock_weights):\n # sid = context.symbol(instrument) # 将标的转化为equity格式\n # if data.can_trade(sid):\n # context.order_target_value(sid, min(cash_for_buy,context.portfolio.portfolio_value*0.5)) # 买入 \n\n #print(today,'--stockBuy1_hold_now--=:',stockBuy1_hold_now)\n stockBuy1_hold_now\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n #buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n buy1N=min(30,(300-stocksBuy1N))\n buy2N=min(10,(20-stocksBuy2N))\n buy1_instruments = []\n if len(stock_to_buy1) > 0 :\n buy1_instruments=list(stock_to_buy1[:buy1N])\n buy2_instruments = []\n if len(stock_to_buy2) > 0 :\n buy2_instruments=list(stock_to_buy2[:buy2N])\n #print(today,' buy_instruments:',buy_instruments,' 权重: ',buy_cash_weights)\n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n for i, instrument in enumerate(buy1_instruments):\n #cash = cash_for_buy * buy_cash_weights[i] \n #cash = context.portfolio.portfolio_value * buy_cash_weights[i]\n #用20分1的资金买一(300zhi)\n cash = (cash_for_buy/20)/(200-stocksBuy1N)\n #print('cash_for_buy==',cash_for_buy, ' cash==',cash)\n #if cash > max_cash_per_instrument - stock_hold_now.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n # cash = max_cash_per_instrument - stock_hold_now.get(instrument, 0)\n if cash > 0:\n if instrument not in stockBuy1_hold_now : #不重复买入\n context.order_value(context.symbol(instrument), cash)\n # print(today,' 买入一买 ',instrument)\n \n for i, instrument in enumerate(buy2_instruments):\n #cash = cash_for_buy * buy_cash_weights[i] \n #cash = context.portfolio.portfolio_value * buy_cash_weights[i]\n cash = (cash_for_buy*0.9)/(20-stocksBuy2N)\n #print('cash_for_buy==',cash_for_buy, ' cash==',cash)\n # if cash > max_cash_per_instrument - stock_hold_now.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n # cash = max_cash_per_instrument - stock_hold_now.get(instrument, 0)\n if cash > 0:\n #if instrument in stockBuy1_hold_now :\n context.order_value(context.symbol(instrument), cash)\n print(today,' 买入二买 ',instrument)\n # else:\n # print(today,' 发现二买,但没有一买,放弃买入:---',instrument)\n else:\n print(today,' 无资金买入二买 ',instrument)\n \n ","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","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":"twap_1","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"twap_1","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"10000000","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":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-374"},{"name":"options_data","node_id":"-374"},{"name":"history_ds","node_id":"-374"},{"name":"benchmark_ds","node_id":"-374"},{"name":"trading_calendar","node_id":"-374"}],"output_ports":[{"name":"raw_perf","node_id":"-374"}],"cacheable":false,"seq_num":19,"comment":"","comment_collapsed":true},{"node_id":"-213","module_id":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","parameters":[{"name":"learning_algorithm","value":"排序","type":"Literal","bound_global_parameter":null},{"name":"number_of_leaves","value":30,"type":"Literal","bound_global_parameter":null},{"name":"minimum_docs_per_leaf","value":1000,"type":"Literal","bound_global_parameter":null},{"name":"number_of_trees","value":20,"type":"Literal","bound_global_parameter":null},{"name":"learning_rate","value":0.1,"type":"Literal","bound_global_parameter":null},{"name":"max_bins","value":1023,"type":"Literal","bound_global_parameter":null},{"name":"feature_fraction","value":1,"type":"Literal","bound_global_parameter":null},{"name":"data_row_fraction","value":1,"type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"ndcg_discount_base","value":1,"type":"Literal","bound_global_parameter":null},{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"-213"},{"name":"features","node_id":"-213"},{"name":"test_ds","node_id":"-213"},{"name":"base_model","node_id":"-213"}],"output_ports":[{"name":"model","node_id":"-213"},{"name":"feature_gains","node_id":"-213"},{"name":"m_lazy_run","node_id":"-213"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-2576","module_id":"BigQuantSpace.dropnan.dropnan-v2","parameters":[],"input_ports":[{"name":"input_data","node_id":"-2576"},{"name":"features","node_id":"-2576"}],"output_ports":[{"name":"data","node_id":"-2576"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-390","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"left","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-390"},{"name":"data2","node_id":"-390"}],"output_ports":[{"name":"data","node_id":"-390"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-956","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"#600335.SHA\n#300061.SZA\n#300364.SZA\n#002173.SZA\n#002433.SZA\n#601020.SHA\n#000545.SZA\n#000514.SZA\n#300505.SZA\n#002226.SZA\n#300299.SZA\n#600425.SHA\n#000632.SZA\n#002060.SZA\n\n#gaodianN5=where(ts_argmax(high_0, 258*5)<800,1,0)\n#gaodianN4=where(ts_argmax(high_0, 258*4)<800,1,0)\n#5年高点,1年按258个交易日算\n#isgaodian=max(gaodianN5,gaodianN4)\n\n#1年低点,1年按258个交易日算\n#didianN=ts_argmin(low_0, 258*1)\n#isdidian=where(didianN<200.0,1,0)\n\n#半年高点,1年按258个交易日算\nbanniangaodianN=ts_argmax(high_0, 128)\nisbanniangaodian=where(banniangaodianN<80.0,1,0)\n\n#timeperiod移动平均线\n#zhouma34=ta_ma(close_0, timeperiod=166)\n#timeperiod移动平均线\nzhouma55=ta_ma(close_0, timeperiod=258)\n#在周55均线之上,\nisupzhou55=where(close_0>zhouma55,1,0)\n#回调程度\nhuitiaodu=ts_max(high_0, 128)/low_1\n\n#反弹比例,选比例最高的10-20只交易,后面调试\n#yiniandidian=ts_min(low_0, 258*1)\nbanniangaodian=ts_max(high_0, 128*1)\n#fantanbili=banniangaodian/yiniandidian\n\n#macd1=ta_macd_macd_12_26_9_0\n#macd2=ta_macd_macdhist_12_26_9_0\n#macd3=ta_macd_macdsignal_12_26_9_0\n#sw1=swing_volatility_5_0 #振幅波动率,timeperiod=5* 取值: , 5, 10, 30, 60, 120, 240\n#sw2=swing_volatility_10_0\n#sw3=swing_volatility_30_0\n#sw4=swing_volatility_60_0\nvl1=volatility_5_0 #波动率,timeperiod=240* 取值: , 5, 10, 30, 60, 120, 240\nvl2=volatility_10_0\nvl3=volatility_30_0\n#vl4=volatility_60_0\n\n\nmacd_dif=ta_macd_dif(close_0/adjust_factor_0)\nmacd_h=ta_macd_hist(close_0/adjust_factor_0)\nduanqiup1=where(low_0>low_1,1,0)\nduanqiup2=where(macd_h>shift(macd_h,1),1,0)\nduanqiup=max(duanqiup1,duanqiup2)\n\n\n#st_status_0\n#my1==1&(vl2<vl3)&(vl2>0.012)&(vl2<0.038)&(macd1<0)&date>'2022-04-01'\n#my1=where((isbanniangaodian==1)&\\\n# (huitiaodu>1.2)&\\\n# (vl2<vl3)&(vl2>0.012)&(vl2<0.038)&(st_status_0==0),1,0)\n\nmy1=where((huitiaodu>1.2)&\\\n (vl2<vl3)&(vl2>0.012)&(vl2<0.038)&(st_status_0==0),1,0)\n\n#isgaodian==1&isdidian==1&isbanniangaodian==1&isbanniangaodian==1&fantanbili>1.5&date>='2022-03-08'\n#调试一下不要半年高点?只要回调度,不管什么时候回调的?涨停上穿也算\n\n#按前一天算ma,即线重合后第三天再买如\nma5=ta_ma(close_0, timeperiod=5)\nma10=ta_ma(close_0, timeperiod=10)\nma13=ta_ma(close_0, timeperiod=13)\nma20=ta_ma(close_0, timeperiod=20)\nma34=ta_ma(close_0, timeperiod=34)\nma55=ta_ma(close_0, timeperiod=55)\n\n#4-5线重合 真阳线 后面再调试是否要过滤returen0《5-8;-这样可以亏损幅度可以小一些;再调试回调幅度是否要大于1.5\n#junxian=where((ma5<=high_0) & (ma10<=high_0) & (ma13<=high_0) &(ma20<=high_0) & (ma34<=high_0) & (ma55<=high_0) &\\\n# (ma5 >=low_0) & (ma10>=low_0) & (ma13>=low_0) & (ma20>=low_0) & (ma34>=low_0) & (ma55>=low_0) &\\\n# (return_0>1.01)&(close_0>open_0)&(return_0<1.08)&(isbanniangaodian==1),1,0) \n#试试2日穿阳\njunxian=where((ma5<=high_0) & (ma10<=high_0) & (ma13<=high_0) &(ma20<=high_0) & (ma34<=high_0) & (ma55<=high_0) &\\\n (return_0>1.01)&(close_0>open_0)&(return_0<1.08),1,0) \n\nmaxline=max(ma5, ma10,ma13, ma20,ma34,ma55)\nminline=min(ma5, ma10,ma13, ma20,ma34,ma55)\nzhanshang55=close_0/maxline\n#4-5线重合度\njunxianchonghedu=minline/maxline\njunxianchonghedu5=shift(junxianchonghedu,5)\njunxianchonghedu18=shift(junxianchonghedu,18)\n# volume_* 第前 * 个交易日的交易量* 取值: 0 .. 20\n#一阳穿线需要放量1.5倍以上,后面调试. #nanmean(x, d), #过去 d 天 x 的均值(去除NaN值)\n\nfanliang=volume_0/volume_1 #放量\ndeaLn=deal_number_0/deal_number_1\ndaDan=fanliang/deaLn #交易笔数放量比不上交易额放量,说明是大单进入多,用大于1.18进行调试\n\n#my2ready=where((isbanniangaodian==1)&(junxian==1)&(zhanshang55>=1.0)&\n #(junxianchonghedu>0.94)&(huitiaodu>1.15)&(fanliang>1.45)&(daDan>1.18),1,0) #需要收拢条件\nmy2ready=where((junxian==1)&(zhanshang55>=1.0)&\\\n (junxianchonghedu>junxianchonghedu5)&(junxianchonghedu5>junxianchonghedu18)&\\\n (junxianchonghedu>0.95)&(huitiaodu>1.15)&(fanliang>1.5)&(daDan>1.2),1,0)\nmy2=where((shift(my2ready,1)==1)&(low_0>low_1)&(close_0>=ma5),1,0)\n#low_0>low_1这个条件太松了\n#最好不离55线太远,--my1使用\nnearMa55=ma55/close_0\n\nSW_code=industry_sw_level1_0\nmyrank=rank_fs_roe_ttm_0+rank_fs_net_profit_qoq_0-rank_pb_lf_0\n\npe_ttm_0 #滚动市盈率\nfs_eps_0 #每股收益\nfs_eps_yoy_0 #每股收益同比增长率\nfs_bps_0 #每股净资产\nfs_roa_ttm_0 #总资产报酬率 (TTM)\n\n#isbanniangaodian==1&junxian==1&zhanshang55>1&junxianchonghedu>0.95&huitiaodu>1.3&date>='2022-01-01'\nmy=max(my1,my2)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-956"}],"output_ports":[{"name":"data","node_id":"-956"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-2158","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":"580","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-2158"},{"name":"features","node_id":"-2158"}],"output_ports":[{"name":"data","node_id":"-2158"}],"cacheable":true,"seq_num":13,"comment":"","comment_collapsed":true},{"node_id":"-2165","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date>='2022-03-10'&my2==1","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":"-2165"}],"output_ports":[{"name":"data","node_id":"-2165"},{"name":"left_data","node_id":"-2165"}],"cacheable":true,"seq_num":14,"comment":"my1","comment_collapsed":true},{"node_id":"-2171","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"left","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-2171"},{"name":"data2","node_id":"-2171"}],"output_ports":[{"name":"data","node_id":"-2171"}],"cacheable":true,"seq_num":20,"comment":"","comment_collapsed":true},{"node_id":"-2178","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":"True","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":"-2178"},{"name":"features","node_id":"-2178"}],"output_ports":[{"name":"data","node_id":"-2178"}],"cacheable":true,"seq_num":21,"comment":"","comment_collapsed":true},{"node_id":"-440","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n # 计算行业行业收益\n industry_df = DataSource(\"basic_info_index_CN_STOCK_A\").read()\n\n SW_industry_list = industry_df[industry_df.instrument.str.startswith('SW')].instrument.tolist()\n\n SW_industry_df = DataSource(\"bar1d_index_CN_STOCK_A\").read(SW_industry_list)\n\n SW_industry_ret = SW_industry_df.groupby('instrument').apply(calcu_ret)\n SW_industry_ret.reset_index(inplace=True, drop=True)\n SW_industry_ret['date'] = SW_industry_ret['date'].apply(lambda x:x.strftime('%Y-%m-%d'))\n print('after apply SW_industry_ret==\\n',SW_industry_ret) \n \n #????daily_buy_industry_dict = {dt:seek_head_industry(SW_industry_ret.set_index('date').loc[dt]) for dt in list(set(SW_industry_ret.date))}\n #print('daily_buy_industry_dict==\\n',daily_buy_industry_dict) \n \n daily_stock = input_1.read()\n daily_stock['SW_code'] = daily_stock['SW_code'].apply(lambda x:'SW'+str(x)+'.HIX')\n print('daily_stock=111=\\n',daily_stock[:10]) \n #daily_stock = daily_stock.groupby(['date', 'industry_sw_level1_0']).apply(seek_head_stock).reset_index()\n #print('daily_stock=222=\\n',daily_stock[:10]) \n buy_df = pd.DataFrame()\n \n print('daily_stock.SW_code.tolist()',daily_stock.SW_code.tolist())\n #for dt in list(set(SW_industry_ret.date)): t=test.loc[(test[\"所属区域\"].isin([\"苏州\",\"昆\n buy_df=seek_head_industry(SW_industry_ret.loc[(SW_industry_ret['instrument'].isin(daily_stock.SW_code.tolist()))])\n \n #for k,v in daily_buy_industry_dict.items():\n # buy_df = buy_df.append(daily_stock[(daily_stock.date==k)&(daily_stock.industry_sw_level1_0.apply(lambda x: x in v))])\n #print('buy_df=====\\n',buy_df) \n #buy_df = buy_df.groupby('date').apply(lambda x:x[0].values.tolist()).reset_index()\n # buy_df[0] = buy_df[0].apply(lambda x:x[0]+x[1]+x[2])\n daily_stock['date'] = daily_stock['date'].apply(lambda x:x.strftime('%Y-%m-%d')) \n buy_df=buy_df[['date','SW_code','score']]\n #buy_df['date'] = buy_df['date'].apply(lambda x:x.strftime('%Y-%m-%d')) \n print('buy_df=222====\\n',buy_df) \n \n data=pd.merge(daily_stock,buy_df,on=['date','SW_code'],suffixes=('_left','_right'),how='inner')\n \n print('data=dddd=\\n',data)\n data_1 = DataSource.write_df(data)\n #data_2 = DataSource.write_df(buy_df)\n \n \n return Outputs(data_1=data_1, data_2=None, data_3=None)\n\n\n\n\n# 计算不同周期的动量\ndef calcu_ret(df):\n df = df.sort_values('date')\n for i in [42, 84, 126]: # 分别代表2月、4月、半年的动量\n df['ret_%s'%i] = df['close']/df['close'].shift(i)-1 \n return df\n\n# 计算出得分\ndef seek_head_industry(df):\n for j in ['ret_42','ret_84','ret_126']:\n df['%s'%j] = df['%s'%j].rank(ascending=True) \n df['score'] = 0.4*df['ret_42']+0.3*df['ret_84']+0.3*df['ret_126'] # 得分的权重分别为0.4、0.3、0.3\n df['SW_code'] = df['instrument']\n #result = df.groupby('date').sort_values('score', ascending=False)\n #i=0\n #for instrument in result.keys():\n # i=i+1\n # instrument['SW_p']=instrument\n \n print('result-----',df)\n return df\n\n# 选出特定行业优质股票\ndef seek_head_stock(df):\n result = df.sort_values(['myrank'], ascending=False)\n #return list(result.instrument[:10]) # 每个行业选10只股票\n return list(result.instrument) # 每个行业选10只股票","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"data_1","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-440"},{"name":"input_2","node_id":"-440"},{"name":"input_3","node_id":"-440"}],"output_ports":[{"name":"data_1","node_id":"-440"},{"name":"data_2","node_id":"-440"},{"name":"data_3","node_id":"-440"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='209,64,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='64,173,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='633,-23,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='877,620,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1002,-2,200,200'/><node_position Node='-339' Position='392,142,200,200'/><node_position Node='-346' Position='385,280,200,200'/><node_position Node='-355' Position='1078,234,200,200'/><node_position Node='-362' Position='1061,339,200,200'/><node_position Node='-374' Position='874,871,200,200'/><node_position Node='-213' Position='640,539,200,200'/><node_position Node='-2576' Position='496,462,200,200'/><node_position Node='-390' Position='1018,718,200,200'/><node_position Node='-956' Position='1328,66,200,200'/><node_position Node='-2158' Position='1342,175,200,200'/><node_position Node='-2165' Position='1406,357,200,200'/><node_position Node='-2171' Position='1084,534,200,200'/><node_position Node='-2178' Position='1407,288,200,200'/><node_position Node='-440' Position='1449,431,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2022-04-22 16:59:43.012881] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-04-22 16:59:43.025224] INFO: moduleinvoker: 命中缓存
[2022-04-22 16:59:43.027702] INFO: moduleinvoker: input_features.v1 运行完成[0.014832s].
[2022-04-22 16:59:43.037027] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-04-22 16:59:43.069055] INFO: moduleinvoker: instruments.v2 运行完成[0.032035s].
[2022-04-22 16:59:43.086884] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-22 16:59:45.316526] INFO: 基础特征抽取: 年份 2020, 特征行数=336
[2022-04-22 16:59:48.655644] INFO: 基础特征抽取: 年份 2021, 特征行数=485
[2022-04-22 16:59:49.412002] INFO: 基础特征抽取: 年份 2022, 特征行数=144
[2022-04-22 16:59:49.487773] INFO: 基础特征抽取: 总行数: 965
[2022-04-22 16:59:49.503458] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[6.416529s].
[2022-04-22 16:59:49.533626] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-22 16:59:49.927441] INFO: derived_feature_extractor: 提取完成 close_0/mean(close_0,5), 0.007s
[2022-04-22 16:59:49.936375] INFO: derived_feature_extractor: 提取完成 close_0/mean(close_0,10), 0.007s
[2022-04-22 16:59:49.945462] INFO: derived_feature_extractor: 提取完成 close_0/mean(close_0,20), 0.006s
[2022-04-22 16:59:49.948651] INFO: derived_feature_extractor: 提取完成 close_0/open_0, 0.001s
[2022-04-22 16:59:49.956427] INFO: derived_feature_extractor: 提取完成 open_0/mean(close_0,5), 0.006s
[2022-04-22 16:59:49.963689] INFO: derived_feature_extractor: 提取完成 open_0/mean(close_0,10), 0.006s
[2022-04-22 16:59:49.970903] INFO: derived_feature_extractor: 提取完成 open_0/mean(close_0,20), 0.006s
[2022-04-22 16:59:49.973554] INFO: derived_feature_extractor: 提取完成 avg_turn_0/avg_turn_5, 0.001s
[2022-04-22 16:59:49.976079] INFO: derived_feature_extractor: 提取完成 avg_turn_0/avg_turn_10, 0.001s
[2022-04-22 16:59:50.204471] INFO: derived_feature_extractor: /y_2020, 336
[2022-04-22 16:59:50.283047] INFO: derived_feature_extractor: /y_2021, 485
[2022-04-22 16:59:50.382649] INFO: derived_feature_extractor: /y_2022, 144
[2022-04-22 16:59:50.475908] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[0.942547s].
[2022-04-22 16:59:50.481286] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-04-22 16:59:50.490854] INFO: moduleinvoker: 命中缓存
[2022-04-22 16:59:50.494131] INFO: moduleinvoker: input_features.v1 运行完成[0.012809s].
[2022-04-22 16:59:50.517609] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-22 16:59:54.297408] INFO: 基础特征抽取: 年份 2019, 特征行数=290
[2022-04-22 16:59:58.257687] INFO: 基础特征抽取: 年份 2020, 特征行数=476
[2022-04-22 17:00:03.243010] INFO: 基础特征抽取: 年份 2021, 特征行数=485
[2022-04-22 17:00:04.895539] INFO: 基础特征抽取: 年份 2022, 特征行数=144
[2022-04-22 17:00:04.963887] INFO: 基础特征抽取: 总行数: 1395
[2022-04-22 17:00:04.969630] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[14.452047s].
[2022-04-22 17:00:04.980011] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-22 17:00:05.332239] INFO: derived_feature_extractor: 提取完成 banniangaodianN=ts_argmax(high_0, 128), 0.011s
[2022-04-22 17:00:05.336070] INFO: derived_feature_extractor: 提取完成 isbanniangaodian=where(banniangaodianN<80.0,1,0), 0.001s
[2022-04-22 17:00:05.349457] INFO: derived_feature_extractor: 提取完成 zhouma55=ta_ma(close_0, timeperiod=258), 0.011s
[2022-04-22 17:00:05.352430] INFO: derived_feature_extractor: 提取完成 isupzhou55=where(close_0>zhouma55,1,0), 0.001s
[2022-04-22 17:00:05.358876] INFO: derived_feature_extractor: 提取完成 huitiaodu=ts_max(high_0, 128)/low_1, 0.004s
[2022-04-22 17:00:05.363952] INFO: derived_feature_extractor: 提取完成 banniangaodian=ts_max(high_0, 128*1), 0.004s
[2022-04-22 17:00:05.365871] INFO: derived_feature_extractor: 提取完成 vl1=volatility_5_0 #波动率,timeperiod=240* 取值: , 5, 10, 30, 60, 120, 240, 0.001s
[2022-04-22 17:00:05.368339] INFO: derived_feature_extractor: 提取完成 vl2=volatility_10_0, 0.001s
[2022-04-22 17:00:05.370512] INFO: derived_feature_extractor: 提取完成 vl3=volatility_30_0, 0.001s
[2022-04-22 17:00:05.379644] INFO: derived_feature_extractor: 提取完成 macd_dif=ta_macd_dif(close_0/adjust_factor_0), 0.008s
[2022-04-22 17:00:05.391220] INFO: derived_feature_extractor: 提取完成 macd_h=ta_macd_hist(close_0/adjust_factor_0), 0.010s
[2022-04-22 17:00:05.394871] INFO: derived_feature_extractor: 提取完成 duanqiup1=where(low_0>low_1,1,0), 0.001s
[2022-04-22 17:00:05.401974] INFO: derived_feature_extractor: 提取完成 duanqiup2=where(macd_h>shift(macd_h,1),1,0), 0.004s
[2022-04-22 17:00:05.404813] INFO: derived_feature_extractor: 提取完成 duanqiup=max(duanqiup1,duanqiup2), 0.001s
[2022-04-22 17:00:05.408615] INFO: derived_feature_extractor: 提取完成 my1=where((huitiaodu>1.2)& (vl20.012)&(vl2<0.038)&(st_status_0==0),1,0), 0.002s
[2022-04-22 17:00:05.423802] INFO: derived_feature_extractor: 提取完成 ma5=ta_ma(close_0, timeperiod=5), 0.012s
[2022-04-22 17:00:05.438654] INFO: derived_feature_extractor: 提取完成 ma10=ta_ma(close_0, timeperiod=10), 0.012s
[2022-04-22 17:00:05.452638] INFO: derived_feature_extractor: 提取完成 ma13=ta_ma(close_0, timeperiod=13), 0.012s
[2022-04-22 17:00:05.465584] INFO: derived_feature_extractor: 提取完成 ma20=ta_ma(close_0, timeperiod=20), 0.011s
[2022-04-22 17:00:05.477542] INFO: derived_feature_extractor: 提取完成 ma34=ta_ma(close_0, timeperiod=34), 0.010s
[2022-04-22 17:00:05.489266] INFO: derived_feature_extractor: 提取完成 ma55=ta_ma(close_0, timeperiod=55), 0.010s
[2022-04-22 17:00:05.494733] INFO: derived_feature_extractor: 提取完成 junxian=where((ma5<=high_0) & (ma10<=high_0) & (ma13<=high_0) &(ma20<=high_0) & (ma34<=high_0) & (ma55<=high_0) & (return_0>1.01)&(close_0>open_0)&(return_0<1.08),1,0), 0.003s
[2022-04-22 17:00:05.499353] INFO: derived_feature_extractor: 提取完成 maxline=max(ma5, ma10,ma13, ma20,ma34,ma55), 0.002s
[2022-04-22 17:00:05.502455] INFO: derived_feature_extractor: 提取完成 minline=min(ma5, ma10,ma13, ma20,ma34,ma55), 0.001s
[2022-04-22 17:00:05.505758] INFO: derived_feature_extractor: 提取完成 zhanshang55=close_0/maxline, 0.002s
[2022-04-22 17:00:05.509837] INFO: derived_feature_extractor: 提取完成 junxianchonghedu=minline/maxline, 0.002s
[2022-04-22 17:00:05.515584] INFO: derived_feature_extractor: 提取完成 junxianchonghedu5=shift(junxianchonghedu,5), 0.004s
[2022-04-22 17:00:05.520888] INFO: derived_feature_extractor: 提取完成 junxianchonghedu18=shift(junxianchonghedu,18), 0.004s
[2022-04-22 17:00:05.523538] INFO: derived_feature_extractor: 提取完成 fanliang=volume_0/volume_1 #放量, 0.001s
[2022-04-22 17:00:05.529398] INFO: derived_feature_extractor: 提取完成 deaLn=deal_number_0/deal_number_1, 0.001s
[2022-04-22 17:00:05.532977] INFO: derived_feature_extractor: 提取完成 daDan=fanliang/deaLn #交易笔数放量比不上交易额放量,说明是大单进入多,用大于1.18进行调试, 0.001s
[2022-04-22 17:00:05.537116] INFO: derived_feature_extractor: 提取完成 my2ready=where((junxian==1)&(zhanshang55>=1.0)& (junxianchonghedu>junxianchonghedu5)&(junxianchonghedu5>junxianchonghedu18)& (junxianchonghedu>0.95)&(huitiaodu>1.15)&(fanliang>1.5)&(daDan>1.2),1,0), 0.003s
[2022-04-22 17:00:05.544719] INFO: derived_feature_extractor: 提取完成 my2=where((shift(my2ready,1)==1)&(low_0>low_1)&(close_0>=ma5),1,0), 0.006s
[2022-04-22 17:00:05.548907] INFO: derived_feature_extractor: 提取完成 nearMa55=ma55/close_0, 0.001s
[2022-04-22 17:00:05.552629] INFO: derived_feature_extractor: 提取完成 SW_code=industry_sw_level1_0, 0.001s
[2022-04-22 17:00:05.555477] INFO: derived_feature_extractor: 提取完成 myrank=rank_fs_roe_ttm_0+rank_fs_net_profit_qoq_0-rank_pb_lf_0, 0.001s
[2022-04-22 17:00:05.557693] INFO: derived_feature_extractor: 提取完成 pe_ttm_0 #滚动市盈率, 0.001s
[2022-04-22 17:00:05.559828] INFO: derived_feature_extractor: 提取完成 fs_eps_0 #每股收益, 0.001s
[2022-04-22 17:00:05.561866] INFO: derived_feature_extractor: 提取完成 fs_eps_yoy_0 #每股收益同比增长率, 0.001s
[2022-04-22 17:00:05.563882] INFO: derived_feature_extractor: 提取完成 fs_bps_0 #每股净资产, 0.001s
[2022-04-22 17:00:05.566145] INFO: derived_feature_extractor: 提取完成 fs_roa_ttm_0 #总资产报酬率 (TTM), 0.001s
[2022-04-22 17:00:05.568928] INFO: derived_feature_extractor: 提取完成 my=max(my1,my2), 0.001s
[2022-04-22 17:00:05.639767] INFO: derived_feature_extractor: /y_2019, 290
[2022-04-22 17:00:05.743139] INFO: derived_feature_extractor: /y_2020, 476
[2022-04-22 17:00:05.839058] INFO: derived_feature_extractor: /y_2021, 485
[2022-04-22 17:00:05.940372] INFO: derived_feature_extractor: /y_2022, 144
[2022-04-22 17:00:06.373660] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[1.393636s].
[2022-04-22 17:00:06.384360] INFO: moduleinvoker: filter.v3 开始运行..
[2022-04-22 17:00:06.414289] INFO: filter: 使用表达式 date>='2022-03-10'&my2==1 过滤
[2022-04-22 17:00:06.490386] INFO: filter: 过滤 /y_2019, 0/0/0
[2022-04-22 17:00:06.558282] INFO: filter: 过滤 /y_2020, 0/0/252
[2022-04-22 17:00:06.621140] INFO: filter: 过滤 /y_2021, 0/0/485
[2022-04-22 17:00:06.733094] INFO: filter: 过滤 /y_2022, 1/0/142
[2022-04-22 17:00:06.813980] INFO: moduleinvoker: filter.v3 运行完成[0.429615s].
[2022-04-22 17:00:06.844829] INFO: moduleinvoker: cached.v3 开始运行..
[2022-04-22 17:00:09.673632] INFO: moduleinvoker: cached.v3 运行完成[2.828801s].
[2022-04-22 17:00:09.686617] INFO: moduleinvoker: join.v3 开始运行..
[2022-04-22 17:00:09.929214] ERROR: moduleinvoker: module name: join, module version: v3, trackeback: ValueError: You are trying to merge on object and datetime64[ns] columns. If you wish to proceed you should use pd.concat
after apply SW_industry_ret==
turn adjust_factor instrument date open \
0 0.4444 1.0 SW110000.HIX 2005-01-04 487.959991
1 0.6792 1.0 SW110000.HIX 2005-01-05 483.820007
2 0.5826 1.0 SW110000.HIX 2005-01-06 493.359985
3 0.5680 1.0 SW110000.HIX 2005-01-07 488.609985
4 0.5365 1.0 SW110000.HIX 2005-01-10 490.790009
... ... ... ... ... ...
117505 1.0204 1.0 SW730000.HIX 2022-04-18 1750.504028
117506 0.9824 1.0 SW730000.HIX 2022-04-19 1792.421997
117507 1.0049 1.0 SW730000.HIX 2022-04-20 1802.852051
117508 1.0049 1.0 SW730000.HIX 2022-04-21 1769.225952
117509 1.3357 1.0 SW730000.HIX 2022-04-22 1715.608032
volume low close high amount \
0 28700000 482.820007 485.750000 490.989990 1.006400e+08
1 41910000 483.420013 493.750000 496.380005 1.607900e+08
2 34700000 487.209991 489.339996 493.859985 1.423500e+08
3 35520000 487.570007 492.470001 495.839996 1.279000e+08
4 35160000 489.709991 497.399994 497.399994 1.182600e+08
... ... ... ... ... ...
117505 922953600 1735.328979 1794.791016 1795.562012 1.041696e+10
117506 888600300 1783.961060 1793.348022 1807.285034 9.420230e+09
117507 908932200 1771.775024 1777.057007 1805.589966 9.515557e+09
117508 1208178500 1717.232056 1723.087036 1782.120972 1.063953e+10
117509 1139707900 1702.421021 1717.829956 1736.412964 1.090968e+10
ret_42 ret_84 ret_126
0 NaN NaN NaN
1 NaN NaN NaN
2 NaN NaN NaN
3 NaN NaN NaN
4 NaN NaN NaN
... ... ... ...
117505 -0.128457 -0.149896 -0.092903
117506 -0.134407 -0.152475 -0.099380
117507 -0.138598 -0.173140 -0.100520
117508 -0.176741 -0.206647 -0.129446
117509 -0.202582 -0.211662 -0.129368
[117510 rows x 13 columns]
daily_stock=111=
adjust_factor_0 close_0 date deal_number_0 deal_number_1 \
1376 1.331137 40.919151 2022-03-25 20741 21227
fs_bps_0 fs_eps_0 fs_eps_yoy_0 fs_roa_ttm_0 high_0 ... my2 \
1376 8.59 0.7511 99.495354 6.4608 41.677898 ... 1
nearMa55 SW_code myrank pe_ttm_0 #滚动市盈率 fs_eps_0 #每股收益 \
1376 0.962039 SW220000.HIX 0.624394 50.403099 0.7511
fs_eps_yoy_0 #每股收益同比增长率 fs_bps_0 #每股净资产 fs_roa_ttm_0 #总资产报酬率 (TTM) my
1376 99.495354 8.59 6.4608 1
[1 rows x 68 columns]
daily_stock.SW_code.tolist() ['SW220000.HIX']
result----- turn adjust_factor instrument date open \
8315 0.8721 1.0 SW220000.HIX 2005-01-04 861.630005
8316 0.6684 1.0 SW220000.HIX 2005-01-05 851.109985
8317 0.5341 1.0 SW220000.HIX 2005-01-06 856.510010
8318 0.5391 1.0 SW220000.HIX 2005-01-07 843.380005
8319 0.5385 1.0 SW220000.HIX 2005-01-10 843.450012
... ... ... ... ... ...
12510 2.0069 1.0 SW220000.HIX 2022-04-18 4312.645020
12511 2.1519 1.0 SW220000.HIX 2022-04-19 4346.229004
12512 2.3881 1.0 SW220000.HIX 2022-04-20 4405.258789
12513 2.4622 1.0 SW220000.HIX 2022-04-21 4284.430176
12514 1.8926 1.0 SW220000.HIX 2022-04-22 4077.868896
volume low close high amount \
8315 176480000 849.349976 852.640015 866.549988 9.839500e+08
8316 136810000 846.479980 857.909973 862.820007 7.456400e+08
8317 110700000 841.409973 844.830017 858.640015 6.014700e+08
8318 113500000 840.479980 846.400024 853.150024 6.070300e+08
8319 108170000 838.960022 848.890015 849.409973 5.607100e+08
... ... ... ... ... ...
12510 4161104100 4262.524902 4339.005859 4360.784180 5.224896e+10
12511 4461741500 4346.229004 4405.312012 4408.581055 5.928265e+10
12512 4957535600 4285.546875 4309.544922 4405.261230 6.081475e+10
12513 5112460000 4097.570801 4109.229004 4296.171875 6.100293e+10
12514 3930212400 4013.625977 4075.458008 4117.765137 4.692035e+10
ret_42 ret_84 ret_126 score SW_code
8315 NaN NaN NaN NaN SW220000.HIX
8316 NaN NaN NaN NaN SW220000.HIX
8317 NaN NaN NaN NaN SW220000.HIX
8318 NaN NaN NaN NaN SW220000.HIX
8319 NaN NaN NaN NaN SW220000.HIX
... ... ... ... ... ...
12510 959.0 638.0 987.0 871.1 SW220000.HIX
12511 981.0 666.0 1048.0 906.6 SW220000.HIX
12512 662.0 514.0 903.0 689.9 SW220000.HIX
12513 374.0 389.0 609.0 449.0 SW220000.HIX
12514 328.0 391.0 464.0 387.7 SW220000.HIX
[4200 rows x 15 columns]
buy_df=222====
date SW_code score
8315 2005-01-04 SW220000.HIX NaN
8316 2005-01-05 SW220000.HIX NaN
8317 2005-01-06 SW220000.HIX NaN
8318 2005-01-07 SW220000.HIX NaN
8319 2005-01-10 SW220000.HIX NaN
... ... ... ...
12510 2022-04-18 SW220000.HIX 871.1
12511 2022-04-19 SW220000.HIX 906.6
12512 2022-04-20 SW220000.HIX 689.9
12513 2022-04-21 SW220000.HIX 449.0
12514 2022-04-22 SW220000.HIX 387.7
[4200 rows x 3 columns]
data=dddd=
adjust_factor_0 close_0 date deal_number_0 deal_number_1 \
0 1.331137 40.919151 2022-03-25 20741 21227
fs_bps_0 fs_eps_0 fs_eps_yoy_0 fs_roa_ttm_0 high_0 ... nearMa55 \
0 8.59 0.7511 99.495354 6.4608 41.677898 ... 0.962039
SW_code myrank pe_ttm_0 #滚动市盈率 fs_eps_0 #每股收益 \
0 SW220000.HIX 0.624394 50.403099 0.7511
fs_eps_yoy_0 #每股收益同比增长率 fs_bps_0 #每股净资产 fs_roa_ttm_0 #总资产报酬率 (TTM) my \
0 99.495354 8.59 6.4608 1
score
0 792.4
[1 rows x 69 columns]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-d7a229da8fc7> in <module>
288 )
289
--> 290 m20 = M.join.v3(
291 data1=m6.data_1,
292 data2=m18.data,
ValueError: You are trying to merge on object and datetime64[ns] columns. If you wish to proceed you should use pd.concat