lstm择时与stockrank选股实盘的问题


(ahxdct) #1

择时在测试训练时有输出,实盘模拟后就没输出了,附策略日志,请大神指教!

In [1]:
# 本代码由可视化策略环境自动生成 2019年2月15日 08:35
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。


# 回测引擎:每日数据处理函数,每天执行一次
def m19_handle_data_bigquant_run(context, data):
    # 按日期过滤得到今日的预测数据
    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

    #---------------------START:大盘风控(含建仓期)--------------------------
    today_date = data.current_dt.strftime('%Y-%m-%d')
    positions_all = [equity.symbol for equity in context.portfolio.positions]
    #ds_id=context.predataid
    #today_prediction = DataSource(id=ds_id).read_pickle()
    dataprediction=context.dataprediction
    today_prediction=dataprediction[dataprediction.date==today_date].direction.values[0]
    print(today_date,'预测仓位',today_prediction)
    # 满足空仓条件
    if today_prediction<0:	
        if len(positions_all)>0:
            # 全部卖出后返回
            for i in positions_all:
                if data.can_trade(context.symbol(i)):
                    context.order_target_percent(context.symbol(i), 0)
                    print('风控执行',today_date)
                    return
                #运行风控后当日结束,不再执行后续的买卖订单
    #------------------------END:大盘风控(含建仓期)---------------------------
    
    
    # 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):
    seq_len=5    #每个input的长度
    # 导入包
    from keras.layers.core import Dense, Activation, Dropout
    from keras.layers.recurrent import LSTM
    from keras.models import Sequential
    from keras import optimizers
    import tensorflow as tf   
    from sklearn.preprocessing import scale
    from keras.layers import Input, Dense, LSTM, merge
    from keras.models import Model
    # 基础参数配置
    instrument = '000300.SHA'  #股票代码
    #设置用于训练和回测的开始/结束日期
    train_length=seq_len*10
    start_date_temp= (pd.to_datetime(context.start_date) - datetime.timedelta(days=2*train_length)).strftime('%Y-%m-%d') # 多取几天的数据,这里取5倍
    len1=len(D.trading_days(start_date=start_date_temp, end_date=context.end_date)) 
    len2=len(D.trading_days(start_date=context.start_date, end_date=context.end_date))
    distance=len1-len2
    trade_day=D.trading_days(start_date=start_date_temp, end_date=context.end_date)
    start_date = trade_day.iloc[distance-train_length][0].strftime('%Y-%m-%d')
    split_date = trade_day.iloc[distance-1][0].strftime('%Y-%m-%d')
    #print('start_date',start_date,'split_date',split_date)
    fields = ['close', 'open', 'high', 'low', 'amount', 'volume']  # features因子
    batch = 100#整数,指定进行梯度下降时每个batch包含的样本数,训练时一个batch的样本会被计算一次梯度下降,使目标函数优化一步
    
    # 数据导入以及初步处理
    data1 = D.history_data(instrument, start_date, context.end_date, fields)
    data1['return'] = data1['close'].shift(-5) / data1['open'].shift(-1) - 1 #计算未来5日收益率(未来第五日的收盘价/明日的开盘价)
    data1=data1[data1.amount>0]
    datatime = data1['date'][data1.date>split_date]  #记录predictions的时间,回测要用
    data1['return'] = data1['return']#.apply(lambda x:np.where(x>=0.2,0.2,np.where(x>-0.2,x,-0.2)))  #去极值
    data1['return'] = data1['return']*10  # 适当增大return范围,利于LSTM模型训练
    data1.reset_index(drop=True, inplace=True)
    scaledata = data1[fields]
    traindata = data1[data1.date<=split_date]
    
    # 数据处理:设定每个input(series×6features)以及数据标准化
    train_input = []
    train_output = []
    test_input = []
    for i in range(seq_len-1, len(traindata)):
        a = scale(scaledata[i+1-seq_len:i+1])
        train_input.append(a)
        c = data1['return'][i]
        train_output.append(c)
    for j in range(len(traindata), len(data1)):
        b = scale(scaledata[j+1-seq_len:j+1])
        test_input.append(b)


    # LSTM接受数组类型的输入
    train_x = np.array(train_input)
    train_y = np.array(train_output)
    test_x = np.array(test_input) 

    # 自定义激活函数
    import tensorflow as tf
    def atan(x): 
        return tf.atan(x)
    # 构建神经网络层 1层LSTM层+3层Dense层
    # 用于1个输入情况
    lstm_input = Input(shape=(seq_len,len(fields)), name='lstm_input')
    lstm_output = LSTM(32, activation=atan, dropout_W=0.2, dropout_U=0.1)(lstm_input)
    Dense_output_1 = Dense(16, activation='linear')(lstm_output)
    Dense_output_2 = Dense(4, activation='linear')(Dense_output_1)
    predictions = Dense(1, activation=atan)(Dense_output_2)
    model = Model(input=lstm_input, output=predictions)
    model.compile(optimizer='adam', loss='mse', metrics=['mse'])
    model.fit(train_x, train_y, batch_size=batch, nb_epoch=5, verbose=0)
    # 预测
    predictions = model.predict(test_x)
    # 如果预测值>0,取为1;如果预测值<=0,取为-1.为回测做准备
    for i in range(len(predictions)):
        if predictions[i]>0:
            predictions[i]=1
        elif predictions[i]<=0:
            predictions[i]=-1
            
    # 将预测值与时间整合作为回测数据
    cc = np.reshape(predictions,len(predictions), 1)
    dataprediction = pd.DataFrame()
    dataprediction['date'] = datatime
    dataprediction['direction']=np.round(cc)
    context.dataprediction=dataprediction

# 回测引擎:初始化函数,只执行一次
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)
    # 设置买入的股票数量,这里买入预测股票列表排名靠前的4只
    stock_count = 4
    # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.25
    context.options['hold_days'] = 5




[2019-02-15 08:36:44.005188] INFO: bigquant: instruments.v2 开始运行..
[2019-02-15 08:36:44.022804] INFO: bigquant: 命中缓存
[2019-02-15 08:36:44.023636] INFO: bigquant: instruments.v2 运行完成[0.018503s].
[2019-02-15 08:36:44.028515] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
[2019-02-15 08:36:46.451825] INFO: bigquant: 命中缓存
[2019-02-15 08:36:46.453307] INFO: bigquant: advanced_auto_labeler.v2 运行完成[2.424782s].
[2019-02-15 08:36:46.458373] INFO: bigquant: input_features.v1 开始运行..
[2019-02-15 08:36:46.543567] INFO: bigquant: 命中缓存
[2019-02-15 08:36:46.544367] INFO: bigquant: input_features.v1 运行完成[0.086007s].
[2019-02-15 08:36:46.761970] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2019-02-15 08:36:55.971230] INFO: 基础特征抽取: 年份 2013, 特征行数=235077
[2019-02-15 08:37:06.078155] INFO: 基础特征抽取: 年份 2014, 特征行数=569948
[2019-02-15 08:37:13.671492] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
[2019-02-15 08:37:19.685493] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
[2019-02-15 08:37:34.791484] INFO: 基础特征抽取: 年份 2017, 特征行数=743233
[2019-02-15 08:37:44.674096] INFO: 基础特征抽取: 年份 2018, 特征行数=325311
[2019-02-15 08:37:49.176825] INFO: 基础特征抽取: 总行数: 3084813
[2019-02-15 08:37:49.182568] INFO: bigquant: general_feature_extractor.v7 运行完成[62.42061s].
[2019-02-15 08:37:49.282300] INFO: bigquant: chinaa_stock_filter.v1 开始运行..
[2019-02-15 08:37:51.194088] INFO: A股股票过滤: 过滤 /y_2013, 230456/0/235077
[2019-02-15 08:37:52.924201] INFO: A股股票过滤: 过滤 /y_2014, 561221/0/569948
[2019-02-15 08:37:54.715432] INFO: A股股票过滤: 过滤 /y_2015, 561179/0/569698
[2019-02-15 08:37:56.817054] INFO: A股股票过滤: 过滤 /y_2016, 630635/0/641546
[2019-02-15 08:37:59.994110] INFO: A股股票过滤: 过滤 /y_2017, 730744/0/743233
[2019-02-15 08:38:03.410894] INFO: A股股票过滤: 过滤 /y_2018, 319242/0/325311
[2019-02-15 08:38:03.414293] INFO: A股股票过滤: 过滤完成, 3033477 + 0
[2019-02-15 08:38:03.904736] INFO: bigquant: chinaa_stock_filter.v1 运行完成[14.622433s].
[2019-02-15 08:38:03.958174] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2019-02-15 08:38:06.723182] INFO: derived_feature_extractor: 提取完成 where(ta_cci_14_0>100,delta(ta_cci_14_0,1),where(ta_cci_14_0<-100,delta(ta_cci_14_0,1),0)), 0.879s
[2019-02-15 08:38:06.744524] INFO: derived_feature_extractor: 提取完成 arctan(avg_turn_5*return_5), 0.020s
[2019-02-15 08:38:06.765955] INFO: derived_feature_extractor: 提取完成 arctan(where(ta_macd_macd_12_26_9_0>0,swing_volatility_5_0,swing_volatility_5_0*-1)), 0.021s
[2019-02-15 08:38:06.787033] INFO: derived_feature_extractor: 提取完成 arctan(avg_mf_net_amount_5/avg_amount_5), 0.020s
[2019-02-15 08:38:07.212153] INFO: derived_feature_extractor: 提取完成 where(delta(ta_macd_macd_12_26_9_0,1)>0,ta_aroon_up_14_0*ta_aroon_down_14_0,ta_aroon_up_14_0*ta_aroon_down_14_0*-1), 0.424s
[2019-02-15 08:38:07.692986] INFO: derived_feature_extractor: 提取完成 arcsin(where(delta(ta_macd_macd_12_26_9_0,1)>0,(1-turn_5*0.01)*(1-turn_0*0.01)*(1-turn_1*0.01)*(1-turn_2*0.01)*(1-turn_3*0.01)*(1-turn_4*0.01),(1-turn_5*0.01)*(1-turn_0*0.01)*(1-turn_1*0.01)*(1-turn_2*0.01)*(1-turn_3*0.01)*(1-turn_4*0.01)*-1)), 0.480s
[2019-02-15 08:38:07.777993] INFO: derived_feature_extractor: 提取完成 arctan2((close_0-close_1),(close_1-close_2)), 0.084s
[2019-02-15 08:38:09.775435] INFO: derived_feature_extractor: /y_2013, 230456
[2019-02-15 08:38:10.036408] INFO: derived_feature_extractor: /y_2014, 561221
[2019-02-15 08:38:10.498138] INFO: derived_feature_extractor: /y_2015, 561179
[2019-02-15 08:38:10.974669] INFO: derived_feature_extractor: /y_2016, 630635
[2019-02-15 08:38:11.617783] INFO: derived_feature_extractor: /y_2017, 730744
[2019-02-15 08:38:16.125938] INFO: derived_feature_extractor: /y_2018, 319242
[2019-02-15 08:38:17.512148] INFO: bigquant: derived_feature_extractor.v3 运行完成[13.553976s].
[2019-02-15 08:38:17.534349] INFO: bigquant: join.v3 开始运行..
[2019-02-15 08:38:34.322630] INFO: join: /y_2013, 行数=0/230456, 耗时=0.875313s
[2019-02-15 08:38:35.716221] INFO: join: /y_2014, 行数=559265/561221, 耗时=1.388608s
[2019-02-15 08:38:37.047078] INFO: join: /y_2015, 行数=552424/561179, 耗时=1.316755s
[2019-02-15 08:38:38.587110] INFO: join: /y_2016, 行数=626759/630635, 耗时=1.525025s
[2019-02-15 08:38:43.969194] INFO: join: /y_2017, 行数=725909/730744, 耗时=5.366012s
[2019-02-15 08:38:45.136005] INFO: join: /y_2018, 行数=301149/319242, 耗时=1.146373s
[2019-02-15 08:38:46.191732] INFO: join: 最终行数: 2765506
[2019-02-15 08:38:46.193827] INFO: bigquant: join.v3 运行完成[28.659484s].
[2019-02-15 08:38:46.217963] INFO: bigquant: dropnan.v1 开始运行..
[2019-02-15 08:38:46.342321] INFO: dropnan: /y_2013, 0/0
[2019-02-15 08:38:47.345998] INFO: dropnan: /y_2014, 556148/559265
[2019-02-15 08:38:48.198030] INFO: dropnan: /y_2015, 547654/552424
[2019-02-15 08:38:49.121493] INFO: dropnan: /y_2016, 622358/626759
[2019-02-15 08:38:50.450194] INFO: dropnan: /y_2017, 714162/725909
[2019-02-15 08:38:54.852306] INFO: dropnan: /y_2018, 299339/301149
[2019-02-15 08:38:55.332935] INFO: dropnan: 行数: 2739661/2765506
[2019-02-15 08:38:55.343308] INFO: bigquant: dropnan.v1 运行完成[9.125324s].
[2019-02-15 08:38:55.361676] INFO: bigquant: stock_ranker_train.v5 开始运行..
[2019-02-15 08:38:59.582867] INFO: StockRanker: 特征预处理 ..
[2019-02-15 08:39:02.307798] INFO: StockRanker: prepare data: training ..
[2019-02-15 08:39:06.166812] INFO: StockRanker: sort ..
[2019-02-15 08:39:34.131205] INFO: StockRanker训练: 131442f2 准备训练: 2739661 行数
[2019-02-15 08:39:38.433156] INFO: StockRanker训练: 正在训练 ..
[2019-02-15 08:50:11.751745] INFO: bigquant: stock_ranker_train.v5 运行完成[676.390083s].
[2019-02-15 08:50:11.754342] INFO: bigquant: instruments.v2 开始运行..
[2019-02-15 08:50:11.759899] INFO: bigquant: 命中缓存
[2019-02-15 08:50:11.760601] INFO: bigquant: instruments.v2 运行完成[0.006294s].
[2019-02-15 08:50:11.767162] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2019-02-15 08:50:14.832013] INFO: 基础特征抽取: 年份 2018, 特征行数=241718
[2019-02-15 08:50:15.794222] INFO: 基础特征抽取: 年份 2019, 特征行数=96149
[2019-02-15 08:50:17.348496] INFO: 基础特征抽取: 总行数: 337867
[2019-02-15 08:50:17.351687] INFO: bigquant: general_feature_extractor.v7 运行完成[5.584491s].
[2019-02-15 08:50:17.353750] INFO: bigquant: chinaa_stock_filter.v1 开始运行..
[2019-02-15 08:50:18.659109] INFO: A股股票过滤: 过滤 /y_2018, 236442/0/241718
[2019-02-15 08:50:20.106502] INFO: A股股票过滤: 过滤 /y_2019, 93984/0/96149
[2019-02-15 08:50:20.108856] INFO: A股股票过滤: 过滤完成, 330426 + 0
[2019-02-15 08:50:20.559340] INFO: bigquant: chinaa_stock_filter.v1 运行完成[3.205564s].
[2019-02-15 08:50:20.561635] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2019-02-15 08:50:20.839023] INFO: derived_feature_extractor: 提取完成 where(ta_cci_14_0>100,delta(ta_cci_14_0,1),where(ta_cci_14_0<-100,delta(ta_cci_14_0,1),0)), 0.083s
[2019-02-15 08:50:20.843169] INFO: derived_feature_extractor: 提取完成 arctan(avg_turn_5*return_5), 0.003s
[2019-02-15 08:50:20.846780] INFO: derived_feature_extractor: 提取完成 arctan(where(ta_macd_macd_12_26_9_0>0,swing_volatility_5_0,swing_volatility_5_0*-1)), 0.003s
[2019-02-15 08:50:20.850734] INFO: derived_feature_extractor: 提取完成 arctan(avg_mf_net_amount_5/avg_amount_5), 0.003s
[2019-02-15 08:50:20.892710] INFO: derived_feature_extractor: 提取完成 where(delta(ta_macd_macd_12_26_9_0,1)>0,ta_aroon_up_14_0*ta_aroon_down_14_0,ta_aroon_up_14_0*ta_aroon_down_14_0*-1), 0.041s
[2019-02-15 08:50:20.937079] INFO: derived_feature_extractor: 提取完成 arcsin(where(delta(ta_macd_macd_12_26_9_0,1)>0,(1-turn_5*0.01)*(1-turn_0*0.01)*(1-turn_1*0.01)*(1-turn_2*0.01)*(1-turn_3*0.01)*(1-turn_4*0.01),(1-turn_5*0.01)*(1-turn_0*0.01)*(1-turn_1*0.01)*(1-turn_2*0.01)*(1-turn_3*0.01)*(1-turn_4*0.01)*-1)), 0.043s
[2019-02-15 08:50:20.942313] INFO: derived_feature_extractor: 提取完成 arctan2((close_0-close_1),(close_1-close_2)), 0.004s
[2019-02-15 08:50:21.254530] INFO: derived_feature_extractor: /y_2018, 236442
[2019-02-15 08:50:21.494789] INFO: derived_feature_extractor: /y_2019, 93984
[2019-02-15 08:50:23.226672] INFO: bigquant: derived_feature_extractor.v3 运行完成[2.665021s].
[2019-02-15 08:50:23.228833] INFO: bigquant: dropnan.v1 开始运行..
[2019-02-15 08:50:23.933241] INFO: dropnan: /y_2018, 233579/236442
[2019-02-15 08:50:24.049046] INFO: dropnan: /y_2019, 93521/93984
[2019-02-15 08:50:25.357953] INFO: dropnan: 行数: 327100/330426
[2019-02-15 08:50:25.362551] INFO: bigquant: dropnan.v1 运行完成[2.133708s].
[2019-02-15 08:50:25.383669] INFO: bigquant: stock_ranker_predict.v5 开始运行..
[2019-02-15 08:50:25.822498] INFO: StockRanker: prepare data: prediction ..
[2019-02-15 08:50:31.269661] INFO: stock_ranker_predict: 准备预测: 327100 行
[2019-02-15 08:50:31.270698] INFO: stock_ranker_predict: 正在预测 ..
[2019-02-15 08:50:51.564335] INFO: bigquant: stock_ranker_predict.v5 运行完成[26.180651s].
[2019-02-15 08:50:51.596693] INFO: forward_register: start to register
[2019-02-15 08:50:51.931926] INFO: forward_register: done of register, create new record
[2019-02-15 08:50:53.660138] INFO: forward_test: init username:ahxdct, algo_id:11388, first_date:2019-02-14, frequency:daily, price_type:post_right, instruments:['000001.SZA', '000002.SZA', '000004.SZA', '000005.SZA', '000006.SZA', '000007.SZA', '000008.SZA', '000009.SZA', '000010.SZA', '000011.SZA', '000012.SZA', '000014.SZA', '000016.SZA', '000017.SZA', '000018.SZA', '000019.SZA', '000020.SZA', '000021.SZA', '000022.SZA', '000023.SZA', '000025.SZA', '000026.SZA', '000027.SZA', '000028.SZA', '000029.SZA', '000030.SZA', '000031.SZA', '000032.SZA', '000034.SZA', '000035.SZA', '000036.SZA', '000037.SZA']
[2019-02-15 08:50:53.661400] INFO: forward_test: biglearning forward test:V5.1.6
[2019-02-15 08:50:53.683042] INFO: forward_test: run_date: 2019-02-14, notebook_id:ahxdct_a5a8c332-30b9-11e9-88a5-0a580a8104e7, algo_name:AI2019策略V9
[2019-02-15 08:50:53.687534] INFO: forward_test: last record: None
[2019-02-15 08:50:53.690417] INFO: forward_test: today record: None
[2019-02-15 08:50:53.692716] INFO: forward_test: first record: None
[2019-02-15 08:50:53.816101] INFO: algo: init() show_debug_info:True, standard_mode:True, instant_fill:False, third_match_model:False, papertrading:True
[2019-02-15 08:50:53.816880] INFO: algo: init() daily start:2019-02-14 00:00:00+00:00 ~ end:2019-02-14 00:00:00+00:00
[2019-02-15 08:50:53.817502] INFO: factory: create simulation parameters [start:2019-02-14 00:00:00+00:00, end:2019-02-14 00:00:00+00:00]
[2019-02-15 08:50:53.818172] INFO: Trading: SimulationParameters start_session:2019-02-14 00:00:00+00:00, end_session:2019-02-14 00:00:00+00:00, emission_rate:daily, arena:backtest
[2019-02-15 08:50:53.819175] INFO: Trading: SimulationParameters _first_open:2019-02-14 09:30:00+00:00, _last_close:2019-02-14 15:00:00+00:00

Using TensorFlow backend.

[2019-02-15 08:51:04.650880] INFO: forward_test: instruments type <class 'list'>, <class 'list'>, <class 'list'>
<class 'pandas.core.panel.Panel'>
Dimensions: 3586 (items) x 238 (major_axis) x 9 (minor_axis)
Items axis: 000001.SZA to 603999.SHA
Major_axis axis: 2018-02-22 00:00:00 to 2019-02-14 00:00:00
Minor_axis axis: high to delist_date
[2019-02-15 08:51:15.831587] INFO: algo: TradingAlgorithm V1.4.6
[2019-02-15 08:51:15.845996] INFO: algo: data.major_axis0: 2018-02-22 00:00:00+00:00
[2019-02-15 08:51:15.846835] INFO: algo: data.major_axis-1: 2019-02-14 00:00:00+00:00
[2019-02-15 08:51:29.151095] INFO: forward_test: c_initialize() positions len:0, value:0.0
[2019-02-15 08:51:29.152281] INFO: forward_test: c_initialize() orders len:0
[2019-02-15 08:51:29.152967] INFO: algo: init() setting[data_frequency:daily, product_type:stock,price_type:backward_adjusted,amount_integer:False,leverage_type:fill_amap,max_leverage:1.0,need_settle:False]
[2019-02-15 08:51:29.154137] INFO: algo: trading transform...
2019-02-14 预测仓位 nan
[2019-02-15 08:51:29.162486] INFO: Blotter: place order [sid:1378, oid:601948, symbol:000678.SZA, amount:2632.34178290825, position_effect:None, is_stored_order:False], dt:2019-02-14 15:00:00+00:00
[2019-02-15 08:51:29.164045] INFO: Blotter: place order [sid:2665, oid:4210d0, symbol:002531.SZA, amount:1187.131719240276, position_effect:None, is_stored_order:False], dt:2019-02-14 15:00:00+00:00
[2019-02-15 08:51:29.165409] INFO: Blotter: place order [sid:1945, oid:eec434, symbol:002786.SZA, amount:1456.3171934347401, position_effect:None, is_stored_order:False], dt:2019-02-14 15:00:00+00:00
[2019-02-15 08:51:29.166767] INFO: Blotter: place order [sid:2113, oid:8e4003, symbol:002474.SZA, amount:737.4690538751684, position_effect:None, is_stored_order:False], dt:2019-02-14 15:00:00+00:00
[2019-02-15 08:51:29.172064] INFO: algo: daily_perf orders:[{'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(1378 [000678.SZA]), 'limit_reached': False, 'id': '601948e39fb348a095adde782e906676', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 2632.34178290825, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None}, {'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(2665 [002531.SZA]), 'limit_reached': False, 'id': '4210d0b2bc464b8bab787801823e7cf9', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 1187.131719240276, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None}, {'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(1945 [002786.SZA]), 'limit_reached': False, 'id': 'eec434b2f9f94e1d8bd4637578406c1c', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 1456.3171934347401, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None}, {'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(2113 [002474.SZA]), 'limit_reached': False, 'id': '8e40039a69d142bc965d32a7c422b0a5', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 737.4690538751684, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None}]
[2019-02-15 08:51:29.172708] INFO: Performance: Simulated 1 trading days out of 1.
[2019-02-15 08:51:29.173278] INFO: Performance: first open: 2019-02-14 09:30:00+00:00
[2019-02-15 08:51:29.173803] INFO: Performance: last close: 2019-02-14 15:00:00+00:00
[2019-02-15 08:51:29.212358] INFO: forward_test: get last row of algo result_1:                            algorithm_period_return  alpha  \
2019-02-14 15:00:00+00:00                      0.0      0   

                           benchmark_period_return  beta  capital_used  \
2019-02-14 15:00:00+00:00                 0.001505     0           0.0   

                           ending_cash  ending_value  long_value  longs_count  \
2019-02-14 15:00:00+00:00    1000000.0           0.0           0            0   

                           max_drawdown  
2019-02-14 15:00:00+00:00           0.0  
[2019-02-15 08:51:29.218949] INFO: forward_test: get last row of algo result_2:                                        period_close period_label  \
2019-02-14 15:00:00+00:00 2019-02-14 15:00:00+00:00      2019-02   

                                        period_open  pnl  portfolio_value  \
2019-02-14 15:00:00+00:00 2019-02-14 09:30:00+00:00  0.0        1000000.0   

                           returns  short_value  shorts_count  sortino  \
2019-02-14 15:00:00+00:00      0.0            0             0        0   

                           starting_cash  starting_value  trading_days  
2019-02-14 15:00:00+00:00      1000000.0             0.0             1  
[2019-02-15 08:51:29.303107] INFO: forward_test: get_orders new_orders 4:
{'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(1378 [000678.SZA]), 'limit_reached': False, 'id': '601948e39fb348a095adde782e906676', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 2632.34178290825, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None},
{'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(2665 [002531.SZA]), 'limit_reached': False, 'id': '4210d0b2bc464b8bab787801823e7cf9', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 1187.131719240276, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None},
{'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(1945 [002786.SZA]), 'limit_reached': False, 'id': 'eec434b2f9f94e1d8bd4637578406c1c', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 1456.3171934347401, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None},
{'stop': None, 'reason': None, 'last_filled': 0, 'commission': 0, 'stop_reached': False, 'sid': Equity(2113 [002474.SZA]), 'limit_reached': False, 'id': '8e40039a69d142bc965d32a7c422b0a5', 'dt': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'position_effect': None, 'filled': 0, 'amount': 737.4690538751684, 'created': Timestamp('2019-02-15 09:30:00+0000', tz='UTC'), 'status': 0, 'limit': None}, 
json_orders:
{'name': '襄阳轴承', 'dt': '2019-02-15 09:30:00', 'sid': '000678.SZA', 'adjust_factor': 4.959914207458496, 'amount_after_adjust': 13056, 'amount': 2632.34178290825, 'price': 5.98, 'date': '2019-02-14', 'direction': '买'},
{'name': '天顺风能', 'dt': '2019-02-15 09:30:00', 'sid': '002531.SZA', 'adjust_factor': 7.814571857452393, 'amount_after_adjust': 9276, 'amount': 1187.131719240276, 'price': 5.31, 'date': '2019-02-14', 'direction': '买'},
{'name': '银宝山新', 'dt': '2019-02-15 09:30:00', 'sid': '002786.SZA', 'adjust_factor': 3.018691062927246, 'amount_after_adjust': 4396, 'amount': 1456.3171934347401, 'price': 8.88, 'date': '2019-02-14', 'direction': '买'},
{'name': '榕基软件', 'dt': '2019-02-15 09:30:00', 'sid': '002474.SZA', 'adjust_factor': 6.246003150939941, 'amount_after_adjust': 4606, 'amount': 737.4690538751684, 'price': 7.3, 'date': '2019-02-14', 'direction': '买'}
[2019-02-15 08:51:29.304101] INFO: forward_test: get_last_sale_date_dict: {'002786.SZA': '2019-02-15 09:30:00+00:00', '002474.SZA': '2019-02-15 09:30:00+00:00', '002531.SZA': '2019-02-15 09:30:00+00:00', '000678.SZA': '2019-02-15 09:30:00+00:00'}
[2019-02-15 08:51:29.353182] INFO: forward_test: get_positions_stocks position_value:0.0 new_positions:
 
json_positions:

[2019-02-15 08:51:29.354242] INFO: forward_test: get_portfolio last_pv:1000000.0, current_pv:1000000.0, json_portfolio:{'drawdown': 0.0, 'annual_return': 0.0, 'first_date': '2019-02-14', 'cum_return': 0.0, 'today_return': 0.0, 'pv': 0.0, 'max_pv': 1000000.0}
[2019-02-15 08:51:29.354978] INFO: forward_test: get_transactions transaction 0:

[2019-02-15 08:51:29.355598] INFO: forward_test: get_transactions total_buy:0.0, total_sell:0.0, json_transaction:

[2019-02-15 08:51:29.363592] INFO: forward_test: get_risk_indicators json_risk_indicator:{'beta': 0.0, 'volatility': 0.0, 'ir': 0.0, 'alpha': 0.0, 'sharpe': 0.0}
cum_return_plot: {}, before_shared_cum_return_plot: {}, after_shared_cum_return_plot: {}, benchmark_cum_return_plot: {}, hold_percent_plot: {} 1 0 0 1 1
[2019-02-15 08:51:29.515180] INFO: forward_test: forward test result, new_cash 1000000.0, extension {"order_price_field_sell": "close", "order_price_field_buy": "open", "is_stock": "True", "need_settle": "False"}

(iQuant) #2

您好,收到您的提问,已提交给策略工程师,我们会尽快为您解答。


(youke) #3

我也是一样的问题,如何解决这个呢?


(iQuant) #4

尝试向前取一定天数数据试试,可能模拟实盘前期没有满足策略要求的数据。