版本v1.0
在开发策略时,经常需要根据大盘指数计算相关技术指标来进行仓位风险控制。
本策略以上证指数5日累计涨幅作为风险控制指标,如果5日累计涨幅小于-4%,则执行清仓止损。
功能实现步骤:
1、新建AI可视化模板策略
2、在回测/模拟模块m19的属性栏中进入“数据准备函数”代码框,在函数体中计算上证指数000001.HIX在回测起止时间段内的5日涨幅指标,同时计算风控信号risk指标保存在context.benckmark_risk变量中:
3、在回测/模拟模块m19的属性栏中进入“主函数”代码框,在函数体中最前端获取当日的风控信号benckmark_risk指标, 如果满足风控条件则将持仓全部卖出后通过return语句返回,结束当天交易实现风险控制功能。
# 本代码由可视化策略环境自动生成 2022年4月12日 13:01
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
# 回测引擎:初始化函数,只执行一次
def m19_initialize_bigquant_run(context):
# 加载预测数据
context.ranker_prediction = context.options['data'].read_df()
# 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
# 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
# 设置买入的股票数量,这里买入预测股票列表排名靠前的5只
stock_count = 5
# 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]
context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])
# 设置每只股票占用的最大资金比例
context.max_cash_per_instrument = 0.5
context.options['hold_days'] = 10
# 回测引擎:每日数据处理函数,每天执行一次
def m19_handle_data_bigquant_run(context, data):
#获取当日日期
today = data.current_dt.strftime('%Y-%m-%d')
stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]
#大盘风控模块,读取风控数据
benckmark_risk=context.benckmark_risk[today]
context.symbol
#当risk为1时,市场有风险,全部平仓,不再执行其它操作
if benckmark_risk > 0:
for instrument in stock_hold_now:
context.order_target(symbol(instrument), 0)
print(today,'大盘风控止损触发,全仓卖出')
return
# 按日期过滤得到今日的预测数据
ranker_prediction = context.ranker_prediction[
context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
# 1. 资金分配
# 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金
# 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)
is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)
cash_avg = context.portfolio.portfolio_value / context.options['hold_days']
cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)
cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
positions = {e.symbol: p.amount * p.last_sale_price
for e, p in context.perf_tracker.position_tracker.positions.items()}
# 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
if not is_staging and cash_for_sell > 0:
equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}
instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))
# print('rank order for sell %s' % instruments)
for instrument in instruments:
context.order_target(context.symbol(instrument), 0)
cash_for_sell -= positions[instrument]
if cash_for_sell <= 0:
break
# 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
buy_cash_weights = context.stock_weights
buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])
max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument
for i, instrument in enumerate(buy_instruments):
cash = cash_for_buy * buy_cash_weights[i]
if cash > max_cash_per_instrument - positions.get(instrument, 0):
# 确保股票持仓量不会超过每次股票最大的占用资金量
cash = max_cash_per_instrument - positions.get(instrument, 0)
if cash > 0:
context.order_value(context.symbol(instrument), cash)
# 回测引擎:准备数据,只执行一次
def m19_prepare_bigquant_run(context):
#在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度
# 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间
start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d')
df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])
benckmark_data=df[df.instrument=='000300.HIX']
#计算上证指数5日涨幅
benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(5)-1
#计算大盘风控条件,如果5日涨幅小于-4%则设置风险状态risk为1,否则为0
benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.04,1,0)
#修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)
benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))
#设置日期为索引
benckmark_data.set_index('date',inplace=True)
#把风控序列输出给全局变量context.benckmark_risk
context.benckmark_risk=benckmark_data['risk']
g = T.Graph({
'm1': 'M.instruments.v2',
'm1.start_date': '2015-01-01',
'm1.end_date': '2018-01-01',
'm1.market': 'CN_STOCK_A',
'm1.instrument_list': '',
'm1.max_count': 0,
'm2': 'M.advanced_auto_labeler.v2',
'm2.instruments': T.Graph.OutputPort('m1.data'),
'm2.label_expr': """# #号开始的表示注释
# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
# 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html
# 添加benchmark_前缀,可使用对应的benchmark数据
# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_
# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
shift(close, -5) / shift(open, -1)
# 极值处理:用1%和99%分位的值做clip
clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
# 将分数映射到分类,这里使用20个分类
all_wbins(label, 20)
# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
where(shift(high, -1) == shift(low, -1), NaN, label)
""",
'm2.start_date': '',
'm2.end_date': '',
'm2.benchmark': '000300.SHA',
'm2.drop_na_label': True,
'm2.cast_label_int': True,
'm3': 'M.input_features.v1',
'm3.features': """# #号开始的表示注释
# 多个特征,每行一个,可以包含基础特征和衍生特征
ta_wma_5_0
mean(volume_0,90)
fs_net_cash_flow_0/fs_paicl_up_capital_0
mean(volume_0,5)
fs_net_cash_flow_ttm_0
pb_lf_0
fs_operating_revenue_ttm_0/(fs_total_liability_0+fs_total_equity_0)
beta_gem_30_0
""",
'm15': 'M.general_feature_extractor.v7',
'm15.instruments': T.Graph.OutputPort('m1.data'),
'm15.features': T.Graph.OutputPort('m3.data'),
'm15.start_date': '',
'm15.end_date': '',
'm15.before_start_days': 0,
'm16': 'M.derived_feature_extractor.v3',
'm16.input_data': T.Graph.OutputPort('m15.data'),
'm16.features': T.Graph.OutputPort('m3.data'),
'm16.date_col': 'date',
'm16.instrument_col': 'instrument',
'm16.drop_na': False,
'm16.remove_extra_columns': False,
'm7': 'M.join.v3',
'm7.data1': T.Graph.OutputPort('m2.data'),
'm7.data2': T.Graph.OutputPort('m16.data'),
'm7.on': 'date,instrument',
'm7.how': 'inner',
'm7.sort': False,
'm6': 'M.filter_delist_stock.v4',
'm6.input_1': T.Graph.OutputPort('m7.data'),
'm11': 'M.filtet_st_stock.v2',
'm11.input_1': T.Graph.OutputPort('m6.data_1'),
'm5': 'M.dropnan.v2',
'm5.input_data': T.Graph.OutputPort('m11.data_1'),
'm4': 'M.stock_ranker_train.v6',
'm4.training_ds': T.Graph.OutputPort('m5.data'),
'm4.features': T.Graph.OutputPort('m3.data'),
'm4.learning_algorithm': '排序',
'm4.number_of_leaves': 30,
'm4.minimum_docs_per_leaf': 1000,
'm4.number_of_trees': 20,
'm4.learning_rate': 0.1,
'm4.max_bins': 1023,
'm4.feature_fraction': 1,
'm4.data_row_fraction': 1,
'm4.plot_charts': True,
'm4.ndcg_discount_base': 1,
'm4.m_lazy_run': False,
'm9': 'M.instruments.v2',
'm9.start_date': T.live_run_param('trading_date', '2018-01-01'),
'm9.end_date': T.live_run_param('trading_date', '2020-12-31'),
'm9.market': 'CN_STOCK_A',
'm9.instrument_list': '',
'm9.max_count': 0,
'm17': 'M.general_feature_extractor.v7',
'm17.instruments': T.Graph.OutputPort('m9.data'),
'm17.features': T.Graph.OutputPort('m3.data'),
'm17.start_date': '',
'm17.end_date': '',
'm17.before_start_days': 60,
'm18': 'M.derived_feature_extractor.v3',
'm18.input_data': T.Graph.OutputPort('m17.data'),
'm18.features': T.Graph.OutputPort('m3.data'),
'm18.date_col': 'date',
'm18.instrument_col': 'instrument',
'm18.drop_na': False,
'm18.remove_extra_columns': False,
'm12': 'M.filter_delist_stock.v4',
'm12.input_1': T.Graph.OutputPort('m18.data'),
'm13': 'M.filtet_st_stock.v2',
'm13.input_1': T.Graph.OutputPort('m12.data_1'),
'm10': 'M.dropnan.v2',
'm10.input_data': T.Graph.OutputPort('m13.data_1'),
'm8': 'M.stock_ranker_predict.v5',
'm8.model': T.Graph.OutputPort('m4.model'),
'm8.data': T.Graph.OutputPort('m10.data'),
'm8.m_lazy_run': False,
'm19': 'M.trade.v4',
'm19.instruments': T.Graph.OutputPort('m9.data'),
'm19.options_data': T.Graph.OutputPort('m8.predictions'),
'm19.start_date': '2020-01-01',
'm19.end_date': '2021-12-31',
'm19.initialize': m19_initialize_bigquant_run,
'm19.handle_data': m19_handle_data_bigquant_run,
'm19.prepare': m19_prepare_bigquant_run,
'm19.volume_limit': 0.025,
'm19.order_price_field_buy': 'open',
'm19.order_price_field_sell': 'close',
'm19.capital_base': 1000000,
'm19.auto_cancel_non_tradable_orders': True,
'm19.data_frequency': 'daily',
'm19.price_type': '后复权',
'm19.product_type': '股票',
'm19.plot_charts': True,
'm19.backtest_only': False,
'm19.benchmark': '000300.HIX',
})
# g.run({})
def m14_run_bigquant_run(
bq_graph,
inputs,
trading_days_market='CN', # 使用那个市场的交易日历, TODO
train_instruments_mid='m1', # 训练数据 证券代码列表 模块id
test_instruments_mid='m9', # 测试数据 证券代码列表 模块id
predict_mid='m8', # 预测 模块id
trade_mid='m19', # 回测 模块id
start_date='2014-01-01', # 数据开始日期
end_date=T.live_run_param('trading_date', '2017-01-01'), # 数据结束日期
train_update_days=250, # 更新周期,按交易日计算,每多少天更新一次
train_update_days_for_live=None, #模拟实盘模式下的更新周期,按交易日计算,每多少天更新一次。如果需要在模拟实盘阶段使用不同的模型更新周期,可以设置这个参数
train_data_min_days=250, # 最小数据天数,按交易日计算,所以第一个滚动的结束日期是 从开始日期到开始日期+最小数据天数
train_data_max_days=250, # 最大数据天数,按交易日计算,0,表示没有限制,否则每一个滚动的开始日期=max(此滚动的结束日期-最大数据天数, 开始日期
rolling_count_for_live=1, #实盘模式下滚动次数,模拟实盘模式下,取最后多少次滚动。一般在模拟实盘模式下,只用到最后一次滚动训练的模型,这里可以设置为1;如果你的滚动训练数据时间段很短,以至于期间可能没有训练数据,这里可以设置大一点。0表示没有限制
):
def merge_datasources(input_1):
df_list = [ds[0].read_df().set_index('date').loc[ds[1]:].reset_index() for ds in input_1]
df = pd.concat(df_list)
instrument_data = {
'start_date': df['date'].min().strftime('%Y-%m-%d'),
'end_date': df['date'].max().strftime('%Y-%m-%d'),
'instruments': list(set(df['instrument'])),
}
return Outputs(data=DataSource.write_df(df), instrument_data=DataSource.write_pickle(instrument_data))
def gen_rolling_dates(trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live):
# 是否实盘模式
tdays = list(D.trading_days(market=trading_days_market, start_date=start_date, end_date=end_date)['date'])
is_live_run = T.live_run_param('trading_date', None) is not None
if is_live_run and train_update_days_for_live:
train_update_days = train_update_days_for_live
rollings = []
train_end_date = train_data_min_days
while train_end_date < len(tdays):
if train_data_max_days is not None and train_data_max_days > 0:
train_start_date = max(train_end_date - train_data_max_days, 0)
else:
train_start_date = 0
rollings.append({
'train_start_date': tdays[train_start_date].strftime('%Y-%m-%d'),
'train_end_date': tdays[train_end_date - 1].strftime('%Y-%m-%d'),
'test_start_date': tdays[train_end_date].strftime('%Y-%m-%d'),
'test_end_date': tdays[min(train_end_date + train_update_days, len(tdays)) - 1].strftime('%Y-%m-%d'),
})
train_end_date += train_update_days
if not rollings:
raise Exception('没有滚动需要执行,请检查配置')
if is_live_run and rolling_count_for_live:
rollings = rollings[-rolling_count_for_live:]
return rollings
g = bq_graph
rolling_dates = gen_rolling_dates(
trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live)
# 训练和预测
results = []
for rolling in rolling_dates:
parameters = {}
# 先禁用回测
parameters[trade_mid + '.__enabled__'] = False
parameters[train_instruments_mid + '.start_date'] = rolling['train_start_date']
parameters[train_instruments_mid + '.end_date'] = rolling['train_end_date']
parameters[test_instruments_mid + '.start_date'] = rolling['test_start_date']
parameters[test_instruments_mid + '.end_date'] = rolling['test_end_date']
# print('------ rolling_train:', parameters)
results.append(g.run(parameters))
# 合并预测结果并回测
mx = M.cached.v3(run=merge_datasources, input_1=[[result[predict_mid].predictions, result[test_instruments_mid].data.read_pickle()['start_date']] for result in results])
parameters = {}
parameters['*.__enabled__'] = False
parameters[trade_mid + '.__enabled__'] = True
parameters[trade_mid + '.instruments'] = mx.instrument_data
parameters[trade_mid + '.options_data'] = mx.data
trade = g.run(parameters)
return {'rollings': results, 'trade': trade}
m14 = M.hyper_rolling_train.v1(
run=m14_run_bigquant_run,
run_now=True,
bq_graph=g
)
[2022-04-12 12:48:27.889501] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-04-12 12:48:28.009527] INFO: moduleinvoker: instruments.v2 运行完成[0.119994s].
[2022-04-12 12:48:28.020684] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-04-12 12:48:28.030547] INFO: moduleinvoker: 命中缓存
[2022-04-12 12:48:28.032415] INFO: moduleinvoker: input_features.v1 运行完成[0.011787s].
[2022-04-12 12:48:28.038722] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-04-12 12:48:28.148281] INFO: moduleinvoker: instruments.v2 运行完成[0.109543s].
[2022-04-12 12:48:28.159858] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2022-04-12 12:48:29.120062] INFO: 自动标注(股票): 加载历史数据: 581647 行
[2022-04-12 12:48:29.122469] INFO: 自动标注(股票): 开始标注 ..
[2022-04-12 12:48:30.133368] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[1.97349s].
[2022-04-12 12:48:30.152519] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-12 12:48:59.184539] INFO: 基础特征抽取: 年份 2014, 特征行数=569948
[2022-04-12 12:49:06.716442] INFO: 基础特征抽取: 年份 2015, 特征行数=11699
[2022-04-12 12:49:06.778846] INFO: 基础特征抽取: 总行数: 581647
[2022-04-12 12:49:06.785460] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[36.632947s].
[2022-04-12 12:49:06.824271] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-12 12:49:20.779577] INFO: 基础特征抽取: 年份 2014, 特征行数=81185
[2022-04-12 12:49:29.155472] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
[2022-04-12 12:49:37.261908] INFO: 基础特征抽取: 年份 2016, 特征行数=28050
[2022-04-12 12:49:37.337307] INFO: 基础特征抽取: 总行数: 678933
[2022-04-12 12:49:37.342794] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[30.518548s].
[2022-04-12 12:49:37.359345] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-12 12:49:40.321435] INFO: derived_feature_extractor: 提取完成 mean(volume_0,90), 0.546s
[2022-04-12 12:49:40.326401] INFO: derived_feature_extractor: 提取完成 fs_net_cash_flow_0/fs_paicl_up_capital_0, 0.003s
[2022-04-12 12:49:40.867345] INFO: derived_feature_extractor: 提取完成 mean(volume_0,5), 0.539s
[2022-04-12 12:49:40.874615] INFO: derived_feature_extractor: 提取完成 fs_operating_revenue_ttm_0/(fs_total_liability_0+fs_total_equity_0), 0.005s
[2022-04-12 12:50:14.681334] INFO: derived_feature_extractor: /y_2014, 569948
[2022-04-12 12:50:50.850737] INFO: derived_feature_extractor: /y_2015, 11699
[2022-04-12 12:50:51.152052] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[73.792688s].
[2022-04-12 12:50:51.164471] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-12 12:51:19.858132] INFO: derived_feature_extractor: 提取完成 mean(volume_0,90), 0.669s
[2022-04-12 12:51:19.867881] INFO: derived_feature_extractor: 提取完成 fs_net_cash_flow_0/fs_paicl_up_capital_0, 0.006s
[2022-04-12 12:51:20.566870] INFO: derived_feature_extractor: 提取完成 mean(volume_0,5), 0.696s
[2022-04-12 12:51:20.574156] INFO: derived_feature_extractor: 提取完成 fs_operating_revenue_ttm_0/(fs_total_liability_0+fs_total_equity_0), 0.005s
[2022-04-12 12:51:43.946881] INFO: derived_feature_extractor: /y_2014, 81185
[2022-04-12 12:51:51.965232] INFO: derived_feature_extractor: /y_2015, 569698
[2022-04-12 12:51:57.299261] INFO: derived_feature_extractor: /y_2016, 28050
[2022-04-12 12:51:57.515929] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[66.351442s].
[2022-04-12 12:51:57.527867] INFO: moduleinvoker: join.v3 开始运行..
[2022-04-12 12:52:59.843423] INFO: join: /y_2014, 行数=566797/569948, 耗时=61.162724s
[2022-04-12 12:53:00.128093] INFO: join: /y_2015, 行数=0/11699, 耗时=0.269077s
[2022-04-12 12:53:00.204945] INFO: join: 最终行数: 566797
[2022-04-12 12:53:00.220303] INFO: moduleinvoker: join.v3 运行完成[62.692418s].
[2022-04-12 12:53:00.240047] INFO: moduleinvoker: filter_delist_stock.v4 开始运行..
[2022-04-12 12:53:05.140320] INFO: moduleinvoker: filter_delist_stock.v4 运行完成[4.900268s].
[2022-04-12 12:53:05.154841] INFO: moduleinvoker: filter_delist_stock.v4 开始运行..
[2022-04-12 12:53:08.224466] INFO: moduleinvoker: filter_delist_stock.v4 运行完成[3.069616s].
[2022-04-12 12:53:08.240566] INFO: moduleinvoker: filtet_st_stock.v2 开始运行..
[2022-04-12 12:53:10.840598] INFO: moduleinvoker: filtet_st_stock.v2 运行完成[2.600047s].
[2022-04-12 12:53:10.853579] INFO: moduleinvoker: filtet_st_stock.v2 开始运行..
[2022-04-12 12:53:13.101580] INFO: moduleinvoker: filtet_st_stock.v2 运行完成[2.247999s].
[2022-04-12 12:53:13.113137] INFO: moduleinvoker: dropnan.v2 开始运行..
[2022-04-12 12:53:14.194320] INFO: dropnan: /data, 423239/665614
[2022-04-12 12:53:14.259688] INFO: dropnan: 行数: 423239/665614
[2022-04-12 12:53:14.275496] INFO: moduleinvoker: dropnan.v2 运行完成[1.162362s].
[2022-04-12 12:53:14.287727] INFO: moduleinvoker: dropnan.v2 开始运行..
[2022-04-12 12:53:15.369111] INFO: dropnan: /data, 333684/554162
[2022-04-12 12:53:15.434293] INFO: dropnan: 行数: 333684/554162
[2022-04-12 12:53:15.444991] INFO: moduleinvoker: dropnan.v2 运行完成[1.15726s].
[2022-04-12 12:53:15.454692] INFO: moduleinvoker: stock_ranker_train.v6 开始运行..
[2022-04-12 12:53:15.992349] INFO: StockRanker: 特征预处理 ..
[2022-04-12 12:53:16.227302] INFO: StockRanker: prepare data: training ..
[2022-04-12 12:53:16.469394] INFO: StockRanker: sort ..
[2022-04-12 12:53:21.895895] INFO: StockRanker训练: 76b093b2 准备训练: 333684 行数
[2022-04-12 12:53:21.898114] INFO: StockRanker训练: AI模型训练,将在333684*8=266.95万数据上对模型训练进行20轮迭代训练。预计将需要2~4分钟。请耐心等待。
[2022-04-12 12:53:22.101250] INFO: StockRanker训练: 正在训练 ..
[2022-04-12 12:53:22.148298] INFO: StockRanker训练: 任务状态: Pending
[2022-04-12 12:53:32.191032] INFO: StockRanker训练: 任务状态: Running
[2022-04-12 12:54:32.488875] INFO: StockRanker训练: 00:01:04.7227457, finished iteration 1
[2022-04-12 12:54:42.550961] INFO: StockRanker训练: 00:01:07.9084359, finished iteration 2
[2022-04-12 12:54:42.553574] INFO: StockRanker训练: 00:01:11.2258711, finished iteration 3
[2022-04-12 12:54:42.555853] INFO: StockRanker训练: 00:01:14.7227632, finished iteration 4
[2022-04-12 12:54:52.605357] INFO: StockRanker训练: 00:01:18.1282642, finished iteration 5
[2022-04-12 12:54:52.607418] INFO: StockRanker训练: 00:01:21.6300447, finished iteration 6
[2022-04-12 12:54:52.609038] INFO: StockRanker训练: 00:01:25.1718903, finished iteration 7
[2022-04-12 12:55:02.666429] INFO: StockRanker训练: 00:01:28.6940991, finished iteration 8
[2022-04-12 12:55:02.668211] INFO: StockRanker训练: 00:01:32.3779005, finished iteration 9
[2022-04-12 12:55:02.669510] INFO: StockRanker训练: 00:01:36.0874253, finished iteration 10
[2022-04-12 12:55:12.716586] INFO: StockRanker训练: 00:01:39.8579849, finished iteration 11
[2022-04-12 12:55:12.718717] INFO: StockRanker训练: 00:01:43.8567205, finished iteration 12
[2022-04-12 12:55:22.758389] INFO: StockRanker训练: 00:01:47.9530599, finished iteration 13
[2022-04-12 12:55:22.760709] INFO: StockRanker训练: 00:01:52.1808940, finished iteration 14
[2022-04-12 12:55:32.807118] INFO: StockRanker训练: 00:01:56.5217537, finished iteration 15
[2022-04-12 12:55:32.809490] INFO: StockRanker训练: 00:02:00.7755698, finished iteration 16
[2022-04-12 12:55:32.812374] INFO: StockRanker训练: 00:02:04.8447397, finished iteration 17
[2022-04-12 12:55:42.858290] INFO: StockRanker训练: 00:02:08.9097666, finished iteration 18
[2022-04-12 12:55:42.860053] INFO: StockRanker训练: 00:02:12.9808948, finished iteration 19
[2022-04-12 12:56:07.131464] INFO: StockRanker训练: 任务状态: Succeeded
[2022-04-12 12:56:07.505403] INFO: moduleinvoker: stock_ranker_train.v6 运行完成[172.05075s].
[2022-04-12 12:56:07.517539] INFO: moduleinvoker: stock_ranker_predict.v5 开始运行..
[2022-04-12 12:56:07.991750] INFO: StockRanker预测: /data ..
[2022-04-12 12:56:08.985579] INFO: moduleinvoker: stock_ranker_predict.v5 运行完成[1.468023s].
[2022-04-12 12:56:08.995289] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-04-12 12:56:09.006030] INFO: moduleinvoker: 命中缓存
[2022-04-12 12:56:09.009127] INFO: moduleinvoker: instruments.v2 运行完成[0.013837s].
[2022-04-12 12:56:09.016269] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-04-12 12:56:09.025760] INFO: moduleinvoker: 命中缓存
[2022-04-12 12:56:09.028013] INFO: moduleinvoker: input_features.v1 运行完成[0.011753s].
[2022-04-12 12:56:09.035358] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-04-12 12:56:09.109248] INFO: moduleinvoker: instruments.v2 运行完成[0.073895s].
[2022-04-12 12:56:09.120866] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2022-04-12 12:56:09.724773] INFO: 自动标注(股票): 加载历史数据: 586049 行
[2022-04-12 12:56:09.726528] INFO: 自动标注(股票): 开始标注 ..
[2022-04-12 12:56:10.445978] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[1.3251s].
[2022-04-12 12:56:10.462263] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-12 12:56:16.144330] INFO: 基础特征抽取: 年份 2015, 特征行数=557999
[2022-04-12 12:56:20.528911] INFO: 基础特征抽取: 年份 2016, 特征行数=28050
[2022-04-12 12:56:20.596601] INFO: 基础特征抽取: 总行数: 586049
[2022-04-12 12:56:20.602798] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[10.140549s].
[2022-04-12 12:56:20.617729] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-04-12 12:56:24.945307] INFO: 基础特征抽取: 年份 2015, 特征行数=74873
[2022-04-12 12:56:30.557188] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
[2022-04-12 12:56:30.746668] INFO: 基础特征抽取: 总行数: 716419
[2022-04-12 12:56:30.754193] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[10.136471s].
[2022-04-12 12:56:30.763047] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-12 12:56:32.720035] INFO: derived_feature_extractor: 提取完成 mean(volume_0,90), 0.541s
[2022-04-12 12:56:32.726590] INFO: derived_feature_extractor: 提取完成 fs_net_cash_flow_0/fs_paicl_up_capital_0, 0.003s
[2022-04-12 12:56:33.177095] INFO: derived_feature_extractor: 提取完成 mean(volume_0,5), 0.449s
[2022-04-12 12:56:33.182435] INFO: derived_feature_extractor: 提取完成 fs_operating_revenue_ttm_0/(fs_total_liability_0+fs_total_equity_0), 0.003s
[2022-04-12 12:56:34.427756] INFO: derived_feature_extractor: /y_2015, 557999
[2022-04-12 12:56:34.909939] INFO: derived_feature_extractor: /y_2016, 28050
[2022-04-12 12:56:35.048191] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[4.285127s].
[2022-04-12 12:56:35.057098] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-04-12 12:56:37.434958] INFO: derived_feature_extractor: 提取完成 mean(volume_0,90), 0.669s
[2022-04-12 12:56:37.440011] INFO: derived_feature_extractor: 提取完成 fs_net_cash_flow_0/fs_paicl_up_capital_0, 0.003s
[2022-04-12 12:56:38.144257] INFO: derived_feature_extractor: 提取完成 mean(volume_0,5), 0.702s
[2022-04-12 12:56:38.150134] INFO: derived_feature_extractor: 提取完成 fs_operating_revenue_ttm_0/(fs_total_liability_0+fs_total_equity_0), 0.004s
[2022-04-12 12:56:38.450471] INFO: derived_feature_extractor: /y_2015, 74873
[2022-04-12 12:56:39.776594] INFO: derived_feature_extractor: /y_2016, 641546
[2022-04-12 12:56:40.336556] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[5.279445s].
[2022-04-12 12:56:40.350449] INFO: moduleinvoker: join.v3 开始运行..
[2022-04-12 12:56:43.414906] INFO: join: /y_2015, 行数=547850/557999, 耗时=1.898438s
[2022-04-12 12:56:43.685234] INFO: join: /y_2016, 行数=14954/28050, 耗时=0.265325s
[2022-04-12 12:56:43.760388] INFO: join: 最终行数: 562804
[2022-04-12 12:56:43.775253] INFO: moduleinvoker: join.v3 运行完成[3.424794s].
[2022-04-12 12:56:43.794053] INFO: moduleinvoker: filter_delist_stock.v4 开始运行..
[2022-04-12 12:56:46.976859] INFO: moduleinvoker: filter_delist_stock.v4 运行完成[3.182821s].
[2022-04-12 12:56:46.988856] INFO: moduleinvoker: filter_delist_stock.v4 开始运行..
[2022-04-12 12:56:49.799680] INFO: moduleinvoker: filter_delist_stock.v4 运行完成[2.810766s].
[2022-04-12 12:56:49.816737] INFO: moduleinvoker: filtet_st_stock.v2 开始运行..
[2022-04-12 12:56:52.041570] INFO: moduleinvoker: filtet_st_stock.v2 运行完成[2.224854s].
[2022-04-12 12:56:52.052887] INFO: moduleinvoker: filtet_st_stock.v2 开始运行..
[2022-04-12 12:56:54.317684] INFO: moduleinvoker: filtet_st_stock.v2 运行完成[2.264725s].
[2022-04-12 12:56:54.329656] INFO: moduleinvoker: dropnan.v2 开始运行..
[2022-04-12 12:56:55.668979] INFO: dropnan: /data, 445156/702179
[2022-04-12 12:56:55.729904] INFO: dropnan: 行数: 445156/702179
[2022-04-12 12:56:55.742607] INFO: moduleinvoker: dropnan.v2 运行完成[1.412962s].
[2022-04-12 12:56:55.752437] INFO: moduleinvoker: dropnan.v2 开始运行..
[2022-04-12 12:56:56.706379] INFO: dropnan: /data, 316327/552334
[2022-04-12 12:56:56.772252] INFO: dropnan: 行数: 316327/552334
[2022-04-12 12:56:56.782715] INFO: moduleinvoker: dropnan.v2 运行完成[1.030268s].
[2022-04-12 12:56:56.790746] INFO: moduleinvoker: stock_ranker_train.v6 开始运行..
[2022-04-12 12:56:57.397266] INFO: StockRanker: 特征预处理 ..
[2022-04-12 12:56:57.679991] INFO: StockRanker: prepare data: training ..
[2022-04-12 12:56:57.919405] INFO: StockRanker: sort ..
[2022-04-12 12:57:02.019257] INFO: StockRanker训练: fa9c222c 准备训练: 316327 行数
[2022-04-12 12:57:02.021682] INFO: StockRanker训练: AI模型训练,将在316327*8=253.06万数据上对模型训练进行20轮迭代训练。预计将需要2~3分钟。请耐心等待。
[2022-04-12 12:57:02.204980] INFO: StockRanker训练: 正在训练 ..
[2022-04-12 12:57:02.256021] INFO: StockRanker训练: 任务状态: Pending
[2022-04-12 12:57:12.302499] INFO: StockRanker训练: 任务状态: Running
[2022-04-12 12:58:12.614390] INFO: StockRanker训练: 00:01:04.1988338, finished iteration 1
[2022-04-12 12:58:22.663431] INFO: StockRanker训练: 00:01:06.7044409, finished iteration 2
[2022-04-12 12:58:22.665152] INFO: StockRanker训练: 00:01:09.2662601, finished iteration 3
[2022-04-12 12:58:22.666682] INFO: StockRanker训练: 00:01:12.0904306, finished iteration 4
[2022-04-12 12:58:22.668273] INFO: StockRanker训练: 00:01:14.7738225, finished iteration 5
[2022-04-12 12:58:32.712829] INFO: StockRanker训练: 00:01:17.4982157, finished iteration 6
[2022-04-12 12:58:32.714719] INFO: StockRanker训练: 00:01:20.2865553, finished iteration 7
[2022-04-12 12:58:32.716279] INFO: StockRanker训练: 00:01:23.5805005, finished iteration 8
[2022-04-12 12:58:42.760477] INFO: StockRanker训练: 00:01:26.7905164, finished iteration 9
[2022-04-12 12:58:42.762212] INFO: StockRanker训练: 00:01:30.2866889, finished iteration 10
[2022-04-12 12:58:42.763832] INFO: StockRanker训练: 00:01:34.0717130, finished iteration 11
[2022-04-12 12:58:52.806965] INFO: StockRanker训练: 00:01:37.0952408, finished iteration 12
[2022-04-12 12:58:52.809216] INFO: StockRanker训练: 00:01:40.3287932, finished iteration 13
[2022-04-12 12:58:52.810945] INFO: StockRanker训练: 00:01:44.6920449, finished iteration 14
[2022-04-12 12:59:02.860911] INFO: StockRanker训练: 00:01:48.0006448, finished iteration 15
[2022-04-12 12:59:02.862948] INFO: StockRanker训练: 00:01:50.9416003, finished iteration 16
[2022-04-12 12:59:02.864722] INFO: StockRanker训练: 00:01:53.8072615, finished iteration 17
[2022-04-12 12:59:12.968457] INFO: StockRanker训练: 00:01:56.9817603, finished iteration 18
[2022-04-12 12:59:12.970653] INFO: StockRanker训练: 00:02:00.1468818, finished iteration 19
[2022-04-12 12:59:12.972372] INFO: StockRanker训练: 00:02:03.4869882, finished iteration 20
[2022-04-12 12:59:23.026158] INFO: StockRanker训练: 任务状态: Succeeded
[2022-04-12 12:59:23.173763] INFO: moduleinvoker: stock_ranker_train.v6 运行完成[146.382998s].
[2022-04-12 12:59:23.184099] INFO: moduleinvoker: stock_ranker_predict.v5 开始运行..
[2022-04-12 12:59:23.589092] INFO: StockRanker预测: /data ..
[2022-04-12 12:59:24.811905] INFO: moduleinvoker: stock_ranker_predict.v5 运行完成[1.627791s].
[2022-04-12 12:59:24.852807] INFO: moduleinvoker: cached.v3 开始运行..
[2022-04-12 12:59:26.025227] INFO: moduleinvoker: cached.v3 运行完成[1.172437s].
[2022-04-12 12:59:26.081949] INFO: moduleinvoker: backtest.v8 开始运行..
[2022-04-12 12:59:26.088208] INFO: backtest: biglearning backtest:V8.6.2
[2022-04-12 12:59:26.184707] INFO: backtest: product_type:stock by specified
[2022-04-12 12:59:26.271777] INFO: moduleinvoker: cached.v2 开始运行..
[2022-04-12 12:59:33.338987] INFO: backtest: 读取股票行情完成:2307626
[2022-04-12 12:59:36.354284] INFO: moduleinvoker: cached.v2 运行完成[10.082529s].
[2022-04-12 12:59:38.526858] INFO: algo: TradingAlgorithm V1.8.7
[2022-04-12 12:59:39.471698] INFO: algo: trading transform...
[2022-04-12 12:59:42.603331] INFO: Performance: Simulated 486 trading days out of 486.
[2022-04-12 12:59:42.607286] INFO: Performance: first open: 2020-01-02 09:30:00+00:00
[2022-04-12 12:59:42.609257] INFO: Performance: last close: 2021-12-31 15:00:00+00:00
[2022-04-12 12:59:45.944090] INFO: moduleinvoker: backtest.v8 运行完成[19.86216s].
[2022-04-12 12:59:45.946346] INFO: moduleinvoker: trade.v4 运行完成[19.910617s].
[2022-04-12 12:59:45.948146] INFO: moduleinvoker: hyper_rolling_train.v1 运行完成[678.092558s].