实际运行错误 (补充)

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

(993210oo) #1

就是这个,


(iQuant) #2

您好 您这样发链接我们无法看到的 请在发帖子的时候
image

麻烦修改一下帖子


(993210oo) #3

回测引擎:每日数据处理函数,每天执行一次

def m19_handle_data_bigquant_run(context, data):

回测引擎:每日数据处理函数,每天执行一次

# 相隔几天(hold_days)进行一下换仓
if context.trading_day_index % context.options['hold_days'] != 0:
    return    
# 按日期过滤得到今日的预测数据
ranker_prediction = context.ranker_prediction[
    context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
positions=[equity.symbol for equity in context.portfolio.positions ]
# 权重
buy_cash_weights =  context.stock_weights
# 今日买入股票列表
stock_to_buy = list(ranker_prediction.instrument[:len(buy_cash_weights)])
# 持仓上限
max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument

# 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]
# 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有
no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]
# 需要卖出的股票
stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]

# 卖出
for stock in stock_to_sell:
    # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态,如果返回真值,则可以正常下单,否则会出错
    # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式
    if data.can_trade(context.symbol(stock)):
        # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,可参考回测文档
        context.order_target_percent(context.symbol(stock), 0)

# 如果当天没有买入的股票,就返回
if len(stock_to_buy) == 0:
    return

positions = {e.symbol: p.amount * p.last_sale_price
             for e, p in context.perf_tracker.position_tracker.positions.items()}
# 买入
for i, instrument in enumerate(stock_to_buy):
    cash = context.portfolio.portfolio_value * 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:
        price = data.current(context.symbol(instrument), 'price')  # 最新价格
        stock_num = np.floor(cash/price/100)*100  # 向下取整
        context.order(context.symbol(instrument), stock_num) # 整百下单

回测引擎:准备数据,只执行一次

def m19_prepare_bigquant_run(context):
pass

回测引擎:初始化函数,只执行一次

def m19_initialize_bigquant_run(context):
# 加载预测数据
context.ranker_prediction = context.options[‘data’].read_df()
# 如果下一个订单,导致当前持股为负,则策略会抛出一个异常,通过这个设置防止重复卖出形成空单
set_long_only()
# 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
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
context.options[‘hold_days’] = 66

g = T.Graph({

'm1': 'M.instruments.v2',
'm1.start_date': '2007-01-01',
'm1.end_date': '2010-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, -22) / 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': """# #号开始的表示注释

多个特征,每行一个,可以包含基础特征和衍生特征

swing_volatility_5_0
fs_operating_revenue_0 / (fs_total_liability_0 + fs_total_equity_0)
list_board_0
pe_lyr_0/group_mean(industry_sw_level1_0, pe_lyr_0)
pe_ttm_0/group_mean(industry_sw_level1_0, pe_ttm_0)
market_cap_0
pe_ttm_0 > 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': 90,

'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',

'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,

'm13': 'M.dropnan.v1',
'm13.input_data': T.Graph.OutputPort('m7.data'),

'm6': 'M.stock_ranker_train.v5',
'm6.training_ds': T.Graph.OutputPort('m13.data'),
'm6.features': T.Graph.OutputPort('m3.data'),
'm6.learning_algorithm': '排序',
'm6.number_of_leaves': 30,
'm6.minimum_docs_per_leaf': 1000,
'm6.number_of_trees': 20,
'm6.learning_rate': 0.1,
'm6.max_bins': 1023,
'm6.feature_fraction': 1,
'm6.m_lazy_run': False,

'm9': 'M.instruments.v2',
'm9.start_date': T.live_run_param('trading_date', '2005-01-01'),
'm9.end_date': T.live_run_param('trading_date', '2005-01-01'),
'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': 90,

'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',

'm14': 'M.dropnan.v1',
'm14.input_data': T.Graph.OutputPort('m18.data'),

'm8': 'M.stock_ranker_predict.v5',
'm8.model': T.Graph.OutputPort('m6.model'),
'm8.data': T.Graph.OutputPort('m14.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': '',
'm19.end_date': '',
'm19.handle_data': m19_handle_data_bigquant_run,
'm19.prepare': m19_prepare_bigquant_run,
'm19.initialize': m19_initialize_bigquant_run,
'm19.volume_limit': 0.025,
'm19.order_price_field_buy': 'open',
'm19.order_price_field_sell': 'close',
'm19.capital_base': 30000,
'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,

})

g.run({})

def m20_run_bigquant_run(
bq_graph,
inputs,
trading_days_market=‘CN’, # 使用那个市场的交易日历
train_instruments_mid=‘m1’, # 训练数据 证券代码列表 模块id
test_instruments_mid=‘m9’, # 测试数据 证券代码列表 模块id
predict_mid=‘m8’, # 预测 模块id
trade_mid=‘m19’, # 回测 模块id
start_date=‘2005-01-01’, # 数据开始日期
end_date=T.live_run_param(‘trading_date’, ‘2018-11-22’), # 数据结束日期
train_update_days=255, # 更新周期,按交易日计算,每多少天更新一次
train_update_days_for_live=None, #模拟实盘模式下的更新周期,按交易日计算,每多少天更新一次。如果需要在模拟实盘阶段使用不同的模型更新周期,可以设置这个参数
train_data_min_days=255, # 最小数据天数,按交易日计算,所以第一个滚动的结束日期是 从开始日期到开始日期+最小数据天数
train_data_max_days=255, # 最大数据天数,按交易日计算,0,表示没有限制,否则每一个滚动的开始日期=max(此滚动的结束日期-最大数据天数, 开始日期
rolling_count_for_live=1, #实盘模式下滚动次数,模拟实盘模式下,取最后多少次滚动。一般在模拟实盘模式下,只用到最后一次滚动训练的模型,这里可以设置为1;如果你的滚动训练数据时间段很短,以至于期间可能没有训练数据,这里可以设置大一点。0表示没有限制
):
def merge_datasources(input_1):
df_list = [ds.read_df() 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:
            train_start_date = max(train_end_date - train_data_max_days, 0)
        else:
            train_start_date = start_date
        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 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}

m20 = M.hyper_rolling_train.v1(
bq_graph=g,
run=m20_run_bigquant_run,
run_now=True
)


(993210oo) #4

实际运行报错情况:

[2018-12-13 20:03:24.776327] INFO: bigquant: input_features.v1 开始运行..
[2018-12-13 20:03:25.065829] INFO: bigquant: 命中缓存
[2018-12-13 20:03:25.066964] INFO: bigquant: input_features.v1 运行完成[0.290692s].
[2018-12-13 20:03:25.070691] INFO: bigquant: instruments.v2 开始运行..
[2018-12-13 20:03:25.267939] INFO: bigquant: 命中缓存
[2018-12-13 20:03:25.268967] INFO: bigquant: instruments.v2 运行完成[0.198271s].
[2018-12-13 20:03:25.270665] INFO: bigquant: instruments.v2 开始运行..
[2018-12-13 20:03:25.466384] INFO: bigquant: 命中缓存
[2018-12-13 20:03:25.467666] INFO: bigquant: instruments.v2 运行完成[0.196991s].
[2018-12-13 20:03:25.472565] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
[2018-12-13 20:03:25.668248] INFO: bigquant: 命中缓存
[2018-12-13 20:03:25.669524] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.196934s].
[2018-12-13 20:03:25.769517] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2018-12-13 20:03:25.971432] INFO: bigquant: 命中缓存
[2018-12-13 20:03:25.972333] INFO: bigquant: general_feature_extractor.v7 运行完成[0.202835s].
[2018-12-13 20:03:26.066151] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2018-12-13 20:03:26.325225] INFO: bigquant: 命中缓存
[2018-12-13 20:03:26.326210] INFO: bigquant: general_feature_extractor.v7 运行完成[0.260075s].
[2018-12-13 20:03:26.330538] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2018-12-13 20:03:26.490130] INFO: bigquant: 命中缓存
[2018-12-13 20:03:26.491076] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.16053s].
[2018-12-13 20:03:26.493033] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2018-12-13 20:03:26.785000] INFO: bigquant: 命中缓存
[2018-12-13 20:03:26.786149] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.293105s].
[2018-12-13 20:03:26.790067] INFO: bigquant: join.v3 开始运行..
[2018-12-13 20:03:26.960940] INFO: bigquant: 命中缓存
[2018-12-13 20:03:26.961943] INFO: bigquant: join.v3 运行完成[0.17187s].
[2018-12-13 20:03:26.965204] INFO: bigquant: dropnan.v1 开始运行..
[2018-12-13 20:03:27.162217] INFO: bigquant: 命中缓存
[2018-12-13 20:03:27.163384] INFO: bigquant: dropnan.v1 运行完成[0.198171s].
[2018-12-13 20:03:27.165180] INFO: bigquant: dropnan.v1 开始运行..
[2018-12-13 20:03:27.259449] INFO: bigquant: 命中缓存
[2018-12-13 20:03:27.260297] INFO: bigquant: dropnan.v1 运行完成[0.095127s].
[2018-12-13 20:03:27.265993] INFO: bigquant: stock_ranker_train.v5 开始运行..
[2018-12-13 20:03:27.566831] INFO: bigquant: 命中缓存
[2018-12-13 20:03:27.568263] INFO: bigquant: stock_ranker_train.v5 运行完成[0.30225s].
[2018-12-13 20:03:27.572643] INFO: bigquant: stock_ranker_predict.v5 开始运行..
[2018-12-13 20:03:27.972731] INFO: bigquant: 命中缓存
[2018-12-13 20:03:27.974897] INFO: bigquant: stock_ranker_predict.v5 运行完成[0.402235s].
[2018-12-13 20:03:27.980442] INFO: bigquant: cached.v3 开始运行..
[2018-12-13 20:03:28.391414] INFO: bigquant: 命中缓存
[2018-12-13 20:03:28.392463] INFO: bigquant: cached.v3 运行完成[0.412015s].
[2018-12-13 20:03:28.657624] INFO: forward_register: start to register
[2018-12-13 20:03:28.721984] INFO: forward_register: update coz content changed
[2018-12-13 20:03:28.722885] INFO: forward_register: done of register
[2018-12-13 20:03:29.364282] INFO: forward_test: init username:993210oo, algo_id:10131, first_date:2018-12-11, frequency:daily, price_type:real, instruments:3538
[2018-12-13 20:03:29.365516] INFO: forward_test: biglearning forward test:V5.1.6
[2018-12-13 20:03:29.390705] INFO: forward_test: run_date: 2018-12-13, notebook_id:993210oo_a5b59136-fd27-11e8-b5d4-0a580a8100bf, algo_name:三月轮动BD,JZ及SZ-Copy1
[2018-12-13 20:03:29.397627] INFO: forward_test: last record: None
[2018-12-13 20:03:29.401320] INFO: forward_test: today record: None
[2018-12-13 20:03:29.404294] INFO: forward_test: first record: None
[2018-12-13 20:03:29.513905] INFO: algo: init() show_debug_info:True, papertrading:True
[2018-12-13 20:03:29.514784] INFO: algo: init() daily start:2018-12-13 00:00:00+00:00 ~ end:2018-12-13 00:00:00+00:00
[2018-12-13 20:03:29.515434] INFO: factory: create simulation parameters [start:2018-12-13 00:00:00+00:00, end:2018-12-13 00:00:00+00:00]
[2018-12-13 20:03:29.516023] INFO: Trading: SimulationParameters start_session:2018-12-13 00:00:00+00:00, end_session:2018-12-13 00:00:00+00:00, emission_rate:daily, arena:backtest
[2018-12-13 20:03:29.516826] INFO: Trading: SimulationParameters _first_open:2018-12-13 09:30:00+00:00, _last_close:2018-12-13 15:00:00+00:00
[2018-12-13 20:03:29.520801] INFO: forward_test: instruments type <class 'list'>, <class 'list'>, <class 'list'>
<class 'pandas.core.panel.Panel'>
Dimensions: 3538 (items) x 244 (major_axis) x 9 (minor_axis)
Items axis: 000001.SZA to 603999.SHA
Major_axis axis: 2017-12-14 00:00:00 to 2018-12-13 00:00:00
Minor_axis axis: open to delist_date
[2018-12-13 20:03:41.174490] INFO: algo: TradingAlgorithm V1.3.7
[2018-12-13 20:03:41.189169] INFO: algo: data.major_axis0: 2017-12-14 00:00:00+00:00
[2018-12-13 20:03:41.190215] INFO: algo: data.major_axis-1: 2018-12-13 00:00:00+00:00
[2018-12-13 20:03:49.819546] ERROR: forward_test: run hit Exception, e unsupported operand type(s) for +: 'NoneType' and 'float'
Traceback (most recent call last):
  File "/var/app/enabled/biglearning/module2/modules/forward_test/v5/__init__.py", line 426, in run
    algo_result = algo.run(ohlc_data, overwrite_sim_params=False)
  File "/var/app/enabled/bigline/zipline/algorithm.py", line 847, in run
    for perf in self.get_generator():
  File "/var/app/enabled/bigline/zipline/algorithm.py", line 711, in get_generator
    return self._create_generator(self.sim_params)
  File "/var/app/enabled/bigline/zipline/algorithm.py", line 663, in _create_generator
    algo=self
  File "/var/app/enabled/bigline/zipline/finance/performance/tracker.py", line 209, in __init__
    self.cumulative_performance.position_tracker = self.position_tracker
  File "/var/app/enabled/bigline/zipline/finance/performance/period.py", line 214, in position_tracker
    self.calculate_performance()
  File "/var/app/enabled/bigline/zipline/finance/performance/period.py", line 352, in calculate_performance
    self._total_intraperiod_capital_change + payout
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-32b5286ff3ee> in <module>()
    293     bq_graph=g,
    294     run=m20_run_bigquant_run,
--> 295     run_now=True
    296 )

/var/app/enabled/biglearning/module2/common/modulemanagerv2.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.modulemanagerv2.BigQuantModuleVersion.__call__()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker.module_invoke()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._module_run()

/var/app/enabled/biglearning/module2/modules/hyper_rolling_train/v1/__init__.py in bigquant_run(bq_graph_port, input_1, input_2, input_3, run, run_now, bq_graph)
    126 
    127     if run_now:
--> 128         result = run(bq_graph, inputs)
    129     else:
    130         result = T.GraphContinue(bq_graph, partial(run, inputs=inputs))

<ipython-input-1-32b5286ff3ee> in m20_run_bigquant_run(bq_graph, inputs, trading_days_market, train_instruments_mid, test_instruments_mid, predict_mid, trade_mid, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live)
    285     parameters[trade_mid + '.options_data'] = mx.data
    286 
--> 287     trade = g.run(parameters)
    288 
    289     return {'rollings': results, 'trade': trade}

/var/app/enabled/biglearning/graphimpl/graph.py in run(self, parameters, execution_class)
    164             execution_class = GraphBase.DefaultGraphExecution
    165 
--> 166         return execution_class(copy.deepcopy(self.__data), copy.deepcopy(parameters)).run()
    167 
    168 

/var/app/enabled/biglearning/graphimpl/graph.py in run(self)
    135     def run(self):
    136         self.build_graph()
--> 137         self._exec_graph()
    138 
    139         results = {}

/var/app/enabled/biglearning/graphimpl/graph.py in _exec_graph(self)
    126         while i < len(queue):
    127             # TODO: parallel execute
--> 128             self.exec_module(queue[i])
    129             for depender in self.__graph[queue[i]][GraphExecution.KEY_DEPENDERS]:
    130                 self.__graph[depender][GraphExecution.KEY_DEPENDEES].remove(queue[i])

/var/app/enabled/biglearning/graphimpl/graph.py in exec_module(self, module)
    114             module_args[k] = v
    115 
--> 116         outputs = self.run_module(module_type, module_args)
    117         args[GraphExecution.KEY_OUTPUTS] = outputs
    118         globals()[module] = outputs

/var/app/enabled/biglearning/graphimpl/graph.py in run_module(self, module_type, args)
    100     def run_module(self, module_type, args):
    101         from biglearning.module2.common.modulemanagerv2 import M
--> 102         return M[module_type](**args)
    103 
    104     def exec_module(self, module):

/var/app/enabled/biglearning/module2/common/modulemanagerv2.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.modulemanagerv2.BigQuantModuleVersion.__call__()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker.module_invoke()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._module_run()

/var/app/enabled/biglearning/module2/modules/trade/v4/__init__.py in bigquant_run(start_date, end_date, handle_data, instruments, prepare, initialize, before_trading_start, volume_limit, order_price_field_buy, order_price_field_sell, capital_base, auto_cancel_non_tradable_orders, data_frequency, price_type, product_type, plot_charts, backtest_only, options_data, options, history_ds, benchmark, trading_calendar, amount_integer, m_meta_kwargs)
    227         env = get_user_env()
    228         if env.is_paper_trading() or env.is_live_trading():
--> 229             return do_live_run(env)
    230 
    231     from biglearning.api import M

/var/app/enabled/biglearning/module2/modules/trade/v4/__init__.py in do_live_run(env)
    221                 treasury_data=None,
    222                 trading_calendar=None,
--> 223                 **m_meta_kwargs)
    224         return lm_3
    225 

/var/app/enabled/biglearning/module2/common/modulemanagerv2.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.modulemanagerv2.BigQuantModuleVersion.__call__()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker.module_invoke()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._invoke_with_cache()

/var/app/enabled/biglearning/module2/common/moduleinvoker.cpython-35m-x86_64-linux-gnu.so in biglearning.module2.common.moduleinvoker._module_run()

/var/app/enabled/biglearning/module2/modules/forward_test/v5/__init__.py in run(self)
    754         except Exception as e:
    755             log.exception("run hit Exception, e {}".format(e))
--> 756             raise e
    757 
    758     def _render_template(self, template, data):

/var/app/enabled/biglearning/module2/modules/forward_test/v5/__init__.py in run(self)
    424 
    425                 # run zipline TradingAlgorithm
--> 426                 algo_result = algo.run(ohlc_data, overwrite_sim_params=False)
    427                 algo_result.sort_index(inplace=True)
    428                 result_last_row = algo_result.tail(1)

/var/app/enabled/bigline/zipline/algorithm.py in run(self, data, overwrite_sim_params)
    845         try:
    846             perfs = []
--> 847             for perf in self.get_generator():
    848                 perfs.append(perf)
    849 

/var/app/enabled/bigline/zipline/algorithm.py in get_generator(self)
    709         method to get a standard construction generator.
    710         """
--> 711         return self._create_generator(self.sim_params)
    712 
    713     def run(self, data=None, overwrite_sim_params=True):

/var/app/enabled/bigline/zipline/algorithm.py in _create_generator(self, sim_params)
    661                 trading_calendar=self.trading_calendar,
    662                 env=self.trading_environment,
--> 663                 algo=self
    664             )
    665             self.blotter.set_position_tracker(self.perf_tracker.position_tracker)

/var/app/enabled/bigline/zipline/finance/performance/tracker.py in __init__(self, sim_params, trading_calendar, env, algo)
    207             name="Cumulative"
    208         )
--> 209         self.cumulative_performance.position_tracker = self.position_tracker
    210 
    211         # this performance period will span just the current market day

/var/app/enabled/bigline/zipline/finance/performance/period.py in position_tracker(self, obj)
    212         self._position_tracker = obj
    213         # we only calculate perf once we inject PositionTracker
--> 214         self.calculate_performance()
    215 
    216     def adjust_period_starting_capital(self, capital_change):

/var/app/enabled/bigline/zipline/finance/performance/period.py in calculate_performance(self)
    350 
    351         self.ending_cash = self.starting_cash + self.cash_flow + \
--> 352             self._total_intraperiod_capital_change + payout
    353         #print("#calculate_performance ending_cash:{0},starting_cash:{1},cash_flow:{2},total_intracapital_change:{3},payout:{4}"
    354         #    .format(self.ending_cash, self.starting_cash, self.cash_flow, self._total_intraperiod_capital_change, payout))

TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

(iQuant) #5

您这个是模拟实盘报错还是回测的时候报错?


(993210oo) #6

模拟不报错,实际运行报错,貌似另外一个策略也是实际运行报错,模拟不报错。


(993210oo) #7

如何,能查到什么原因不?


(iQuant) #8

回测没问题,可以提供一下你的模拟交易的notebook_id么 就是你打开我的交易然后点击那个策略,网址最后有个notebook_id=XXXXXXXXX


(993210oo) #9

notebook_id=a5b59136-fd27-11e8-b5d4-0a580a8100bf