复制链接
克隆策略

    {"description":"实验创建于2022/12/12","graph":{"edges":[{"to_node_id":"-1225:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-1260:input_1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-1234:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-1225:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"-190:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"-1234:input_data","from_node_id":"-1225:data"},{"to_node_id":"-137:input_data","from_node_id":"-1014:data"},{"to_node_id":"-292:input_data","from_node_id":"-1234:data"},{"to_node_id":"-1014:input_data","from_node_id":"-292:data"},{"to_node_id":"-292:features","from_node_id":"-1260:data_1"},{"to_node_id":"-190:options_data","from_node_id":"-137:data"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"e=0.0000000001\n\n上市时间=list_days_0\n\n收益=return_10\n\n\n#特征\n市值=market_cap_0\n\n#过滤特征\n换手rank_std20=rank(std(turn_0,20))\n换手rank_std5=rank(std(turn_0,5))\n\n\n#罗伯瑞克选股指标\n市净率=pb_lf_0\n市盈率=pe_ttm_0\n借款比例=fs_total_liability_0/(fs_current_assets_0+fs_fixed_assets_0)\n现金流比率=close_0/fs_free_cash_flow_0\n\n\n\n\n\n\n\n\n\n\n\n","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":false,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2013-01-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2017-01-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-8"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-1225","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":"50","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-1225"},{"name":"features","node_id":"-1225"}],"output_ports":[{"name":"data","node_id":"-1225"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-1014","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%3Afalse%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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%3Atrue%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":"-1014"}],"output_ports":[{"name":"data","node_id":"-1014"},{"name":"left_data","node_id":"-1014"}],"cacheable":false,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"-1234","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":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"def talib_SLOPE(df, close, timeperiod=21):\n return talib.LINEARREG_SLOPE(close, timeperiod)\n\nbigquant_run = {\n'ta_slope':talib_SLOPE\n}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-1234"},{"name":"features","node_id":"-1234"}],"output_ports":[{"name":"data","node_id":"-1234"}],"cacheable":false,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-292","module_id":"BigQuantSpace.fillnan.fillnan-v1","parameters":[{"name":"fill_value","value":"0.0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-292"},{"name":"features","node_id":"-292"}],"output_ports":[{"name":"data","node_id":"-292"}],"cacheable":false,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-1260","module_id":"BigQuantSpace.features_short.features_short-v1","parameters":[],"input_ports":[{"name":"input_1","node_id":"-1260"}],"output_ports":[{"name":"data_1","node_id":"-1260"}],"cacheable":false,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-137","module_id":"BigQuantSpace.datahub_handler_column.datahub_handler_column-v1","parameters":[{"name":"handler","value":"# Python 代码处理数据\ndef bigquant_run(data):\n \n df_tmp = data\n data=data[data['上市时间'] >365]\n data=data[data['换手rank_std20'] < 0.8]\n data=data[data['换手rank_std5'] <0.8]\n \n data=pd.DataFrame(data)\n date=data.date.unique()\n df_list=[]\n\n for i in date:\n \n cut=data.loc[data['date']==i]\n \n cut=cut[cut['市净率'] < 1.5]\n \n pb_mean = cut['市盈率'].mean()\n cut=cut[cut['市盈率'] < pb_mean]\n \n cut=cut[cut['借款比例'] < 0.33]\n\n \n \n \n df_list.append(cut)\n\n df_=pd.concat(df_list)\n \n \n \n \n \n return df_","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-137"}],"output_ports":[{"name":"data","node_id":"-137"}],"cacheable":false,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-190","module_id":"BigQuantSpace.hftrade.hftrade-v2","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.ranker_prediction = context.options['data'].read_df()\n \n #=========================== 设置交易参数 ====================================\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.00015, sell_cost=0.0013, min_cost=5))\n #=========================== 设置持仓参数 ====================================\n \n #最大持仓量\n context.stock_count = 5\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.5\n \n #持仓天数\n context.hold_days = 5\n \n #股票止损列表\n context.stop_list = {}\n \n #股票止损卖出后最小买入间隔\n context.min_stop_days = 20\n \n #=======================================功能开关\n #是否止损\n context.stop_win = True\n context.set_stock_t1(1)","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n # 盘前处理,订阅行情等\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, tick):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 交易引擎:bar数据处理函数,每个时间单位执行一次\ndef bigquant_run(context, data):\n \n import datetime\n \n #初始化()\n buy_list = [] #买入列表\n sell_list = [] #卖出列表\n target_list = [] #目标列表\n #==================== 数据准备\n today = data.current_dt.strftime('%Y-%m-%d')\n time = data.current_dt\n \n today_data = context.ranker_prediction[context.ranker_prediction['date'] == today]\n #print(today_data)\n \n if len(today_data)>0:\n #获得当日预备持仓\n today_data = today_data.sort_values(by='市值', ascending = True)\n target_list = today_data.instrument.tolist()\n \n #获得当前持仓列表\n holding_list = list(context.get_account_positions().keys())\n holding_num = len(holding_list)\n long_num = 0 #初始化多头数\n \n if len(target_list)>0:\n pct = 1/len(target_list)\n else:\n pct=len(holding_list)\n \n\n #生成卖单\n for ins in holding_list:\n if ins not in target_list:\n context.order_target_percent(ins,0)\n sell_list.append(ins)\n \n #现有持仓的持仓量调整\n for ins in holding_list:\n if ins not in sell_list:\n context.order_target_percent(ins,pct)\n \n #生成买单\n for ins in target_list:\n if ins not in holding_list: \n context.order_target_percent(ins,pct)\n\n\n","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, trade):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, order):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"after_trading","value":"# 交易引擎:盘后处理函数,每日盘后执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"100000","type":"Literal","bound_global_parameter":null},{"name":"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":"before_start_days","value":"0","type":"Literal","bound_global_parameter":null},{"name":"volume_limit","value":1,"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":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"disable_cache","value":"True","type":"Literal","bound_global_parameter":null},{"name":"replay_bdb","value":"False","type":"Literal","bound_global_parameter":null},{"name":"show_debug_info","value":"False","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-190"},{"name":"options_data","node_id":"-190"},{"name":"history_ds","node_id":"-190"},{"name":"benchmark_ds","node_id":"-190"}],"output_ports":[{"name":"raw_perf","node_id":"-190"}],"cacheable":false,"seq_num":2,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='52,-1099,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='-362,-1100,200,200'/><node_position Node='-1225' Position='-166,-954,200,200'/><node_position Node='-1014' Position='-137,-634,200,200'/><node_position Node='-1234' Position='-157,-843,200,200'/><node_position Node='-292' Position='-144,-752,200,200'/><node_position Node='-1260' Position='212,-955,200,200'/><node_position Node='-137' Position='-121,-539,200,200'/><node_position Node='-190' Position='-176,-408,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [ ]:
    # 本代码由可视化策略环境自动生成 2023年4月12日 20:49
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def talib_SLOPE(df, close, timeperiod=21):
        return talib.LINEARREG_SLOPE(close, timeperiod)
    
    m12_user_functions_bigquant_run = {
    'ta_slope':talib_SLOPE
    }
    # Python 代码处理数据
    def m8_handler_bigquant_run(data):
        
        df_tmp = data
        data=data[data['上市时间'] >365]
        data=data[data['换手rank_std20'] < 0.8]
        data=data[data['换手rank_std5'] <0.8]
        
        data=pd.DataFrame(data)
        date=data.date.unique()
        df_list=[]
    
        for i in date:
            
            cut=data.loc[data['date']==i]
            
            cut=cut[cut['市净率'] < 1.5]
            
            pb_mean = cut['市盈率'].mean()
            cut=cut[cut['市盈率'] < pb_mean]
            
            cut=cut[cut['借款比例'] < 0.33]
    
            
            
            
            df_list.append(cut)
    
        df_=pd.concat(df_list)
        
        
        
        
        
        return df_
    # 交易引擎:初始化函数,只执行一次
    def m2_initialize_bigquant_run(context):
        #=========================== 加载预测数据  ===================================
        
        context.ranker_prediction = context.options['data'].read_df()
        
        #===========================  设置交易参数  ====================================
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.00015, sell_cost=0.0013, min_cost=5))
        #===========================  设置持仓参数  ====================================
        
        #最大持仓量
        context.stock_count = 5
        # 设置每只股票占用的最大资金比例
        context.max_cash_per_instrument = 0.5
        
        #持仓天数
        context.hold_days = 5
        
        #股票止损列表
        context.stop_list = {}
        
        #股票止损卖出后最小买入间隔
        context.min_stop_days = 20
        
        #=======================================功能开关
        #是否止损
        context.stop_win = True
        context.set_stock_t1(1)
    # 交易引擎:每个单位时间开盘前调用一次。
    def m2_before_trading_start_bigquant_run(context, data):
        # 盘前处理,订阅行情等
        pass
    
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m2_handle_tick_bigquant_run(context, tick):
        pass
    
    # 交易引擎:bar数据处理函数,每个时间单位执行一次
    def m2_handle_data_bigquant_run(context, data):
        
        import datetime
        
        #初始化()
        buy_list = []  #买入列表
        sell_list = [] #卖出列表
        target_list = []  #目标列表
        #==================== 数据准备
        today = data.current_dt.strftime('%Y-%m-%d')
        time = data.current_dt
        
        today_data  = context.ranker_prediction[context.ranker_prediction['date'] == today]
        #print(today_data)
        
        if len(today_data)>0:
            #获得当日预备持仓
            today_data = today_data.sort_values(by='市值', ascending = True)
            target_list = today_data.instrument.tolist()
        
        #获得当前持仓列表
        holding_list = list(context.get_account_positions().keys())
        holding_num = len(holding_list)
        long_num = 0 #初始化多头数
        
        if len(target_list)>0:
            pct = 1/len(target_list)
        else:
            pct=len(holding_list)
        
    
        #生成卖单
        for ins in holding_list:
            if ins not in target_list:
                context.order_target_percent(ins,0)
                sell_list.append(ins)
                
        #现有持仓的持仓量调整
        for ins in holding_list:
            if ins not in sell_list:
                context.order_target_percent(ins,pct)
        
        #生成买单
        for ins in target_list:
            if ins not in holding_list:  
                context.order_target_percent(ins,pct)
    
    
    
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m2_handle_trade_bigquant_run(context, trade):
        pass
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m2_handle_order_bigquant_run(context, order):
        pass
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m2_after_trading_bigquant_run(context, data):
        pass
    
    
    m1 = M.input_features.v1(
        features="""e=0.0000000001
    
    上市时间=list_days_0
    
    收益=return_10
    
    
    #特征
    市值=market_cap_0
    
    #过滤特征
    换手rank_std20=rank(std(turn_0,20))
    换手rank_std5=rank(std(turn_0,5))
    
    
    #罗伯瑞克选股指标
    市净率=pb_lf_0
    市盈率=pe_ttm_0
    借款比例=fs_total_liability_0/(fs_current_assets_0+fs_fixed_assets_0)
    现金流比率=close_0/fs_free_cash_flow_0
    
    
    
    
    
    
    
    
    
    
    
    """,
        m_cached=False
    )
    
    m17 = M.features_short.v1(
        input_1=m1.data,
        m_cached=False
    )
    
    m3 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2013-01-01'),
        end_date=T.live_run_param('trading_date', '2017-01-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0,
        m_cached=False
    )
    
    m4 = M.general_feature_extractor.v7(
        instruments=m3.data,
        features=m1.data,
        start_date='',
        end_date='',
        before_start_days=50,
        m_cached=False
    )
    
    m12 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m1.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=True,
        user_functions=m12_user_functions_bigquant_run,
        m_cached=False
    )
    
    m16 = M.fillnan.v1(
        input_data=m12.data,
        features=m17.data_1,
        fill_value='0.0',
        m_cached=False
    )
    
    m15 = M.chinaa_stock_filter.v1(
        input_data=m16.data,
        index_constituent_cond=['全部'],
        board_cond=['上证主板', '深证主板', '创业板'],
        industry_cond=['交通运输', '休闲服务', '传媒/信息服务', '公用事业', '农林牧渔', '化工', '医药生物', '商业贸易', '国防军工', '家用电器', '建筑材料/建筑建材', '建筑装饰', '房地产', '有色金属', '机械设备', '汽车/交运设备', '电子', '电气设备', '纺织服装', '综合', '计算机', '轻工制造', '通信', '采掘', '钢铁', '食品饮料'],
        st_cond=['正常'],
        delist_cond=['非退市'],
        output_left_data=False,
        m_cached=False
    )
    
    m8 = M.datahub_handler_column.v1(
        input_data=m15.data,
        handler=m8_handler_bigquant_run
    )
    
    m2 = M.hftrade.v2(
        instruments=m3.data,
        options_data=m8.data,
        start_date='',
        end_date='',
        initialize=m2_initialize_bigquant_run,
        before_trading_start=m2_before_trading_start_bigquant_run,
        handle_tick=m2_handle_tick_bigquant_run,
        handle_data=m2_handle_data_bigquant_run,
        handle_trade=m2_handle_trade_bigquant_run,
        handle_order=m2_handle_order_bigquant_run,
        after_trading=m2_after_trading_bigquant_run,
        capital_base=100000,
        frequency='daily',
        price_type='真实价格',
        product_type='股票',
        before_start_days='0',
        volume_limit=1,
        order_price_field_buy='open',
        order_price_field_sell='close',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=True,
        replay_bdb=False,
        show_debug_info=False,
        backtest_only=False
    )
    

    数据处理(自定义) 数据统计 (前 2118 行) </font></font>

    date instrument e 上市时间 收益 市值 换手rank_std20 换手rank_std5 市净率 市盈率 借款比例 现金流比率
    count(Nan) 0 0 0 0 0 0 0 0 0 0 0 0
    type datetime64[ns] object float64 float32 float32 float64 float64 float64 float32 float32 float64 float64

    数据处理(自定义) 数据预览 (前 5 行) </font></font>

    date instrument e 上市时间 收益 市值 换手rank_std20 换手rank_std5 市净率 市盈率 借款比例 现金流比率
    878 2012-11-12 000030.SZA 1.000000e-10 6984.0 1.030809 2.316013e+09 0.0 0.0 -95297.515625 -922.274292 0.000000 -2.053298e-04
    2035 2012-11-12 000096.SZA 1.000000e-10 4494.0 0.979540 2.022240e+09 0.0 0.0 1.125427 24.317139 0.199649 -4.365882e-07
    7164 2012-11-12 000635.SZA 1.000000e-10 5836.0 0.962040 2.458041e+09 0.0 0.0 0.932666 -60.740070 0.296427 -1.832404e-08
    9214 2012-11-12 000726.SZA 1.000000e-10 4340.0 0.998392 6.265609e+09 0.0 0.0 1.218711 10.562615 0.315390 1.221924e-07
    11359 2012-11-12 000821.SZA 1.000000e-10 5253.0 0.971204 1.280836e+09 0.0 0.0 1.149406 -32.167004 0.291004 -3.083850e-07