stock_ranker回测为什么不能到end_date?

策略分享
标签: #<Tag:0x00007fc064a6c968>

(sundicovery) #1

克隆策略
In [17]:
# LSTM与stockranker配合回测

# 基础参数配置
class conf:
    start_date = '2000-01-01'
    end_date='2017-07-28'
    # split_date 之前的数据用于训练,之后的数据用作效果评估
    split_date = '2016-01-01'
    # D.instruments: https://bigquant.com/docs/data_instruments.html
    instruments = D.instruments(start_date, end_date)

    # 机器学习目标标注函数
    # 如下标注函数等价于 min(max((持有期间的收益 * 100), -20), 20) + 20 (后面的M.fast_auto_labeler会做取整操作)
    # 说明:max/min这里将标注分数限定在区间[-20, 20],+20将分数变为非负数 (StockRanker要求标注分数非负整数)
    label_expr = ['return * 100', 'where(label > {0}, {0}, where(label < -{0}, -{0}, label)) + {0}'.format(20)]
    # 持有天数,用于计算label_expr中的return值(收益)
    hold_days = 5

    # 特征 https://bigquant.com/docs/data_features.html,你可以通过表达式构造任何特征
    features = [
        'close_5/close_0',  # 5日收益
        'close_10/close_0',  # 10日收益
        'close_20/close_0',  # 20日收益
        'avg_amount_0/avg_amount_5',  # 当日/5日平均交易额
        'avg_amount_5/avg_amount_20',  # 5日/20日平均交易额
        'rank_avg_amount_0/rank_avg_amount_5',  # 当日/5日平均交易额排名
        'rank_avg_amount_5/rank_avg_amount_10',  # 5日/10日平均交易额排名
        'rank_return_0',  # 当日收益
        'rank_return_5',  # 5日收益
        'rank_return_10',  # 10日收益
        'rank_return_0/rank_return_5',  # 当日/5日收益排名
        'rank_return_5/rank_return_10',  # 5日/10日收益排名
    ]


# 给数据做标注:给每一行数据(样本)打分,一般分数越高表示越好
m1 = M.fast_auto_labeler.v7(
    instruments=conf.instruments, start_date=conf.start_date, end_date=conf.end_date,
    label_expr=conf.label_expr, hold_days=conf.hold_days,
    benchmark='000300.SHA', sell_at='open', buy_at='open')
# 计算特征数据
m2 = M.general_feature_extractor.v5(
    instruments=conf.instruments, start_date=conf.start_date, end_date=conf.end_date,
    features=conf.features)
# 数据预处理:缺失数据处理,数据规范化,T.get_stock_ranker_default_transforms为StockRanker模型做数据预处理
m3 = M.transform.v2(
    data=m2.data, transforms=T.get_stock_ranker_default_transforms(),
    drop_null=True, astype='int32', except_columns=['date', 'instrument'],
    clip_lower=0, clip_upper=200000000)
# 合并标注和特征数据
m4 = M.join.v2(data1=m1.data, data2=m3.data, on=['date', 'instrument'], sort=True)

# 训练数据集
m5_training = M.filter.v2(data=m4.data, expr='date < "%s"' % conf.split_date)
# 评估数据集
m5_evaluation = M.filter.v2(data=m4.data, expr='"%s" <= date' % conf.split_date)
# StockRanker机器学习训练
m6 = M.stock_ranker_train.v3(training_ds=m5_training.data, features=conf.features)
# 对评估集做预测
m7 = M.stock_ranker_predict.v2(model_id=m6.model_id, data=m5_evaluation.data)


## 量化回测 https://bigquant.com/docs/strategy_backtest.html
# 回测引擎:初始化函数,只执行一次
def initialize(context):
    # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
    context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
    # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
    context.ranker_prediction = context.options['ranker_prediction'].read_df()
    # 设置买入的股票数量,这里买入预测股票列表排名靠前的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.2
    
    context.date={}

# 回测引擎:每日数据处理函数,每天执行一次
def handle_data(context, data):
    # 按日期过滤得到今日的预测数据
    ranker_prediction = context.ranker_prediction[context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
    current_dt = 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()}
    equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}
    buy_dates = {}
    for e in equities:
        if e in context.date:
            buy_dates[e] = context.date[e]
    
    # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    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]))])))
    for instrument in instruments:
        if context.trading_calendar.session_distance(pd.Timestamp(context.date[instrument]), pd.Timestamp(current_dt))>=5:
            context.order_target(context.symbol(instrument), 0)
    
    if not is_staging and cash_for_sell > 0:
        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. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    
    buy_dt = data.current_dt.strftime('%Y-%m-%d')
    context.date=buy_dt
    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)
            buy_dates[instrument] = current_dt
    
    buy_dt = data.current_dt.strftime('%Y-%m-%d')
    context.date=buy_dt
    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)
            buy_dates[instrument] = current_dt
            
    context.date = buy_dates

# 调用回测引擎
m8 = M.backtest.v6(
    instruments=m7.instruments,
    start_date=m7.start_date,
    end_date=m7.end_date,
    initialize=initialize,
    handle_data=handle_data,
    order_price_field_buy='open',       # 表示 开盘 时买入
    order_price_field_sell='open',     # 表示 收盘 前卖出
    capital_base=100000,               # 初始资金
    benchmark='000300.SHA',             # 比较基准,不影响回测结果
    # 通过 options 参数传递预测数据和参数给回测引擎
    options={'ranker_prediction': m7.predictions, 'hold_days': conf.hold_days},
    m_cached=False
)
[2017-08-04 16:29:00.779647] INFO: bigquant: fast_auto_labeler.v7 start ..
[2017-08-04 16:29:00.783289] INFO: bigquant: hit cache
[2017-08-04 16:29:00.793820] INFO: bigquant: fast_auto_labeler.v7 end [0.01417s].
[2017-08-04 16:29:00.803734] INFO: bigquant: general_feature_extractor.v5 start ..
[2017-08-04 16:29:00.806882] INFO: bigquant: hit cache
[2017-08-04 16:29:00.807786] INFO: bigquant: general_feature_extractor.v5 end [0.004065s].
[2017-08-04 16:29:00.819960] INFO: bigquant: transform.v2 start ..
[2017-08-04 16:29:00.824131] INFO: bigquant: hit cache
[2017-08-04 16:29:00.825156] INFO: bigquant: transform.v2 end [0.005229s].
[2017-08-04 16:29:00.834533] INFO: bigquant: join.v2 start ..
[2017-08-04 16:29:00.838061] INFO: bigquant: hit cache
[2017-08-04 16:29:00.839034] INFO: bigquant: join.v2 end [0.004547s].
[2017-08-04 16:29:00.847099] INFO: bigquant: filter.v2 start ..
[2017-08-04 16:29:00.852446] INFO: filter: filter with expr date < "2016-01-01"
[2017-08-04 16:29:03.106663] INFO: filter: filter /y_2005, 286073/286073
[2017-08-04 16:29:04.282994] INFO: filter: filter /y_2006, 285723/285723
[2017-08-04 16:29:07.937070] INFO: filter: filter /y_2007, 317980/317980
[2017-08-04 16:29:10.044394] INFO: filter: filter /y_2008, 357124/357124
[2017-08-04 16:29:11.710577] INFO: filter: filter /y_2009, 372749/372749
[2017-08-04 16:29:13.626488] INFO: filter: filter /y_2010, 424080/424080
[2017-08-04 16:29:16.655015] INFO: filter: filter /y_2011, 505162/505162
[2017-08-04 16:29:19.635361] INFO: filter: filter /y_2012, 561285/561285
[2017-08-04 16:29:22.926608] INFO: filter: filter /y_2013, 563104/563104
[2017-08-04 16:29:25.909883] INFO: filter: filter /y_2014, 566142/566142
[2017-08-04 16:29:28.626082] INFO: filter: filter /y_2015, 558321/558321
[2017-08-04 16:29:30.189291] INFO: filter: filter /y_2016, 0/635713
[2017-08-04 16:29:30.961343] INFO: filter: filter /y_2017, 0/383849
[2017-08-04 16:29:31.121093] INFO: bigquant: filter.v2 end [30.273979s].
[2017-08-04 16:29:31.128146] INFO: bigquant: filter.v2 start ..
[2017-08-04 16:29:31.133857] INFO: filter: filter with expr "2016-01-01" <= date
[2017-08-04 16:29:31.444667] INFO: filter: filter /y_2005, 0/286073
[2017-08-04 16:29:31.578282] INFO: filter: filter /y_2006, 0/285723
[2017-08-04 16:29:31.707427] INFO: filter: filter /y_2007, 0/317980
[2017-08-04 16:29:31.844691] INFO: filter: filter /y_2008, 0/357124
[2017-08-04 16:29:32.199067] INFO: filter: filter /y_2009, 0/372749
[2017-08-04 16:29:32.347052] INFO: filter: filter /y_2010, 0/424080
[2017-08-04 16:29:32.756590] INFO: filter: filter /y_2011, 0/505162
[2017-08-04 16:29:32.951132] INFO: filter: filter /y_2012, 0/561285
[2017-08-04 16:29:33.152859] INFO: filter: filter /y_2013, 0/563104
[2017-08-04 16:29:33.382796] INFO: filter: filter /y_2014, 0/566142
[2017-08-04 16:29:33.655569] INFO: filter: filter /y_2015, 0/558321
[2017-08-04 16:29:37.302374] INFO: filter: filter /y_2016, 635713/635713
[2017-08-04 16:29:39.683659] INFO: filter: filter /y_2017, 383849/383849
[2017-08-04 16:29:40.072737] INFO: bigquant: filter.v2 end [8.944561s].
[2017-08-04 16:29:40.082810] INFO: bigquant: stock_ranker_train.v3 start ..
[2017-08-04 16:30:04.574280] INFO: df2bin: prepare data: training ..
[2017-08-04 16:31:11.386933] INFO: stock_ranker_train: 0eea5c68 training: 4797743 rows
[2017-08-04 16:33:58.022461] INFO: bigquant: stock_ranker_train.v3 end [257.939654s].
[2017-08-04 16:33:58.029247] INFO: bigquant: stock_ranker_predict.v2 start ..
[2017-08-04 16:33:59.011790] INFO: df2bin: prepare data: prediction ..
[2017-08-04 16:34:13.726960] INFO: stock_ranker_predict: prediction: 1019562 rows
[2017-08-04 16:34:28.148036] INFO: bigquant: stock_ranker_predict.v2 end [30.118747s].
[2017-08-04 16:34:28.159719] INFO: bigquant: backtest.v6 start ..
[2017-08-04 16:35:19.396225] INFO: Performance: Simulated 377 trading days out of 377.
[2017-08-04 16:35:19.397741] INFO: Performance: first open: 2016-01-04 14:30:00+00:00
[2017-08-04 16:35:19.398938] INFO: Performance: last close: 2017-07-20 19:00:00+00:00
[注意] 有 121 笔卖出是在多天内完成的。当日卖出股票超过了当日股票交易的2.5%会出现这种情况。
  • 收益率21.53%
  • 年化收益率13.92%
  • 基准收益率0.45%
  • 阿尔法0.14
  • 贝塔1.05
  • 夏普比率0.34
  • 收益波动率28.1%
  • 信息比率0.68
  • 最大回撤30.97%
[2017-08-04 16:35:21.238406] INFO: bigquant: backtest.v6 end [53.078636s].

用stock_ranker做回测,end_date设置到2017年7月28日。回测完成之后发现收益曲线图只是到7月20日,交易详情也只是到月20日


(iQuant) #2

你好,收到你的反馈。原因已经找到了。
你的代码版本是之前的,我把你代码稍微调整一下,调整以后就能回测到end_date当天。

克隆策略
In [1]:
# 基础参数配置
class conf:
    start_date = '2000-01-01'
    end_date='2017-07-28'
    # split_date 之前的数据用于训练,之后的数据用作效果评估
    split_date = '2016-01-01'
    # D.instruments: https://bigquant.com/docs/data_instruments.html
    instruments = D.instruments(start_date, split_date)

    # 机器学习目标标注函数
    # 如下标注函数等价于 min(max((持有期间的收益 * 100), -20), 20) + 20 (后面的M.fast_auto_labeler会做取整操作)
    # 说明:max/min这里将标注分数限定在区间[-20, 20],+20将分数变为非负数 (StockRanker要求标注分数非负整数)
    label_expr = ['return * 100', 'where(label > {0}, {0}, where(label < -{0}, -{0}, label)) + {0}'.format(20)]
    # 持有天数,用于计算label_expr中的return值(收益)
    hold_days = 5

    # 特征 https://bigquant.com/docs/data_features.html,你可以通过表达式构造任何特征
    features = [
        'close_5/close_0',  # 5日收益
        'close_10/close_0',  # 10日收益
        'close_20/close_0',  # 20日收益
        'avg_amount_0/avg_amount_5',  # 当日/5日平均交易额
        'avg_amount_5/avg_amount_20',  # 5日/20日平均交易额
        'rank_avg_amount_0/rank_avg_amount_5',  # 当日/5日平均交易额排名
        'rank_avg_amount_5/rank_avg_amount_10',  # 5日/10日平均交易额排名
        'rank_return_0',  # 当日收益
        'rank_return_5',  # 5日收益
        'rank_return_10',  # 10日收益
        'rank_return_0/rank_return_5',  # 当日/5日收益排名
        'rank_return_5/rank_return_10',  # 5日/10日收益排名
    ]

# 给数据做标注:给每一行数据(样本)打分,一般分数越高表示越好
m1 = M.fast_auto_labeler.v8(
    instruments=conf.instruments, start_date=conf.start_date, end_date=conf.split_date,
    label_expr=conf.label_expr, hold_days=conf.hold_days,
    benchmark='000300.SHA', sell_at='open', buy_at='open')
# 计算特征数据
m2 = M.general_feature_extractor.v5(
    instruments=conf.instruments, start_date=conf.start_date, end_date=conf.split_date,
    features=conf.features)
# 数据预处理:缺失数据处理,数据规范化,T.get_stock_ranker_default_transforms为StockRanker模型做数据预处理
m3 = M.transform.v2(
    data=m2.data, transforms=T.get_stock_ranker_default_transforms(),
    drop_null=True, astype='int32', except_columns=['date', 'instrument'],
    clip_lower=0, clip_upper=200000000)
# 合并标注和特征数据
m4 = M.join.v2(data1=m1.data, data2=m3.data, on=['date', 'instrument'], sort=True)
# StockRanker机器学习训练
m5 = M.stock_ranker_train.v3(training_ds=m4.data, features=conf.features)


## 量化回测 https://bigquant.com/docs/module_trade.html
# 回测引擎:准备数据,只执行一次
def prepare(context):
    # context.start_date / end_date,回测的时候,为trader传入参数;在实盘运行的时候,由系统替换为实盘日期
    n1 = M.general_feature_extractor.v5(
        instruments=D.instruments(),
        start_date=context.start_date, end_date=context.end_date,
        model_id=context.options['model_id'])
    n2 = M.transform.v2(
        data=n1.data, transforms=T.get_stock_ranker_default_transforms(),
        drop_null=True, astype='int32', except_columns=['date', 'instrument'],
        clip_lower=0, clip_upper=200000000)
    n3 = M.stock_ranker_predict.v2(model_id=context.options['model_id'], data=n2.data)
    context.instruments = n3.instruments
    context.options['predictions'] = n3.predictions

# 回测引擎:初始化函数,只执行一次
def initialize(context):
    # 加载预测数据
    context.ranker_prediction = context.options['predictions'].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.2

# 回测引擎:每日数据处理函数,每天执行一次
def handle_data(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天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    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. 生成买入订单:按StockRanker预测的排序,买入前面的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)


# 调用交易引擎
m6 = M.trade.v2(
    instruments=None,
    start_date=conf.split_date,
    end_date=conf.end_date,
    prepare=prepare,
    initialize=initialize,
    handle_data=handle_data,
    order_price_field_buy='open',       # 表示 开盘 时买入
    order_price_field_sell='close',     # 表示 收盘 前卖出
    capital_base=1000000,               # 初始资金
    benchmark='000300.SHA',             # 比较基准,不影响回测结果
    # 通过 options 参数传递预测数据和参数给回测引擎
    options={'hold_days': conf.hold_days, 'model_id': m5.model_id}
)
[2017-08-04 17:37:55.297591] INFO: bigquant: fast_auto_labeler.v8 start ..
[2017-08-04 17:38:25.665315] INFO: fast_auto_labeler: load history data: 4873915 rows
[2017-08-04 17:38:29.681511] INFO: fast_auto_labeler: start labeling
[2017-08-04 17:40:20.158784] INFO: bigquant: fast_auto_labeler.v8 end [144.861198s].
[2017-08-04 17:40:20.202593] INFO: bigquant: general_feature_extractor.v5 start ..
[2017-08-04 17:40:20.225321] INFO: general_feature_extractor: year 2000, featurerows=0
[2017-08-04 17:40:20.238969] INFO: general_feature_extractor: year 2001, featurerows=0
[2017-08-04 17:40:20.246693] INFO: general_feature_extractor: year 2002, featurerows=0
[2017-08-04 17:40:20.254823] INFO: general_feature_extractor: year 2003, featurerows=0
[2017-08-04 17:40:20.263182] INFO: general_feature_extractor: year 2004, featurerows=0
[2017-08-04 17:40:31.112570] INFO: general_feature_extractor: year 2005, featurerows=314357
[2017-08-04 17:40:40.726572] INFO: general_feature_extractor: year 2006, featurerows=288040
[2017-08-04 17:40:51.325486] INFO: general_feature_extractor: year 2007, featurerows=323371
[2017-08-04 17:41:02.346851] INFO: general_feature_extractor: year 2008, featurerows=360328
[2017-08-04 17:41:17.907797] INFO: general_feature_extractor: year 2009, featurerows=375308
[2017-08-04 17:41:35.139714] INFO: general_feature_extractor: year 2010, featurerows=431567
[2017-08-04 17:41:57.579261] INFO: general_feature_extractor: year 2011, featurerows=511455
[2017-08-04 17:42:19.792506] INFO: general_feature_extractor: year 2012, featurerows=565675
[2017-08-04 17:42:37.774544] INFO: general_feature_extractor: year 2013, featurerows=564168
[2017-08-04 17:42:55.743062] INFO: general_feature_extractor: year 2014, featurerows=569948
[2017-08-04 17:43:08.638082] INFO: general_feature_extractor: year 2015, featurerows=569698
[2017-08-04 17:43:18.111250] INFO: general_feature_extractor: year 2016, featurerows=0
[2017-08-04 17:43:18.296911] INFO: general_feature_extractor: total feature rows: 4873915
[2017-08-04 17:43:18.298657] INFO: bigquant: general_feature_extractor.v5 end [178.09614s].
[2017-08-04 17:43:18.312445] INFO: bigquant: transform.v2 start ..
[2017-08-04 17:43:20.744740] INFO: transform: transformed /y_2005, 287065/314357
[2017-08-04 17:43:22.683423] INFO: transform: transformed /y_2006, 286898/288040
[2017-08-04 17:43:24.911206] INFO: transform: transformed /y_2007, 320851/323371
[2017-08-04 17:43:27.368466] INFO: transform: transformed /y_2008, 358611/360328
[2017-08-04 17:43:29.854790] INFO: transform: transformed /y_2009, 373596/375308
[2017-08-04 17:43:32.200555] INFO: transform: transformed /y_2010, 424613/431567
[2017-08-04 17:43:34.990375] INFO: transform: transformed /y_2011, 505694/511455
[2017-08-04 17:43:38.187706] INFO: transform: transformed /y_2012, 562381/565675
[2017-08-04 17:43:41.020638] INFO: transform: transformed /y_2013, 564139/564168
[2017-08-04 17:43:44.179169] INFO: transform: transformed /y_2014, 567630/569948
[2017-08-04 17:43:47.151790] INFO: transform: transformed /y_2015, 565355/569698
[2017-08-04 17:43:47.344723] INFO: transform: transformed rows: 4816833/4873915
[2017-08-04 17:43:47.373960] INFO: bigquant: transform.v2 end [29.061503s].
[2017-08-04 17:43:47.385317] INFO: bigquant: join.v2 start ..
[2017-08-04 17:44:28.640083] INFO: join: /y_2005, rows=286073/287065, timetaken=28.533031s
[2017-08-04 17:45:25.724723] INFO: join: /y_2006, rows=285723/286898, timetaken=57.070399s
[2017-08-04 17:46:19.123398] INFO: join: /y_2007, rows=317980/320851, timetaken=53.378125s
[2017-08-04 17:47:15.246232] INFO: join: /y_2008, rows=357124/358611, timetaken=56.100408s
[2017-08-04 17:47:49.266259] INFO: join: /y_2009, rows=372749/373596, timetaken=33.99321s
[2017-08-04 17:48:07.694517] INFO: join: /y_2010, rows=424080/424613, timetaken=18.405644s
[2017-08-04 17:48:37.749450] INFO: join: /y_2011, rows=505162/505694, timetaken=30.012278s
[2017-08-04 17:49:35.782555] INFO: join: /y_2012, rows=561285/562381, timetaken=57.99104s
[2017-08-04 17:50:15.487137] INFO: join: /y_2013, rows=563104/564139, timetaken=39.654692s
[2017-08-04 17:51:18.084400] INFO: join: /y_2014, rows=566132/567630, timetaken=62.545202s
[2017-08-04 17:52:20.130443] INFO: join: /y_2015, rows=541890/565355, timetaken=61.998002s
[2017-08-04 17:52:20.461321] INFO: join: total result rows: 4781302
[2017-08-04 17:52:20.463347] INFO: bigquant: join.v2 end [513.07803s].
[2017-08-04 17:52:20.474559] INFO: bigquant: stock_ranker_train.v3 start ..
[2017-08-04 17:52:56.215565] INFO: df2bin: prepare data: training ..
[2017-08-04 17:54:44.851282] INFO: stock_ranker_train: 9b8a276a training: 4781302 rows
[2017-08-04 17:57:16.435561] INFO: bigquant: stock_ranker_train.v3 end [295.960971s].
[2017-08-04 17:57:16.485159] INFO: bigquant: backtest.v7 start ..
[2017-08-04 17:57:16.593280] INFO: bigquant: general_feature_extractor.v5 start ..
[2017-08-04 17:57:24.677507] INFO: general_feature_extractor: year 2016, featurerows=641546
[2017-08-04 17:57:29.150289] INFO: general_feature_extractor: year 2017, featurerows=409680
[2017-08-04 17:57:29.278634] INFO: general_feature_extractor: total feature rows: 1051226
[2017-08-04 17:57:29.285212] INFO: bigquant: general_feature_extractor.v5 end [12.691932s].
[2017-08-04 17:57:29.302902] INFO: bigquant: transform.v2 start ..
[2017-08-04 17:57:32.221377] INFO: transform: transformed /y_2016, 637125/641546
[2017-08-04 17:57:34.553280] INFO: transform: transformed /y_2017, 404027/409680
[2017-08-04 17:57:34.688432] INFO: transform: transformed rows: 1041152/1051226
[2017-08-04 17:57:34.702961] INFO: bigquant: transform.v2 end [5.400031s].
[2017-08-04 17:57:34.713977] INFO: bigquant: stock_ranker_predict.v2 start ..
[2017-08-04 17:57:35.896885] INFO: df2bin: prepare data: prediction ..
[2017-08-04 17:57:51.433273] INFO: stock_ranker_predict: prediction: 1041152 rows
[2017-08-04 17:58:00.159173] INFO: bigquant: stock_ranker_predict.v2 end [25.445147s].
[2017-08-04 17:58:35.715748] INFO: Performance: Simulated 383 trading days out of 383.
[2017-08-04 17:58:35.716921] INFO: Performance: first open: 2016-01-04 14:30:00+00:00
[2017-08-04 17:58:35.717741] INFO: Performance: last close: 2017-07-28 19:00:00+00:00
  • 收益率42.16%
  • 年化收益率26.04%
  • 基准收益率-0.24%
  • 阿尔法0.27
  • 贝塔1.16
  • 夏普比率0.68
  • 收益波动率31.63%
  • 信息比率1.12
  • 最大回撤21.94%
[2017-08-04 17:58:38.316870] INFO: bigquant: backtest.v7 end [81.831673s].

(sundicovery) #3

谢谢,还有一个问题,为啥回测模型的train和predict会分版本而且版本号还是分开的?难到不是一个模型训练好了就可以拿来预测么?还有回测,可以在后台自动切换到新版本吗,难道同一个交易不同版本的回测结果会不一样?


(iQuant) #4

train和predict是不同的模块,因此版本号可能不一样,不过谢谢你的建议。
如果你使用策略研究平台的 策略自动生成器 生成AI策略,那么代码会是最新版本的。
不同版本的模块在具体细节处理上可能会有一些细微差异,因此结果有可能不一样。


(神龙斗士) #5

为了支持模块更新(比如增加新功能或者修改接口),但同时又不break任何已有策略,我们借鉴了成熟的软件管理方法,通过版本来对模块做管理。这样模块也可以持续更新,同时用户可放心的使用模块,而不用担心策略哪天就不能运行了。