请问,回测中资金状态是如何更新的?context.portfolio中的那几个属性都是如何在每日更新的?算了半天,数值对不上。

用户成长系列
新手专区
标签: #<Tag:0x00007f4921e95770> #<Tag:0x00007f4921e95630>

(BOLO) #1

请问,context.portfolio中的那几个属性都是如何在每日更新的?
算了半天,每天的portfolio都对不上。
‘capital_used’, ‘cash’, ‘pnl’ 这几个数值是如何更新的?他们和买卖股票金额以及买/卖手续费 之间的关系是什么?
我相信平台不会有问题,但是真的是看不出来关系,否则这么跑下去真的不知道对不对。

我是从社区里面直接copy下来的整百操作模板。
谢谢!

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-106:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"DestinationInputPortId":"-106:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-113:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-126:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-140:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-147:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-159:options_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-140:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-159:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-126:training_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-113:input_data","SourceOutputPortId":"-106:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-113:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"-126:model"},{"DestinationInputPortId":"-147:input_data","SourceOutputPortId":"-140:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-147:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2011-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2012-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\n \n(close_0 + close_1 + close_2 + close_3 + close_4) / 5 / close_0\nmax(high_0, high_1, high_2) / min(low_0, low_1, low_2)\nmean(close_0,20)/std(close_0,20)\ndelta(open_0/shift(close_0,1), 10)\n \n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","ModuleId":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","ModuleParameters":[{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"OutputPortsInternal":[{"Name":"predictions","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null},{"Name":"m_lazy_run","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-05-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2016-08-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"600030.SHA\n601688.SHA\n000063.SZA\n600498.SHA\n300308.SZA\n002281.SZA\n002792.SZA\n002194.SZA\n600487.SHA\n300383.SZA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-86","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-106","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-106"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-106"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-106","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-113","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-113"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-113"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-113","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-126","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":1000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":20,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"learning_rate","Value":0.1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_bins","Value":1023,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_row_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ndcg_discount_base","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-126"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-126"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-126"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-126"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-126","OutputType":null},{"Name":"feature_gains","NodeId":"-126","OutputType":null},{"Name":"m_lazy_run","NodeId":"-126","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-140","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-140"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-140"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-140","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-147","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-147"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-147"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-147","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":19,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-159","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 2\n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.2\n context.options['hold_days'] = 5\n\n help(context.has_unfinished_sell_order)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n print(\"--------------------------------------------------------------------------------\")\n print(\"------------------ranker_prediction is-----------------------------------------\")\n print(ranker_prediction)\n \n\n # 1. 资金分配\n print(\"1. 资金分配\")\n \n # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金\n # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)\n is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)\n print(\"----------context.trading_day_index is-----------------------------------------\")\n print(context.trading_day_index)\n #每天进行滚动,从0开始的\n \n print(\"*******context.portfolio is*******\")\n print(context.portfolio)\n \n \n cash_avg = context.portfolio.portfolio_value / context.options['hold_days']\n print(\"-------------------------------cash_avg is-------------------------------------\")\n print(cash_avg)\n \n cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)\n print(\"*******context.portfolio.cash is*******\")\n print(context.portfolio.cash)\n \n print(\"*******cash_for_buy is*******\")\n print(cash_for_buy)\n \n \n cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n print(\"*******cash_for_sell is*******\")\n print(cash_for_sell)\n \n \n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n print(\"*******positions is*******\")\n print(positions)\n \n\n\n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰\n print(\"2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰\")\n if not is_staging and cash_for_sell > 0:\n equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}\n print(\"****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***\")\n print(\"*******equities is*******\")\n print(equities)\n \n instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))\n print(\"****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]))])))***\")\n print(\"*******instruments is*******\")\n print(instruments)\n \n \n # print('rank order for sell %s' % instruments)\n print(\"***rank order for sell %s' % instruments***\")\n for instrument in instruments:\n print(\"*******for instrument in instruments:*******\")\n print(\"*******instrument is*******\")\n print(instrument)\n \n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n print(\"***cash_for_sell -= positions[instrument]***\")\n print(\"*******cash_for_sell is*******\")\n print(cash_for_sell)\n \n if cash_for_sell <= 0:\n break\n \n \n \n \n\n # 3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票\n print(\"3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票\")\n buy_cash_weights = context.stock_weights\n #即将购买股票权重\n print(\"*******context.stock_weights is*******\")\n print(context.stock_weights)\n \n buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n #购买股票的代码,eg:['002194.SZA', '000063.SZA']\n print(\"*******buy_instruments is*******\")\n print(buy_instruments)\n \n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n print(\"***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***\")\n print(\"*******context.portfolio.portfolio_value is*******\")\n print(context.portfolio.portfolio_value)\n print(\"*******context.max_cash_per_instrument is*******\")\n print(context.max_cash_per_instrument)\n print(\"******* max_cash_per_instrument is*******\")\n print( max_cash_per_instrument)\n \n for i, instrument in enumerate(buy_instruments):\n cash = cash_for_buy * buy_cash_weights[i]\n print(\"******* Number of stock to buy is*******\")\n print(i)\n print(\"***cash = cash_for_buy * buy_cash_weights[i]***\")\n print(cash)\n \n print(\"******判断是否跳入补仓金额判断******\")\n print(\"******if cash > max_cash_per_instrument - positions.get(instrument, 0):******\")\n print(\"******positions.get(instrument, 0)******\")\n print(positions.get(instrument, 0))\n print(\"******max_cash_per_instrument - positions.get(instrument, 0)******\")\n print(max_cash_per_instrument - positions.get(instrument, 0))\n print(\"******cash > max_cash_per_instrument - positions.get(instrument, 0)******\")\n print(cash > max_cash_per_instrument - positions.get(instrument, 0))\n \n \n if cash > max_cash_per_instrument - positions.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n cash = max_cash_per_instrument - positions.get(instrument, 0)\n print(\"***cash > max_cash_per_instrument - positions.get(instrument, 0):***\")\n print(\"******* positions.get(instrument, 0) is*******\")\n print(positions.get(instrument, 0))\n print(\"******* cash is*******\")\n print(cash)\n \n if cash > 0:\n current_price = data.current(context.symbol(instrument), 'price')\n amount = math.floor(cash / current_price / 100) * 100\n context.order(context.symbol(instrument), amount)\n print(\"***current_price = data.current(context.symbol(instrument), 'price')***\")\n print(\"******* context.symbol(instrument) is*******\")\n print(context.symbol(instrument))\n print(\"******* current_price is*******\")\n print(current_price)\n print(\"***amount = math.floor(cash / current_price / 100) * 100***\")\n print(\"******* amount is*******\")\n print(amount)\n \n \n \n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":1000000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"真实价格","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-159"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-159"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-159"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-159"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-159"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-159","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":20,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='211,64,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='70,183,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='765,21,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='906,647,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1074,127,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='376,467,200,200'/><NodePosition Node='-86' Position='1078,418,200,200'/><NodePosition Node='-106' Position='381,188,200,200'/><NodePosition Node='-113' Position='385,280,200,200'/><NodePosition Node='-126' Position='638,561,200,200'/><NodePosition Node='-140' Position='1078,236,200,200'/><NodePosition Node='-147' Position='1081,327,200,200'/><NodePosition Node='-159' Position='1037,751,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":false}
    In [1]:
    # 本代码由可视化策略环境自动生成 2020年8月1日 17:50
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m20_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 = 2
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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'] = 5
    
        help(context.has_unfinished_sell_order)
    # 回测引擎:每日数据处理函数,每天执行一次
    def m20_handle_data_bigquant_run(context, data):
        # 按日期过滤得到今日的预测数据
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
        print("--------------------------------------------------------------------------------")
        print("------------------ranker_prediction  is-----------------------------------------")
        print(ranker_prediction)
        
    
        # 1. 资金分配
        print("1. 资金分配")
        
        # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金
        # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)
        is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)
        print("----------context.trading_day_index  is-----------------------------------------")
        print(context.trading_day_index)
        #每天进行滚动,从0开始的
        
        print("*******context.portfolio is*******")
        print(context.portfolio)
            
           
        cash_avg = context.portfolio.portfolio_value / context.options['hold_days']
        print("-------------------------------cash_avg  is-------------------------------------")
        print(cash_avg)
        
        cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)
        print("*******context.portfolio.cash is*******")
        print(context.portfolio.cash)
        
        print("*******cash_for_buy is*******")
        print(cash_for_buy)
        
        
        cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
        print("*******cash_for_sell is*******")
        print(cash_for_sell)
        
        
        positions = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.perf_tracker.position_tracker.positions.items()}
        print("*******positions is*******")
        print(positions)
        
    
    
        # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
        print("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()}
            print("****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***")
            print("*******equities is*******")
            print(equities)
            
            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("****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("*******instruments is*******")
            print(instruments)
            
            
            # print('rank order for sell %s' % instruments)
            print("***rank order for sell %s' % instruments***")
            for instrument in instruments:
                print("*******for instrument in instruments:*******")
                print("*******instrument is*******")
                print(instrument)
                
                context.order_target(context.symbol(instrument), 0)
                cash_for_sell -= positions[instrument]
                print("***cash_for_sell -= positions[instrument]***")
                print("*******cash_for_sell is*******")
                print(cash_for_sell)
                
                if cash_for_sell <= 0:
                    break
                    
                    
                    
                    
    
        # 3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
        print("3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票")
        buy_cash_weights = context.stock_weights
        #即将购买股票权重
        print("*******context.stock_weights is*******")
        print(context.stock_weights)
        
        buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])
        #购买股票的代码,eg:['002194.SZA', '000063.SZA']
        print("*******buy_instruments is*******")
        print(buy_instruments)
        
        max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument
        print("***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***")
        print("*******context.portfolio.portfolio_value is*******")
        print(context.portfolio.portfolio_value)
        print("*******context.max_cash_per_instrument is*******")
        print(context.max_cash_per_instrument)
        print("******* max_cash_per_instrument is*******")
        print( max_cash_per_instrument)
        
        for i, instrument in enumerate(buy_instruments):
            cash = cash_for_buy * buy_cash_weights[i]
            print("******* Number of stock to buy is*******")
            print(i)
            print("***cash = cash_for_buy * buy_cash_weights[i]***")
            print(cash)
            
            print("******判断是否跳入补仓金额判断******")
            print("******if cash > max_cash_per_instrument - positions.get(instrument, 0):******")
            print("******positions.get(instrument, 0)******")
            print(positions.get(instrument, 0))
            print("******max_cash_per_instrument - positions.get(instrument, 0)******")
            print(max_cash_per_instrument - positions.get(instrument, 0))
            print("******cash > max_cash_per_instrument - positions.get(instrument, 0)******")
            print(cash > max_cash_per_instrument - positions.get(instrument, 0))
            
            
            if cash > max_cash_per_instrument - positions.get(instrument, 0):
                # 确保股票持仓量不会超过每次股票最大的占用资金量
                cash = max_cash_per_instrument - positions.get(instrument, 0)
                print("***cash > max_cash_per_instrument - positions.get(instrument, 0):***")
                print("******* positions.get(instrument, 0) is*******")
                print(positions.get(instrument, 0))
                print("******* cash is*******")
                print(cash)
                
            if cash > 0:
                current_price = data.current(context.symbol(instrument), 'price')
                amount = math.floor(cash / current_price / 100) * 100
                context.order(context.symbol(instrument), amount)
                print("***current_price = data.current(context.symbol(instrument), 'price')***")
                print("******* context.symbol(instrument) is*******")
                print(context.symbol(instrument))
                print("******* current_price is*******")
                print(current_price)
                print("***amount = math.floor(cash / current_price / 100) * 100***")
                print("******* amount is*******")
                print(amount)
                
                
                
    
    # 回测引擎:准备数据,只执行一次
    def m20_prepare_bigquant_run(context):
        pass
    
    
    m1 = M.instruments.v2(
        start_date='2011-01-01',
        end_date='2012-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        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)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
     
    (close_0 + close_1 + close_2 + close_3 + close_4) / 5 / close_0
    max(high_0, high_1, high_2) / min(low_0, low_1, low_2)
    mean(close_0,20)/std(close_0,20)
    delta(open_0/shift(close_0,1), 10)
     
    """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m7.data
    )
    
    m17 = M.stock_ranker_train.v6(
        training_ds=m13.data,
        features=m3.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=20,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        data_row_fraction=1,
        ndcg_discount_base=1,
        m_lazy_run=False
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2016-05-01'),
        end_date=T.live_run_param('trading_date', '2016-08-01'),
        market='CN_STOCK_A',
        instrument_list="""600030.SHA
    601688.SHA
    000063.SZA
    600498.SHA
    300308.SZA
    002281.SZA
    002792.SZA
    002194.SZA
    600487.SHA
    300383.SZA""",
        max_count=0
    )
    
    m18 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m19 = M.derived_feature_extractor.v3(
        input_data=m18.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m14 = M.dropnan.v1(
        input_data=m19.data
    )
    
    m8 = M.stock_ranker_predict.v5(
        model=m17.model,
        data=m14.data,
        m_lazy_run=False
    )
    
    m20 = M.trade.v4(
        instruments=m9.data,
        options_data=m8.predictions,
        start_date='',
        end_date='',
        initialize=m20_initialize_bigquant_run,
        handle_data=m20_handle_data_bigquant_run,
        prepare=m20_prepare_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='真实价格',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark='000300.SHA'
    )
    
    设置评估测试数据集,查看训练曲线
    [视频教程]StockRanker训练曲线
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-c1bea27a4272423c85e7bef5ef16b8f3"}/bigcharts-data-end
    Help on method _has_unfinished_sell_order:
    
    _has_unfinished_sell_order(equity) method of zipline.algorithm.TradingAlgorithm instance
    
    
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    0
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    200000.0
    *******cash_for_sell is*******
    -600000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    1
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    200000.0
    *******cash_for_sell is*******
    -600000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    2
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    200000.0
    *******cash_for_sell is*******
    -600000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    3
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    200000.0
    *******cash_for_sell is*******
    -600000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    4
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    200000.0
    *******cash_for_sell is*******
    -600000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    5
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    6
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    7
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    8
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    9
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    10
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    11
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    12
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    13
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    14
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    15
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    16
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    17
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
    Empty DataFrame
    Columns: [date, instrument, score, position]
    Index: []
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    18
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    []
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
            date  instrument     score  position
    0 2016-05-30  002194.SZA  0.175806         1
    1 2016-05-30  000063.SZA  0.028962         2
    2 2016-05-30  600030.SHA  0.024937         3
    3 2016-05-30  601688.SHA -0.004531         4
    4 2016-05-30  600487.SHA -0.062095         5
    5 2016-05-30  002281.SZA -0.085332         6
    6 2016-05-30  600498.SHA -0.095832         7
    7 2016-05-30  002792.SZA -0.159608         8
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    19
    *******context.portfolio is*******
    Portfolio({'capital_used': 0.0, 'starting_cash': 1000000, 'portfolio_value': 1000000.0, 'pnl': 0.0, 'returns': 0.0, 'cash': 1000000.0, 'actual_cash': 1000000.0, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {}, 'positions_value': 0.0, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 0.0})
    -------------------------------cash_avg  is-------------------------------------
    200000.0
    *******context.portfolio.cash is*******
    1000000.0
    *******cash_for_buy is*******
    300000.0
    *******cash_for_sell is*******
    -500000.0
    *******positions is*******
    {}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1000000.0
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    200000.0
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    183944.15782963752
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    200000.0
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    10.450001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    17600
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    116055.84217036246
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    200000.0
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.29
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    8700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    8  2016-05-31  002194.SZA -0.081046         1
    9  2016-05-31  000063.SZA -0.093206         2
    10 2016-05-31  600487.SHA -0.094764         3
    11 2016-05-31  002281.SZA -0.106121         4
    12 2016-05-31  600498.SHA -0.145665         5
    13 2016-05-31  601688.SHA -0.161714         6
    14 2016-05-31  600030.SHA -0.181315         7
    15 2016-05-31  002792.SZA -0.360610         8
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    20
    *******context.portfolio is*******
    Portfolio({'capital_used': -302006.7535058257, 'starting_cash': 1000000, 'portfolio_value': 1011655.2481993439, 'pnl': 11655.248199343914, 'returns': 0.011655248199343915, 'cash': 697993.2464941742, 'actual_cash': 697993.2464941742, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:17600,today_amount:17600,frozen_amount:0,cost_basis:10.57,last_sale_price:11.010000228881836,available_close_amount:17600), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:8700,today_amount:8700,frozen_amount:0,cost_basis:13.32,last_sale_price:13.779999732971191,available_close_amount:8700)}, 'positions_value': 313662.0017051697, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 313662.0017051697})
    -------------------------------cash_avg  is-------------------------------------
    202331.04963986878
    *******context.portfolio.cash is*******
    697993.2464941742
    *******cash_for_buy is*******
    303496.5744598032
    *******cash_for_sell is*******
    -192165.62239450228
    *******positions is*******
    {'002194.SZA': 193776.0040283203, '000063.SZA': 119885.99767684937}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1011655.2481993439
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    202331.04963986878
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186088.07264396123
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    193776.0040283203
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    8555.04561154847
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    193776.0040283203
    ******* cash is*******
    8555.04561154847
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    11.01
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    700
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117408.50181584191
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    119885.99767684937
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    82445.05196301942
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    119885.99767684937
    ******* cash is*******
    82445.05196301942
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.78
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    5900
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    16 2016-06-01  002194.SZA -0.048137         1
    17 2016-06-01  000063.SZA -0.091420         2
    18 2016-06-01  002281.SZA -0.094764         3
    19 2016-06-01  600498.SHA -0.116533         4
    20 2016-06-01  600487.SHA -0.120945         5
    21 2016-06-01  002792.SZA -0.128242         6
    22 2016-06-01  601688.SHA -0.130400         7
    23 2016-06-01  600030.SHA -0.181367         8
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    21
    *******context.portfolio is*******
    Portfolio({'capital_used': -391222.20005503664, 'starting_cash': 1000000, 'portfolio_value': 1012768.8059378527, 'pnl': 12768.80593785271, 'returns': 0.01276880593785271, 'cash': 608777.7999449633, 'actual_cash': 608777.7999449633, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:18300,today_amount:700,frozen_amount:0,cost_basis:10.587,last_sale_price:11.130000114440918,available_close_amount:18300), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:14600,today_amount:5900,frozen_amount:0,cost_basis:13.518,last_sale_price:13.720000267028809,available_close_amount:14600)}, 'positions_value': 403991.0059928894, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 403991.0059928894})
    -------------------------------cash_avg  is-------------------------------------
    202553.76118757055
    *******context.portfolio.cash is*******
    608777.7999449633
    *******cash_for_buy is*******
    303830.64178135584
    *******cash_for_sell is*******
    -102393.39697603692
    *******positions is*******
    {'002194.SZA': 203679.0020942688, '000063.SZA': 200312.0038986206}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1012768.8059378527
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    202553.76118757055
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186292.90508436592
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    203679.0020942688
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -1125.240906698251
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    203679.0020942688
    ******* cash is*******
    -1125.240906698251
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117537.73669698989
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200312.0038986206
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2241.7572889499424
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200312.0038986206
    ******* cash is*******
    2241.7572889499424
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.72
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    24 2016-06-02  600498.SHA -0.019339         1
    25 2016-06-02  601688.SHA -0.048137         2
    26 2016-06-02  600487.SHA -0.050238         3
    27 2016-06-02  000063.SZA -0.084484         4
    28 2016-06-02  600030.SHA -0.116533         5
    29 2016-06-02  002194.SZA -0.132256         6
    30 2016-06-02  002281.SZA -0.161875         7
    31 2016-06-02  002792.SZA -0.281546         8
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    22
    *******context.portfolio is*******
    Portfolio({'capital_used': -392600.20010463044, 'starting_cash': 1000000, 'portfolio_value': 1014376.7973662253, 'pnl': 14376.797366225277, 'returns': 0.014376797366225278, 'cash': 607399.7998953696, 'actual_cash': 607399.7998953696, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:18300,today_amount:0,frozen_amount:0,cost_basis:10.587,last_sale_price:11.170000076293945,available_close_amount:18300), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:14700,today_amount:100,frozen_amount:0,cost_basis:13.519,last_sale_price:13.779999732971191,available_close_amount:14700)}, 'positions_value': 406976.9974708557, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 406976.9974708557})
    -------------------------------cash_avg  is-------------------------------------
    202875.35947324504
    *******context.portfolio.cash is*******
    607399.7998953696
    *******cash_for_buy is*******
    304313.0392098676
    *******cash_for_sell is*******
    -100211.40121225693
    *******positions is*******
    {'002194.SZA': 204411.0013961792, '000063.SZA': 202565.9960746765}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '601688.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1014376.7973662253
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    202875.35947324507
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186588.68571345517
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    202875.35947324507
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.9
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    7800
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117724.35349641238
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    202875.35947324507
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    18.35
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    6400
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    32 2016-06-03  600498.SHA  0.080763         1
    33 2016-06-03  600030.SHA -0.023579         2
    34 2016-06-03  002281.SZA -0.036633         3
    35 2016-06-03  600487.SHA -0.066178         4
    36 2016-06-03  002194.SZA -0.084484         5
    37 2016-06-03  601688.SHA -0.132230         6
    38 2016-06-03  000063.SZA -0.218522         7
    39 2016-06-03  002792.SZA -0.373203         8
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    23
    *******context.portfolio is*******
    Portfolio({'capital_used': -696203.2683825346, 'starting_cash': 1000000, 'portfolio_value': 1020936.7478871492, 'pnl': 20936.74788714922, 'returns': 0.02093674788714922, 'cash': 303796.7316174654, 'actual_cash': 303796.7316174654, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:18300,today_amount:0,frozen_amount:0,cost_basis:10.587,last_sale_price:11.289999961853027,available_close_amount:18300), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:14700,today_amount:0,frozen_amount:0,cost_basis:13.519,last_sale_price:13.949999809265137,available_close_amount:14700), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:7800,today_amount:7800,frozen_amount:0,cost_basis:23.88,last_sale_price:23.860000610351562,available_close_amount:7800), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6400,today_amount:6400,frozen_amount:0,cost_basis:18.32,last_sale_price:18.649999618530273,available_close_amount:6400)}, 'positions_value': 717140.0162696838, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 717140.0162696838})
    -------------------------------cash_avg  is-------------------------------------
    204187.34957742985
    *******context.portfolio.cash is*******
    303796.7316174654
    *******cash_for_buy is*******
    303796.7316174654
    *******cash_for_sell is*******
    204187.34957742985
    *******positions is*******
    {'002194.SZA': 206607.0167541504, '000063.SZA': 205064.9971961975, '600498.SHA': 186108.0047607422, '601688.SHA': 119359.99755859375}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002194.SZA': Equity(104 [002194.SZA]), '000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '601688.SHA': Equity(273 [601688.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['000063.SZA', '601688.SHA', '002194.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    000063.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -877.6476187676599
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '600030.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1020936.7478871492
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    204187.34957742985
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186272.11316257025
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    186108.0047607422
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    18079.344816687662
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    186108.0047607422
    ******* cash is*******
    18079.344816687662
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.86
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    700
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117524.61845489508
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    204187.34957742985
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.619999
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    7000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    40 2016-06-06  600498.SHA  0.043860         1
    41 2016-06-06  600030.SHA  0.036712         2
    42 2016-06-06  002194.SZA  0.021470         3
    43 2016-06-06  000063.SZA  0.006394         4
    44 2016-06-06  002281.SZA -0.052448         5
    45 2016-06-06  600487.SHA -0.116533         6
    46 2016-06-06  601688.SHA -0.132230         7
    47 2016-06-06  300383.SZA -0.149440         8
    48 2016-06-06  002792.SZA -0.208531         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    24
    *******context.portfolio is*******
    Portfolio({'capital_used': -624270.4020360955, 'starting_cash': 1000000, 'portfolio_value': 1018503.6276002876, 'pnl': 18503.627600287553, 'returns': 0.018503627600287554, 'cash': 375729.5979639045, 'actual_cash': 375729.5979639045, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:18300,today_amount:0,frozen_amount:0,cost_basis:10.587,last_sale_price:11.329999923706055,available_close_amount:18300), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8500,today_amount:700,frozen_amount:0,cost_basis:23.88,last_sale_price:23.6299991607666,available_close_amount:8500), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6400,today_amount:0,frozen_amount:0,cost_basis:18.32,last_sale_price:18.649999618530273,available_close_amount:6400), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:7000,today_amount:7000,frozen_amount:0,cost_basis:16.65,last_sale_price:16.459999084472656,available_close_amount:7000)}, 'positions_value': 642774.029636383, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 642774.029636383})
    -------------------------------cash_avg  is-------------------------------------
    203700.72552005752
    *******context.portfolio.cash is*******
    375729.5979639045
    *******cash_for_buy is*******
    305551.0882800863
    *******cash_for_sell is*******
    133522.2158362393
    *******positions is*******
    {'002194.SZA': 207339.0160560608, '600498.SHA': 200855.0090789795, '601688.SHA': 119359.99755859375, '600030.SHA': 115220.00694274902}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002194.SZA': Equity(104 [002194.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '601688.SHA': Equity(273 [601688.SHA]), '600030.SHA': Equity(9 [600030.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['601688.SHA', '002194.SZA', '600030.SHA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    601688.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    14162.21827764556
    *******for instrument in instruments:*******
    *******instrument is*******
    002194.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -193176.79777841523
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '600030.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1018503.6276002876
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    203700.72552005752
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    187347.79202536566
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200855.0090789795
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2845.716441078024
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200855.0090789795
    ******* cash is*******
    2845.716441078024
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.630001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    118203.2962547206
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    115220.00694274902
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    88480.7185773085
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    115220.00694274902
    ******* cash is*******
    88480.7185773085
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.460001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    5300
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    49 2016-06-07  600030.SHA  0.063682         1
    50 2016-06-07  002194.SZA  0.032317         2
    51 2016-06-07  000063.SZA  0.025999         3
    52 2016-06-07  600498.SHA  0.005138         4
    53 2016-06-07  002281.SZA -0.052448         5
    54 2016-06-07  601688.SHA -0.073459         6
    55 2016-06-07  600487.SHA -0.107143         7
    56 2016-06-07  300383.SZA -0.131972         8
    57 2016-06-07  002792.SZA -0.429115         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    25
    *******context.portfolio is*******
    Portfolio({'capital_used': -390546.5520675152, 'starting_cash': 1000000, 'portfolio_value': 1017734.456271413, 'pnl': 17734.456271413015, 'returns': 0.017734456271413016, 'cash': 609453.4479324848, 'actual_cash': 609453.4479324848, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:100,frozen_amount:0,cost_basis:23.878,last_sale_price:23.889999389648438,available_close_amount:8600), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12300,today_amount:5300,frozen_amount:0,cost_basis:16.59,last_sale_price:16.489999771118164,available_close_amount:12300)}, 'positions_value': 408281.0083389282, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 408281.0083389282})
    -------------------------------cash_avg  is-------------------------------------
    203546.89125428261
    *******context.portfolio.cash is*******
    609453.4479324848
    *******cash_for_buy is*******
    305320.33688142395
    *******cash_for_sell is*******
    -100586.21979677823
    *******positions is*******
    {'600498.SHA': 205454.0111541748, '600030.SHA': 202826.99718475342}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '002194.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1017734.456271413
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    203546.89125428261
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    187206.30745304914
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    202826.99718475342
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    719.8940695291967
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    202826.99718475342
    ******* cash is*******
    719.8940695291967
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.49
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    118114.02942837478
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    203546.89125428261
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    11.21
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    10500
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    58 2016-06-08  601688.SHA  0.434478         1
    59 2016-06-08  000063.SZA  0.405339         2
    60 2016-06-08  002792.SZA  0.399253         3
    61 2016-06-08  300383.SZA  0.161742         4
    62 2016-06-08  600498.SHA  0.153275         5
    63 2016-06-08  002194.SZA  0.069164         6
    64 2016-06-08  600030.SHA  0.015572         7
    65 2016-06-08  002281.SZA -0.001670         8
    66 2016-06-08  600487.SHA -0.095832         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    26
    *******context.portfolio is*******
    Portfolio({'capital_used': -508286.9458404883, 'starting_cash': 1000000, 'portfolio_value': 1013823.0668815271, 'pnl': 13823.066881527076, 'returns': 0.013823066881527077, 'cash': 491713.0541595117, 'actual_cash': 491713.0541595117, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:23.878,last_sale_price:23.68000030517578,available_close_amount:8600), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12300,today_amount:0,frozen_amount:0,cost_basis:16.59,last_sale_price:16.389999389648438,available_close_amount:12300), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:10500,today_amount:10500,frozen_amount:0,cost_basis:11.21,last_sale_price:11.130000114440918,available_close_amount:10500)}, 'positions_value': 522110.0127220154, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 522110.0127220154})
    -------------------------------cash_avg  is-------------------------------------
    202764.6133763054
    *******context.portfolio.cash is*******
    491713.0541595117
    *******cash_for_buy is*******
    304146.9200644581
    *******cash_for_sell is*******
    15198.479281251814
    *******positions is*******
    {'600498.SHA': 203648.01902770996, '600030.SHA': 201596.99249267578, '002194.SZA': 116865.00120162964}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '600030.SHA': Equity(9 [600030.SHA]), '002194.SZA': Equity(104 [002194.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['600030.SHA', '002194.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600030.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -186398.51321142397
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['601688.SHA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1013823.0668815271
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    202764.61337630544
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186486.83022578276
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    202764.61337630544
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    17.99
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    10300
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117660.08983867531
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    202764.61337630544
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.81
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    8500
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    67 2016-06-13  002792.SZA  0.790011         1
    68 2016-06-13  300383.SZA  0.443879         2
    69 2016-06-13  002281.SZA  0.380674         3
    70 2016-06-13  601688.SHA  0.377935         4
    71 2016-06-13  600498.SHA  0.172061         5
    72 2016-06-13  000063.SZA  0.166284         6
    73 2016-06-13  002194.SZA  0.146677         7
    74 2016-06-13  600030.SHA  0.146677         8
    75 2016-06-13  600487.SHA -0.002717         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    27
    *******context.portfolio is*******
    Portfolio({'capital_used': -613927.7584301017, 'starting_cash': 1000000, 'portfolio_value': 984986.2406505563, 'pnl': -15013.759349443717, 'returns': -0.015013759349443717, 'cash': 386072.2415698983, 'actual_cash': 386072.2415698983, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:23.878,last_sale_price:23.0,available_close_amount:8600), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:10500,today_amount:0,frozen_amount:0,cost_basis:11.21,last_sale_price:10.630000114440918,available_close_amount:10500), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:10300,today_amount:10300,frozen_amount:0,cost_basis:17.6,last_sale_price:17.229999542236328,available_close_amount:10300), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:8500,today_amount:8500,frozen_amount:0,cost_basis:13.65,last_sale_price:13.180000305175781,available_close_amount:8500)}, 'positions_value': 598913.999080658, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 598913.999080658})
    -------------------------------cash_avg  is-------------------------------------
    196997.24813011126
    *******context.portfolio.cash is*******
    386072.2415698983
    *******cash_for_buy is*******
    295495.8721951669
    *******cash_for_sell is*******
    106420.87875537982
    *******positions is*******
    {'600498.SHA': 197800.0, '002194.SZA': 111615.00120162964, '601688.SHA': 177468.99528503418, '000063.SZA': 112030.00259399414}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '002194.SZA': Equity(104 [002194.SZA]), '601688.SHA': Equity(273 [601688.SHA]), '000063.SZA': Equity(235 [000063.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002194.SZA', '000063.SZA', '600498.SHA', '601688.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002194.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -5194.122446249821
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '300383.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    984986.2406505563
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    196997.24813011126
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    181182.46451024723
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    196997.24813011126
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    53.55
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3300
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    114313.40768491961
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    196997.24813011126
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    34.4
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3300
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    76 2016-06-14  002792.SZA  0.790011         1
    77 2016-06-14  600498.SHA  0.527048         2
    78 2016-06-14  300383.SZA  0.443879         3
    79 2016-06-14  601688.SHA  0.380674         4
    80 2016-06-14  002281.SZA  0.363597         5
    81 2016-06-14  000063.SZA  0.262523         6
    82 2016-06-14  600030.SHA  0.178167         7
    83 2016-06-14  600487.SHA  0.011216         8
    84 2016-06-14  002194.SZA -0.039017         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    28
    *******context.portfolio is*******
    Portfolio({'capital_used': -785172.255742612, 'starting_cash': 1000000, 'portfolio_value': 992907.7449440336, 'pnl': -7092.255055966438, 'returns': -0.007092255055966438, 'cash': 214827.74425738805, 'actual_cash': 214827.74425738805, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:23.878,last_sale_price:23.309999465942383,available_close_amount:8600), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:10300,today_amount:0,frozen_amount:0,cost_basis:17.6,last_sale_price:17.280000686645508,available_close_amount:10300), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:8500,today_amount:0,frozen_amount:0,cost_basis:13.65,last_sale_price:13.199999809265137,available_close_amount:8500), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3300,today_amount:3300,frozen_amount:0,cost_basis:51.6,last_sale_price:52.95000076293945,available_close_amount:3300), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:3300,frozen_amount:0,cost_basis:33.95,last_sale_price:34.150001525878906,available_close_amount:3300)}, 'positions_value': 778080.0006866455, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 778080.0006866455})
    -------------------------------cash_avg  is-------------------------------------
    198581.54898880672
    *******context.portfolio.cash is*******
    214827.74425738805
    *******cash_for_buy is*******
    214827.74425738805
    *******cash_for_sell is*******
    198581.54898880672
    *******positions is*******
    {'600498.SHA': 200466.01181030273, '601688.SHA': 177983.9874267578, '000063.SZA': 112200.00648498535, '002792.SZA': 174734.98992919922, '300383.SZA': 112695.00503540039}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '601688.SHA': Equity(273 [601688.SHA]), '000063.SZA': Equity(235 [000063.SZA]), '002792.SZA': Equity(95 [002792.SZA]), '300383.SZA': Equity(182 [300383.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['000063.SZA', '601688.SHA', '300383.SZA', '600498.SHA', '002792.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    000063.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    86381.54250382137
    *******for instrument in instruments:*******
    *******instrument is*******
    601688.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -91602.44492293644
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    992907.7449440336
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    198581.54898880672
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    131721.0283195533
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    174734.98992919922
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    23846.559059607505
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    174734.98992919922
    ******* cash is*******
    23846.559059607505
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    52.949997
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    400
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    83106.71593783473
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200466.01181030273
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -1884.4628214960103
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200466.01181030273
    ******* cash is*******
    -1884.4628214960103
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
             date  instrument     score  position
    85 2016-06-15  002792.SZA  0.489859         1
    86 2016-06-15  601688.SHA  0.481427         2
    87 2016-06-15  600030.SHA  0.274447         3
    88 2016-06-15  300383.SZA  0.244059         4
    89 2016-06-15  000063.SZA  0.131796         5
    90 2016-06-15  002194.SZA -0.079482         6
    91 2016-06-15  600487.SHA -0.097957         7
    92 2016-06-15  002281.SZA -0.132677         8
    93 2016-06-15  600498.SHA -0.164154         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    29
    *******context.portfolio is*******
    Portfolio({'capital_used': -510917.10418228037, 'starting_cash': 1000000, 'portfolio_value': 1012957.9045915233, 'pnl': 12957.904591523344, 'returns': 0.012957904591523343, 'cash': 489082.89581771963, 'actual_cash': 489082.89581771963, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:23.878,last_sale_price:23.799999237060547,available_close_amount:8600), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3700,today_amount:400,frozen_amount:0,cost_basis:51.565,last_sale_price:54.90999984741211,available_close_amount:3700), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:0,frozen_amount:0,cost_basis:33.95,last_sale_price:35.15999984741211,available_close_amount:3300)}, 'positions_value': 523875.0087738037, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 523875.0087738037})
    -------------------------------cash_avg  is-------------------------------------
    202591.58091830468
    *******context.portfolio.cash is*******
    489082.89581771963
    *******cash_for_buy is*******
    303887.37137745705
    *******cash_for_sell is*******
    17396.056478042097
    *******positions is*******
    {'600498.SHA': 204680.00984191895, '002792.SZA': 203166.9994354248, '300383.SZA': 116027.99949645996}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '002792.SZA': Equity(95 [002792.SZA]), '300383.SZA': Equity(182 [300383.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['600498.SHA', '300383.SZA', '002792.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -187283.95336387685
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '601688.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1012957.9045915233
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    202591.58091830468
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    186327.6886769621
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    203166.9994354248
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -575.4185171201243
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    203166.9994354248
    ******* cash is*******
    -575.4185171201243
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117559.68270049492
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    202591.58091830468
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    17.54
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    6700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    94  2016-06-16  002792.SZA  0.794145         1
    95  2016-06-16  000063.SZA  0.449659         2
    96  2016-06-16  300383.SZA  0.418512         3
    97  2016-06-16  601688.SHA  0.324276         4
    98  2016-06-16  600030.SHA  0.181018         5
    99  2016-06-16  600487.SHA  0.147235         6
    100 2016-06-16  600498.SHA  0.019569         7
    101 2016-06-16  002194.SZA -0.166373         8
    102 2016-06-16  002281.SZA -0.179871         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    30
    *******context.portfolio is*******
    Portfolio({'capital_used': -424188.55108341516, 'starting_cash': 1000000, 'portfolio_value': 1005039.4457427567, 'pnl': 5039.44574275671, 'returns': 0.00503944574275671, 'cash': 575811.4489165848, 'actual_cash': 575811.4489165848, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3700,today_amount:0,frozen_amount:0,cost_basis:51.565,last_sale_price:54.31999969482422,available_close_amount:3700), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:0,frozen_amount:0,cost_basis:33.95,last_sale_price:34.0,available_close_amount:3300), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6700,today_amount:6700,frozen_amount:0,cost_basis:17.47,last_sale_price:17.31999969482422,available_close_amount:6700)}, 'positions_value': 429227.9968261719, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 429227.9968261719})
    -------------------------------cash_avg  is-------------------------------------
    201007.88914855133
    *******context.portfolio.cash is*******
    575811.4489165848
    *******cash_for_buy is*******
    301511.833722827
    *******cash_for_sell is*******
    -73291.72604520648
    *******positions is*******
    {'002792.SZA': 200983.9988708496, '300383.SZA': 112200.0, '601688.SHA': 116043.99795532227}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1005039.4457427567
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    201007.88914855136
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    184871.13443271705
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200983.9988708496
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    23.890277701750165
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200983.9988708496
    ******* cash is*******
    23.890277701750165
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    54.32
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    116640.69929010994
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    201007.88914855136
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.31
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    8700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    103 2016-06-17  600030.SHA  0.066264         1
    104 2016-06-17  000063.SZA -0.005401         2
    105 2016-06-17  600498.SHA -0.048612         3
    106 2016-06-17  300383.SZA -0.072638         4
    107 2016-06-17  002281.SZA -0.081046         5
    108 2016-06-17  600487.SHA -0.095832         6
    109 2016-06-17  601688.SHA -0.099049         7
    110 2016-06-17  002194.SZA -0.118318         8
    111 2016-06-17  002792.SZA -0.271226         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    31
    *******context.portfolio is*******
    Portfolio({'capital_used': -541064.6064092129, 'starting_cash': 1000000, 'portfolio_value': 1016710.3828142673, 'pnl': 16710.3828142673, 'returns': 0.016710382814267302, 'cash': 458935.3935907871, 'actual_cash': 458935.3935907871, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3700,today_amount:0,frozen_amount:0,cost_basis:51.565,last_sale_price:56.119998931884766,available_close_amount:3700), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:0,frozen_amount:0,cost_basis:33.95,last_sale_price:34.31999969482422,available_close_amount:3300), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6700,today_amount:0,frozen_amount:0,cost_basis:17.47,last_sale_price:17.5,available_close_amount:6700), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:8700,today_amount:8700,frozen_amount:0,cost_basis:13.43,last_sale_price:13.75,available_close_amount:8700)}, 'positions_value': 557774.9892234802, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 557774.9892234802})
    -------------------------------cash_avg  is-------------------------------------
    203342.07656285347
    *******context.portfolio.cash is*******
    458935.3935907871
    *******cash_for_buy is*******
    305013.1148442802
    *******cash_for_sell is*******
    49419.797816346574
    *******positions is*******
    {'002792.SZA': 207643.98193359375, '300383.SZA': 113255.99899291992, '601688.SHA': 117250.0, '000063.SZA': 119625.00829696655}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002792.SZA': Equity(95 [002792.SZA]), '300383.SZA': Equity(182 [300383.SZA]), '601688.SHA': Equity(273 [601688.SHA]), '000063.SZA': Equity(235 [000063.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002792.SZA', '601688.SHA', '300383.SZA', '000063.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002792.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -158224.18411724718
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1016710.3828142673
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    203342.07656285347
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    187017.93512341875
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    203342.07656285347
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    15.669999
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    11900
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    117995.1797208614
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    119625.00829696655
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    83717.06826588692
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    119625.00829696655
    ******* cash is*******
    83717.06826588692
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.750001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    6000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    112 2016-06-20  300383.SZA  0.437616         1
    113 2016-06-20  600498.SHA  0.365682         2
    114 2016-06-20  600030.SHA  0.066067         3
    115 2016-06-20  000063.SZA -0.019339         4
    116 2016-06-20  002194.SZA -0.039427         5
    117 2016-06-20  601688.SHA -0.047632         6
    118 2016-06-20  600487.SHA -0.064749         7
    119 2016-06-20  002281.SZA -0.176974         8
    120 2016-06-20  002792.SZA -0.280329         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    32
    *******context.portfolio is*******
    Portfolio({'capital_used': -597432.8159120416, 'starting_cash': 1000000, 'portfolio_value': 1020192.1777937079, 'pnl': 20192.17779370793, 'returns': 0.02019217779370793, 'cash': 402567.1840879584, 'actual_cash': 402567.1840879584, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:0,frozen_amount:0,cost_basis:33.95,last_sale_price:33.97999954223633,available_close_amount:3300), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6700,today_amount:0,frozen_amount:0,cost_basis:17.47,last_sale_price:17.639999389648438,available_close_amount:6700), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:14700,today_amount:6000,frozen_amount:0,cost_basis:13.557,last_sale_price:13.670000076293945,available_close_amount:14700), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:11900,today_amount:11900,frozen_amount:0,cost_basis:15.71,last_sale_price:15.65999984741211,available_close_amount:11900)}, 'positions_value': 617624.9937057495, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 617624.9937057495})
    -------------------------------cash_avg  is-------------------------------------
    204038.4355587416
    *******context.portfolio.cash is*******
    402567.1840879584
    *******cash_for_buy is*******
    306057.6533381124
    *******cash_for_sell is*******
    107528.90480889558
    *******positions is*******
    {'300383.SZA': 112133.99848937988, '601688.SHA': 118187.99591064453, '000063.SZA': 200949.001121521, '600030.SHA': 186353.9981842041}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'300383.SZA': Equity(182 [300383.SZA]), '601688.SHA': Equity(273 [601688.SHA]), '000063.SZA': Equity(235 [000063.SZA]), '600030.SHA': Equity(9 [600030.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['601688.SHA', '000063.SZA', '600030.SHA', '300383.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    601688.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -10659.091101748956
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['300383.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1020192.1777937079
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    204038.4355587416
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    187658.39096864744
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    112133.99848937988
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    91904.43706936171
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    112133.99848937988
    ******* cash is*******
    91904.43706936171
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    33.98
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    2700
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    118399.26236946492
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    204038.4355587416
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.480001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    5000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    121 2016-06-21  300383.SZA  0.314184         1
    122 2016-06-21  000063.SZA  0.111714         2
    123 2016-06-21  600498.SHA  0.105126         3
    124 2016-06-21  600487.SHA  0.092750         4
    125 2016-06-21  002194.SZA  0.069638         5
    126 2016-06-21  600030.SHA -0.001410         6
    127 2016-06-21  601688.SHA -0.094764         7
    128 2016-06-21  002281.SZA -0.128435         8
    129 2016-06-21  002792.SZA -0.248964         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    33
    *******context.portfolio is*******
    Portfolio({'capital_used': -689453.3886231967, 'starting_cash': 1000000, 'portfolio_value': 1020836.603995364, 'pnl': 20836.603995364043, 'returns': 0.020836603995364043, 'cash': 310546.61137680325, 'actual_cash': 310546.61137680325, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:6000,today_amount:2700,frozen_amount:0,cost_basis:34.188,last_sale_price:34.04999923706055,available_close_amount:6000), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:14700,today_amount:0,frozen_amount:0,cost_basis:13.557,last_sale_price:13.520000457763672,available_close_amount:14700), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:11900,today_amount:0,frozen_amount:0,cost_basis:15.71,last_sale_price:15.84000015258789,available_close_amount:11900), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:5000,today_amount:5000,frozen_amount:0,cost_basis:23.62,last_sale_price:23.75,available_close_amount:5000)}, 'positions_value': 710289.9926185608, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 710289.9926185608})
    -------------------------------cash_avg  is-------------------------------------
    204167.3207990728
    *******context.portfolio.cash is*******
    310546.61137680325
    *******cash_for_buy is*******
    306250.9811986092
    *******cash_for_sell is*******
    199871.69062087877
    *******positions is*******
    {'300383.SZA': 204299.99542236328, '000063.SZA': 198744.00672912598, '600030.SHA': 188495.99046707153, '600498.SHA': 118750.0}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'300383.SZA': Equity(182 [300383.SZA]), '000063.SZA': Equity(235 [000063.SZA]), '600030.SHA': Equity(9 [600030.SHA]), '600498.SHA': Equity(73 [600498.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600030.SHA', '600498.SHA', '000063.SZA', '300383.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600030.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    11375.700153807236
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -107374.29984619276
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['300383.SZA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1020836.603995364
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    204167.32079907283
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    187776.9294035944
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    204299.99542236328
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -132.6746232904552
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    204299.99542236328
    ******* cash is*******
    -132.6746232904552
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    118474.05179501478
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    198744.00672912598
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    5423.3140699468495
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    198744.00672912598
    ******* cash is*******
    5423.3140699468495
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    13.52
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    400
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    130 2016-06-22  000063.SZA  0.083626         1
    131 2016-06-22  600498.SHA -0.007543         2
    132 2016-06-22  300383.SZA -0.057228         3
    133 2016-06-22  002281.SZA -0.077937         4
    134 2016-06-22  601688.SHA -0.106121         5
    135 2016-06-22  600030.SHA -0.107143         6
    136 2016-06-22  600487.SHA -0.107143         7
    137 2016-06-22  002194.SZA -0.128075         8
    138 2016-06-22  002792.SZA -0.369284         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    34
    *******context.portfolio is*******
    Portfolio({'capital_used': -384448.45638731285, 'starting_cash': 1000000, 'portfolio_value': 1034041.5205909892, 'pnl': 34041.52059098915, 'returns': 0.03404152059098915, 'cash': 615551.5436126872, 'actual_cash': 615551.5436126872, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:6000,today_amount:0,frozen_amount:0,cost_basis:34.188,last_sale_price:35.27000045776367,available_close_amount:6000), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:400,frozen_amount:0,cost_basis:13.555,last_sale_price:13.699999809265137,available_close_amount:15100)}, 'positions_value': 418489.976978302, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 418489.976978302})
    -------------------------------cash_avg  is-------------------------------------
    206808.30411819782
    *******context.portfolio.cash is*******
    615551.5436126872
    *******cash_for_buy is*******
    310212.4561772967
    *******cash_for_sell is*******
    -98530.78331719263
    *******positions is*******
    {'300383.SZA': 211619.97985839844, '000063.SZA': 206869.99711990356}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['000063.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1034041.5205909892
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    206808.30411819785
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    190205.89666598724
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    206869.99711990356
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -61.6930017057166
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    206869.99711990356
    ******* cash is*******
    -61.6930017057166
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    120006.55951130942
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    206808.30411819785
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.940002
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    5000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    139 2016-06-23  600030.SHA  0.017589         1
    140 2016-06-23  600498.SHA -0.005401         2
    141 2016-06-23  600487.SHA -0.033728         3
    142 2016-06-23  000063.SZA -0.042579         4
    143 2016-06-23  002281.SZA -0.064959         5
    144 2016-06-23  300383.SZA -0.106121         6
    145 2016-06-23  601688.SHA -0.109770         7
    146 2016-06-23  002194.SZA -0.130348         8
    147 2016-06-23  002792.SZA -0.190744         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    35
    *******context.portfolio is*******
    Portfolio({'capital_used': -504984.60978916934, 'starting_cash': 1000000, 'portfolio_value': 1037718.4011513824, 'pnl': 37718.401151382364, 'returns': 0.037718401151382364, 'cash': 495015.39021083066, 'actual_cash': 495015.39021083066, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:6000,today_amount:0,frozen_amount:0,cost_basis:34.188,last_sale_price:34.959999084472656,available_close_amount:6000), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:13.930000305175781,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:5000,today_amount:5000,frozen_amount:0,cost_basis:24.1,last_sale_price:24.520000457763672,available_close_amount:5000)}, 'positions_value': 542703.0109405518, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 542703.0109405518})
    -------------------------------cash_avg  is-------------------------------------
    207543.68023027648
    *******context.portfolio.cash is*******
    495015.39021083066
    *******cash_for_buy is*******
    311315.52034541476
    *******cash_for_sell is*******
    23843.810364860576
    *******positions is*******
    {'300383.SZA': 209759.99450683594, '000063.SZA': 210343.0046081543, '600498.SHA': 122600.01182556152}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'300383.SZA': Equity(182 [300383.SZA]), '000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['300383.SZA', '000063.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    300383.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -185916.18414197536
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1037718.4011513824
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    207543.68023027648
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    190882.237364109
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    207543.68023027648
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    15.96
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    11900
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    120433.28298130572
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    122600.01182556152
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    84943.66840471496
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    122600.01182556152
    ******* cash is*******
    84943.66840471496
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    24.520002
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3400
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    148 2016-06-24  600498.SHA  0.474689         1
    149 2016-06-24  002792.SZA  0.353110         2
    150 2016-06-24  000063.SZA  0.345251         3
    151 2016-06-24  600030.SHA  0.282665         4
    152 2016-06-24  600487.SHA  0.279814         5
    153 2016-06-24  601688.SHA  0.047790         6
    154 2016-06-24  002281.SZA -0.099049         7
    155 2016-06-24  300383.SZA -0.134686         8
    156 2016-06-24  002194.SZA -0.243016         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    36
    *******context.portfolio is*******
    Portfolio({'capital_used': -569913.4324072713, 'starting_cash': 1000000, 'portfolio_value': 1022362.57009517, 'pnl': 22362.570095170056, 'returns': 0.022362570095170058, 'cash': 430086.56759272865, 'actual_cash': 430086.56759272865, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:13.630000114440918,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8400,today_amount:3400,frozen_amount:0,cost_basis:24.23,last_sale_price:23.780000686645508,available_close_amount:8400), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:11900,today_amount:11900,frozen_amount:0,cost_basis:15.91,last_sale_price:15.6899995803833,available_close_amount:11900)}, 'positions_value': 592276.0025024414, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 592276.0025024414})
    -------------------------------cash_avg  is-------------------------------------
    204472.51401903402
    *******context.portfolio.cash is*******
    430086.56759272865
    *******cash_for_buy is*******
    306708.77102855104
    *******cash_for_sell is*******
    81094.7174548564
    *******positions is*******
    {'000063.SZA': 205813.00172805786, '600498.SHA': 199752.00576782227, '600030.SHA': 186710.99500656128}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '600030.SHA': Equity(9 [600030.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600030.SHA', '000063.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600030.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -105616.27755170487
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '002792.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1022362.57009517
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    204472.51401903402
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    188057.62195269982
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    199752.00576782227
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    4720.5082512117515
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    199752.00576782227
    ******* cash is*******
    4720.5082512117515
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    23.78
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    118651.1490758512
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    204472.51401903402
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    56.899998
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    2000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    157 2016-06-27  600030.SHA  0.014726         1
    158 2016-06-27  600498.SHA -0.016308         2
    159 2016-06-27  300383.SZA -0.028830         3
    160 2016-06-27  002194.SZA -0.048137         4
    161 2016-06-27  000063.SZA -0.066178         5
    162 2016-06-27  002281.SZA -0.081046         6
    163 2016-06-27  601688.SHA -0.095832         7
    164 2016-06-27  600487.SHA -0.116533         8
    165 2016-06-27  002792.SZA -0.145620         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    37
    *******context.portfolio is*******
    Portfolio({'capital_used': -496005.960757217, 'starting_cash': 1000000, 'portfolio_value': 1043092.0481615452, 'pnl': 43092.048161545186, 'returns': 0.04309204816154519, 'cash': 503994.039242783, 'actual_cash': 503994.039242783, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:14.180000305175781,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8500,today_amount:100,frozen_amount:0,cost_basis:24.221,last_sale_price:24.280000686645508,available_close_amount:8500), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:2000,today_amount:2000,frozen_amount:0,cost_basis:56.57,last_sale_price:59.29999923706055,available_close_amount:2000)}, 'positions_value': 539098.0089187622, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 539098.0089187622})
    -------------------------------cash_avg  is-------------------------------------
    208618.40963230905
    *******context.portfolio.cash is*******
    503994.039242783
    *******cash_for_buy is*******
    312927.61444846354
    *******cash_for_sell is*******
    17551.984837989614
    *******positions is*******
    {'000063.SZA': 214118.0046081543, '600498.SHA': 206380.00583648682, '002792.SZA': 118599.9984741211}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '002792.SZA': Equity(95 [002792.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002792.SZA', '000063.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002792.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -101048.01363613148
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1043092.0481615452
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    208618.40963230905
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    191870.68833786712
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    208618.40963230905
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    15.940001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    12000
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    121056.9261105964
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    206380.00583648682
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2238.4037958222325
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    206380.00583648682
    ******* cash is*******
    2238.4037958222325
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    24.28
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    166 2016-06-28  600498.SHA -0.019339         1
    167 2016-06-28  300383.SZA -0.060247         2
    168 2016-06-28  000063.SZA -0.080116         3
    169 2016-06-28  002281.SZA -0.094984         4
    170 2016-06-28  600030.SHA -0.105358         5
    171 2016-06-28  601688.SHA -0.118318         6
    172 2016-06-28  600487.SHA -0.130470         7
    173 2016-06-28  002792.SZA -0.145620         8
    174 2016-06-28  002194.SZA -0.242965         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    38
    *******context.portfolio is*******
    Portfolio({'capital_used': -562223.5138345982, 'starting_cash': 1000000, 'portfolio_value': 1058303.476674435, 'pnl': 58303.47667443496, 'returns': 0.05830347667443496, 'cash': 437776.48616540176, 'actual_cash': 437776.48616540176, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:14.420000076293945,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8500,today_amount:0,frozen_amount:0,cost_basis:24.221,last_sale_price:24.530000686645508,available_close_amount:8500), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12000,today_amount:12000,frozen_amount:0,cost_basis:15.8,last_sale_price:16.190000534057617,available_close_amount:12000)}, 'positions_value': 620526.9905090332, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 620526.9905090332})
    -------------------------------cash_avg  is-------------------------------------
    211660.695334887
    *******context.portfolio.cash is*******
    437776.48616540176
    *******cash_for_buy is*******
    317491.04300233047
    *******cash_for_sell is*******
    91375.2521718157
    *******positions is*******
    {'000063.SZA': 217742.00115203857, '600498.SHA': 208505.00583648682, '600030.SHA': 194279.9835205078}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '600030.SHA': Equity(9 [600030.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600030.SHA', '000063.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600030.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -102904.73134869212
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '300383.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1058303.476674435
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    211660.69533488702
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    194668.74174505635
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    208505.00583648682
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    3155.689498400199
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    208505.00583648682
    ******* cash is*******
    3155.689498400199
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    24.53
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    122822.30125727408
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    211660.69533488702
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    37.489998
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3200
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    175 2016-06-29  600498.SHA -0.001958         1
    176 2016-06-29  600487.SHA -0.066178         2
    177 2016-06-29  002281.SZA -0.085995         3
    178 2016-06-29  600030.SHA -0.091420         4
    179 2016-06-29  601688.SHA -0.091420         5
    180 2016-06-29  002194.SZA -0.101311         6
    181 2016-06-29  000063.SZA -0.122738         7
    182 2016-06-29  300383.SZA -0.130400         8
    183 2016-06-29  002792.SZA -0.208877         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    39
    *******context.portfolio is*******
    Portfolio({'capital_used': -491526.76196328056, 'starting_cash': 1000000, 'portfolio_value': 1055077.2464252387, 'pnl': 55077.24642523867, 'returns': 0.055077246425238674, 'cash': 508473.23803671944, 'actual_cash': 508473.23803671944, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:14.319999694824219,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:100,frozen_amount:0,cost_basis:24.225,last_sale_price:24.540000915527344,available_close_amount:8600), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3200,today_amount:3200,frozen_amount:0,cost_basis:37.65,last_sale_price:37.290000915527344,available_close_amount:3200)}, 'positions_value': 546604.0083885193, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 546604.0083885193})
    -------------------------------cash_avg  is-------------------------------------
    211015.44928504774
    *******context.portfolio.cash is*******
    508473.23803671944
    *******cash_for_buy is*******
    316523.1739275716
    *******cash_for_sell is*******
    19065.385175899923
    *******positions is*******
    {'000063.SZA': 216232.00979232788, '600498.SHA': 211044.00787353516, '300383.SZA': 119327.99072265625}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '300383.SZA': Equity(182 [300383.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['300383.SZA', '000063.SZA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    300383.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -100262.60554675633
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '600487.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1055077.2464252387
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    211015.44928504774
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    194075.29553890348
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    211044.00787353516
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -28.558588487416273
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    211044.00787353516
    ******* cash is*******
    -28.558588487416273
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    122447.87838866812
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    211015.44928504774
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(234 [600487.SHA])
    ******* current_price is*******
    12.69
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    9600
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    184 2016-06-30  002792.SZA  0.370821         1
    185 2016-06-30  600498.SHA  0.107990         2
    186 2016-06-30  002281.SZA  0.086314         3
    187 2016-06-30  600487.SHA  0.029666         4
    188 2016-06-30  000063.SZA  0.021470         5
    189 2016-06-30  300383.SZA -0.043290         6
    190 2016-06-30  600030.SHA -0.084484         7
    191 2016-06-30  601688.SHA -0.118318         8
    192 2016-06-30  002194.SZA -0.163378         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    40
    *******context.portfolio is*******
    Portfolio({'capital_used': -491976.9051700439, 'starting_cash': 1000000, 'portfolio_value': 1054133.1023067627, 'pnl': 54133.10230676271, 'returns': 0.05413310230676271, 'cash': 508023.0948299561, 'actual_cash': 508023.0948299561, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:15100,today_amount:0,frozen_amount:0,cost_basis:13.555,last_sale_price:14.34000015258789,available_close_amount:15100), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:24.225,last_sale_price:24.280000686645508,available_close_amount:8600), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:9600,today_amount:9600,frozen_amount:0,cost_basis:12.66,last_sale_price:12.579999923706055,available_close_amount:9600)}, 'positions_value': 546110.0074768066, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 546110.0074768066})
    -------------------------------cash_avg  is-------------------------------------
    210826.62046135255
    *******context.portfolio.cash is*******
    508023.0948299561
    *******cash_for_buy is*******
    316239.93069202884
    *******cash_for_sell is*******
    19043.456323425256
    *******positions is*******
    {'000063.SZA': 216534.00230407715, '600498.SHA': 208808.00590515137, '600487.SHA': 120767.99926757812}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'000063.SZA': Equity(235 [000063.SZA]), '600498.SHA': Equity(73 [600498.SHA]), '600487.SHA': Equity(234 [600487.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['000063.SZA', '600487.SHA', '600498.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    000063.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -197490.5459806519
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1054133.1023067627
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    210826.62046135255
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    193901.6257441606
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    210826.62046135255
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    59.8
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3200
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    122338.30494786821
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    208808.00590515137
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2018.6145562011807
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    208808.00590515137
    ******* cash is*******
    2018.6145562011807
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    24.28
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    193 2016-07-01  600498.SHA  0.527048         1
    194 2016-07-01  300383.SZA  0.333653         2
    195 2016-07-01  002281.SZA  0.117084         3
    196 2016-07-01  600487.SHA  0.103197         4
    197 2016-07-01  000063.SZA  0.030854         5
    198 2016-07-01  600030.SHA -0.007566         6
    199 2016-07-01  002194.SZA -0.018472         7
    200 2016-07-01  601688.SHA -0.095832         8
    201 2016-07-01  002792.SZA -0.181271         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    41
    *******context.portfolio is*******
    Portfolio({'capital_used': -468612.86249166203, 'starting_cash': 1000000, 'portfolio_value': 1057947.1388816289, 'pnl': 57947.13888162887, 'returns': 0.05794713888162887, 'cash': 531387.137508338, 'actual_cash': 531387.137508338, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8600,today_amount:0,frozen_amount:0,cost_basis:24.225,last_sale_price:24.15999984741211,available_close_amount:8600), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:9600,today_amount:0,frozen_amount:0,cost_basis:12.66,last_sale_price:12.579999923706055,available_close_amount:9600), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3200,today_amount:3200,frozen_amount:0,cost_basis:59.6,last_sale_price:61.880001068115234,available_close_amount:3200)}, 'positions_value': 526560.001373291, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 526560.001373291})
    -------------------------------cash_avg  is-------------------------------------
    211589.42777632579
    *******context.portfolio.cash is*******
    531387.137508338
    *******cash_for_buy is*******
    317384.1416644887
    *******cash_for_sell is*******
    -2413.568067523476
    *******positions is*******
    {'600498.SHA': 207775.99868774414, '600487.SHA': 120767.99926757812, '002792.SZA': 198016.00341796875}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600498.SHA', '300383.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1057947.1388816289
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    211589.42777632579
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    194603.1954898558
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    207775.99868774414
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    3813.4290885816445
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    207775.99868774414
    ******* cash is*******
    3813.4290885816445
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    24.16
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    122780.94617463286
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    211589.42777632579
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    37.08
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3300
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    202 2016-07-04  300383.SZA  0.309930         1
    203 2016-07-04  002281.SZA  0.210056         2
    204 2016-07-04  600498.SHA  0.083626         3
    205 2016-07-04  000063.SZA  0.027751         4
    206 2016-07-04  600030.SHA -0.019339         5
    207 2016-07-04  600487.SHA -0.064176         6
    208 2016-07-04  002194.SZA -0.086822         7
    209 2016-07-04  002792.SZA -0.163378         8
    210 2016-07-04  601688.SHA -0.242965         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    42
    *******context.portfolio is*******
    Portfolio({'capital_used': -593225.5019455894, 'starting_cash': 1000000, 'portfolio_value': 1071841.4921492592, 'pnl': 71841.4921492592, 'returns': 0.0718414921492592, 'cash': 406774.49805441056, 'actual_cash': 406774.49805441056, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8700,today_amount:100,frozen_amount:0,cost_basis:24.223,last_sale_price:24.59000015258789,available_close_amount:8700), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:9600,today_amount:0,frozen_amount:0,cost_basis:12.66,last_sale_price:12.9399995803833,available_close_amount:9600), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3200,today_amount:0,frozen_amount:0,cost_basis:59.6,last_sale_price:63.900001525878906,available_close_amount:3200), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3300,today_amount:3300,frozen_amount:0,cost_basis:37.02,last_sale_price:37.099998474121094,available_close_amount:3300)}, 'positions_value': 665066.9940948486, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 665066.9940948486})
    -------------------------------cash_avg  is-------------------------------------
    214368.29842985183
    *******context.portfolio.cash is*******
    406774.49805441056
    *******cash_for_buy is*******
    321552.4476447777
    *******cash_for_sell is*******
    129146.24802021898
    *******positions is*******
    {'600498.SHA': 213933.00132751465, '600487.SHA': 124224.00512695312, '002792.SZA': 204479.99267578125, '300383.SZA': 122429.99496459961}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '600487.SHA': Equity(234 [600487.SHA]), '002792.SZA': Equity(95 [002792.SZA]), '300383.SZA': Equity(182 [300383.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002792.SZA', '600487.SHA', '600498.SHA', '300383.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002792.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -75333.74465556227
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['300383.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1071841.4921492592
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    214368.29842985186
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    197158.9806002575
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    122429.99496459961
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    91938.30346525225
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    122429.99496459961
    ******* cash is*******
    91938.30346525225
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    37.1
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    2400
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124393.46704452019
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    214368.29842985186
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    64.0
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1900
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    211 2016-07-05  300383.SZA  0.309635         1
    212 2016-07-05  002281.SZA  0.292046         2
    213 2016-07-05  002194.SZA  0.253095         3
    214 2016-07-05  600498.SHA  0.083626         4
    215 2016-07-05  000063.SZA -0.003407         5
    216 2016-07-05  600030.SHA -0.019339         6
    217 2016-07-05  600487.SHA -0.091420         7
    218 2016-07-05  002792.SZA -0.176985         8
    219 2016-07-05  601688.SHA -0.242965         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    43
    *******context.portfolio is*******
    Portfolio({'capital_used': -593170.6932462199, 'starting_cash': 1000000, 'portfolio_value': 1075814.311178829, 'pnl': 75814.31117882906, 'returns': 0.07581431117882906, 'cash': 406829.3067537801, 'actual_cash': 406829.3067537801, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:8700,today_amount:0,frozen_amount:0,cost_basis:24.223,last_sale_price:24.59000015258789,available_close_amount:8700), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:9600,today_amount:0,frozen_amount:0,cost_basis:12.66,last_sale_price:12.9399995803833,available_close_amount:9600), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:5700,today_amount:2400,frozen_amount:0,cost_basis:37.096,last_sale_price:36.95000076293945,available_close_amount:5700), Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:1900,today_amount:1900,frozen_amount:0,cost_basis:63.76,last_sale_price:63.27000045776367,available_close_amount:1900)}, 'positions_value': 668985.0044250488, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 668985.0044250488})
    -------------------------------cash_avg  is-------------------------------------
    215162.86223576582
    *******context.portfolio.cash is*******
    406829.3067537801
    *******cash_for_buy is*******
    322744.29335364874
    *******cash_for_sell is*******
    131077.84883563445
    *******positions is*******
    {'600498.SHA': 213933.00132751465, '600487.SHA': 124224.00512695312, '300383.SZA': 210615.00434875488, '002281.SZA': 120212.99362182617}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600498.SHA': Equity(73 [600498.SHA]), '600487.SHA': Equity(234 [600487.SHA]), '300383.SZA': Equity(182 [300383.SZA]), '002281.SZA': Equity(49 [002281.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['600487.SHA', '600498.SHA', '002281.SZA', '300383.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600487.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    6853.843708681321
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -207079.15761883333
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['300383.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1075814.311178829
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215162.86223576582
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    197889.7574508613
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    210615.00434875488
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    4547.857887010934
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    210615.00434875488
    ******* cash is*******
    4547.857887010934
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    36.95
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124854.5359027874
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    120212.99362182617
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    94949.86861393965
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    120212.99362182617
    ******* cash is*******
    94949.86861393965
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    63.269997
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1500
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    220 2016-07-06  300383.SZA  0.265715         1
    221 2016-07-06  002194.SZA  0.207029         2
    222 2016-07-06  600498.SHA  0.080763         3
    223 2016-07-06  600487.SHA  0.017589         4
    224 2016-07-06  600030.SHA  0.011371         5
    225 2016-07-06  000063.SZA -0.025907         6
    226 2016-07-06  002281.SZA -0.043290         7
    227 2016-07-06  601688.SHA -0.161766         8
    228 2016-07-06  002792.SZA -0.166503         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    44
    *******context.portfolio is*******
    Portfolio({'capital_used': -353895.683947194, 'starting_cash': 1000000, 'portfolio_value': 1080174.2920965073, 'pnl': 80174.29209650727, 'returns': 0.08017429209650727, 'cash': 646104.316052806, 'actual_cash': 646104.316052806, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:5800,today_amount:100,frozen_amount:0,cost_basis:37.092,last_sale_price:36.83000183105469,available_close_amount:5800), Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:1500,frozen_amount:0,cost_basis:63.473,last_sale_price:64.83999633789062,available_close_amount:3400)}, 'positions_value': 434069.9760437012, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 434069.9760437012})
    -------------------------------cash_avg  is-------------------------------------
    216034.85841930145
    *******context.portfolio.cash is*******
    646104.316052806
    *******cash_for_buy is*******
    324052.2876289522
    *******cash_for_sell is*******
    -106017.17000455235
    *******positions is*******
    {'300383.SZA': 213613.98849487305, '002281.SZA': 220455.98754882812}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['300383.SZA', '002194.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1080174.2920965073
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    216034.85841930145
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198691.7504689169
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    213613.98849487305
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2420.869924428407
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    213613.98849487305
    ******* cash is*******
    2420.869924428407
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    36.829998
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125360.53716003524
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    216034.85841930145
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    12.76
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    9800
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    229 2016-07-07  002792.SZA  0.450576         1
    230 2016-07-07  601688.SHA  0.442985         2
    231 2016-07-07  600487.SHA  0.316699         3
    232 2016-07-07  002281.SZA  0.272779         4
    233 2016-07-07  300383.SZA  0.102073         5
    234 2016-07-07  600030.SHA  0.018196         6
    235 2016-07-07  000063.SZA -0.018292         7
    236 2016-07-07  600498.SHA -0.140736         8
    237 2016-07-07  002194.SZA -0.224395         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    45
    *******context.portfolio is*******
    Portfolio({'capital_used': -478000.9108939491, 'starting_cash': 1000000, 'portfolio_value': 1079709.088762728, 'pnl': 79709.08876272803, 'returns': 0.07970908876272803, 'cash': 521999.0891060509, 'actual_cash': 521999.0891060509, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:5800,today_amount:0,frozen_amount:0,cost_basis:37.092,last_sale_price:36.65999984741211,available_close_amount:5800), Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:63.38999938964844,available_close_amount:3400), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:9800,today_amount:9800,frozen_amount:0,cost_basis:12.66,last_sale_price:13.220000267028809,available_close_amount:9800)}, 'positions_value': 557709.9996566772, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 557709.9996566772})
    -------------------------------cash_avg  is-------------------------------------
    215941.8177525456
    *******context.portfolio.cash is*******
    521999.0891060509
    *******cash_for_buy is*******
    323912.72662881843
    *******cash_for_sell is*******
    17855.455275313143
    *******positions is*******
    {'300383.SZA': 212627.99911499023, '002281.SZA': 215525.9979248047, '002194.SZA': 129556.00261688232}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'300383.SZA': Equity(182 [300383.SZA]), '002281.SZA': Equity(49 [002281.SZA]), '002194.SZA': Equity(104 [002194.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002194.SZA', '300383.SZA', '002281.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002194.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -111700.54734156918
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '601688.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1079709.088762728
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215941.8177525456
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198606.17903346536
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    215941.8177525456
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    63.57
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125306.54759535304
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    215941.8177525456
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    19.9
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    6200
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    238 2016-07-08  002281.SZA  0.265715         1
    239 2016-07-08  601688.SHA  0.222933         2
    240 2016-07-08  600498.SHA  0.103661         3
    241 2016-07-08  600487.SHA  0.080852         4
    242 2016-07-08  000063.SZA  0.062856         5
    243 2016-07-08  600030.SHA -0.024820         6
    244 2016-07-08  002792.SZA -0.064445         7
    245 2016-07-08  300383.SZA -0.161766         8
    246 2016-07-08  002194.SZA -0.190744         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    46
    *******context.portfolio is*******
    Portfolio({'capital_used': -669743.7290839928, 'starting_cash': 1000000, 'portfolio_value': 1094277.2689171059, 'pnl': 94277.26891710586, 'returns': 0.09427726891710586, 'cash': 330256.2709160072, 'actual_cash': 330256.2709160072, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:5800,today_amount:0,frozen_amount:0,cost_basis:37.092,last_sale_price:38.79999923706055,available_close_amount:5800), Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:62.97999954223633,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3100,today_amount:3100,frozen_amount:0,cost_basis:63.57,last_sale_price:64.58999633789062,available_close_amount:3100), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:6200,today_amount:6200,frozen_amount:0,cost_basis:19.9,last_sale_price:20.100000381469727,available_close_amount:6200)}, 'positions_value': 764020.9980010986, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 764020.9980010986})
    -------------------------------cash_avg  is-------------------------------------
    218855.45378342117
    *******context.portfolio.cash is*******
    330256.2709160072
    *******cash_for_buy is*******
    328283.18067513173
    *******cash_for_sell is*******
    216882.36354254567
    *******positions is*******
    {'300383.SZA': 225039.99557495117, '002281.SZA': 214132.01141357422, '002792.SZA': 200228.98864746094, '601688.SHA': 124620.0023651123}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'300383.SZA': Equity(182 [300383.SZA]), '002281.SZA': Equity(49 [002281.SZA]), '002792.SZA': Equity(95 [002792.SZA]), '601688.SHA': Equity(273 [601688.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['300383.SZA', '002792.SZA', '601688.SHA', '002281.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    300383.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -8157.632032405498
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002281.SZA', '601688.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1094277.2689171059
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    218855.4537834212
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    201285.9106630728
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    214132.01141357422
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    4723.442369846976
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    214132.01141357422
    ******* cash is*******
    4723.442369846976
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    62.980003
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    126997.2700120589
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    124620.0023651123
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    94235.45141830889
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    124620.0023651123
    ******* cash is*******
    94235.45141830889
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    20.1
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    4600
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    247 2016-07-11  002792.SZA  0.380067         1
    248 2016-07-11  002281.SZA  0.096083         2
    249 2016-07-11  000063.SZA  0.063682         3
    250 2016-07-11  600030.SHA  0.048856         4
    251 2016-07-11  600487.SHA  0.014726         5
    252 2016-07-11  600498.SHA -0.005401         6
    253 2016-07-11  002194.SZA -0.137415         7
    254 2016-07-11  601688.SHA -0.139375         8
    255 2016-07-11  300383.SZA -0.149250         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    47
    *******context.portfolio is*******
    Portfolio({'capital_used': -546111.5348675847, 'starting_cash': 1000000, 'portfolio_value': 1069499.4510790706, 'pnl': 69499.45107907057, 'returns': 0.06949945107907057, 'cash': 453888.4651324153, 'actual_cash': 453888.4651324153, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:62.150001525878906,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3100,today_amount:0,frozen_amount:0,cost_basis:63.57,last_sale_price:60.150001525878906,available_close_amount:3100), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:10800,today_amount:4600,frozen_amount:0,cost_basis:20.028,last_sale_price:20.170000076293945,available_close_amount:10800)}, 'positions_value': 615610.9859466553, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 615610.9859466553})
    -------------------------------cash_avg  is-------------------------------------
    213899.8902158141
    *******context.portfolio.cash is*******
    453888.4651324153
    *******cash_for_buy is*******
    320849.83532372117
    *******cash_for_sell is*******
    80861.26040711999
    *******positions is*******
    {'002281.SZA': 211309.99221801758, '002792.SZA': 186464.9929046631, '601688.SHA': 217836.0008239746}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002281.SZA': Equity(49 [002281.SZA]), '002792.SZA': Equity(95 [002792.SZA]), '601688.SHA': Equity(273 [601688.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['601688.SHA', '002281.SZA', '002792.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    601688.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -136974.74041685462
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1069499.4510790706
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    213899.8902158141
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    196728.17582799925
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    186464.9929046631
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    27434.897311151028
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    186464.9929046631
    ******* cash is*******
    27434.897311151028
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    60.149998
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    400
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124121.65949572189
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    211309.99221801758
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2589.8979977965355
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    211309.99221801758
    ******* cash is*******
    2589.8979977965355
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    62.149998
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    256 2016-07-12  002792.SZA  0.309620         1
    257 2016-07-12  002281.SZA  0.125328         2
    258 2016-07-12  600030.SHA  0.044154         3
    259 2016-07-12  600498.SHA -0.005401         4
    260 2016-07-12  600487.SHA -0.017432         5
    261 2016-07-12  000063.SZA -0.093206         6
    262 2016-07-12  601688.SHA -0.132230         7
    263 2016-07-12  300383.SZA -0.134686         8
    264 2016-07-12  002194.SZA -0.170324         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    48
    *******context.portfolio is*******
    Portfolio({'capital_used': -346202.2037190704, 'starting_cash': 1000000, 'portfolio_value': 1079579.7973948212, 'pnl': 79579.79739482119, 'returns': 0.07957979739482118, 'cash': 653797.7962809296, 'actual_cash': 653797.7962809296, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:62.22999954223633,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3500,today_amount:400,frozen_amount:0,cost_basis:63.162,last_sale_price:61.20000076293945,available_close_amount:3500)}, 'positions_value': 425782.0011138916, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 425782.0011138916})
    -------------------------------cash_avg  is-------------------------------------
    215915.95947896424
    *******context.portfolio.cash is*******
    653797.7962809296
    *******cash_for_buy is*******
    323873.9392184464
    *******cash_for_sell is*******
    -114007.89758351896
    *******positions is*******
    {'002281.SZA': 211581.99844360352, '002792.SZA': 214200.0026702881}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1079579.7973948212
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215915.95947896424
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198582.3966416811
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    214200.0026702881
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    1715.9568086761574
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    214200.0026702881
    ******* cash is*******
    1715.9568086761574
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    61.2
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125291.54257676525
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    211581.99844360352
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    4333.961035360728
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    211581.99844360352
    ******* cash is*******
    4333.961035360728
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    62.23
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    265 2016-07-13  002792.SZA  0.300866         1
    266 2016-07-13  002281.SZA -0.032685         2
    267 2016-07-13  600030.SHA -0.091420         3
    268 2016-07-13  600498.SHA -0.091420         4
    269 2016-07-13  000063.SZA -0.107143         5
    270 2016-07-13  300383.SZA -0.161766         6
    271 2016-07-13  600487.SHA -0.162184         7
    272 2016-07-13  601688.SHA -0.176985         8
    273 2016-07-13  002194.SZA -0.250181         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    49
    *******context.portfolio is*******
    Portfolio({'capital_used': -346202.2037190704, 'starting_cash': 1000000, 'portfolio_value': 1077607.7736216278, 'pnl': 77607.77362162783, 'returns': 0.07760777362162782, 'cash': 653797.7962809296, 'actual_cash': 653797.7962809296, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:62.70000076293945,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3500,today_amount:0,frozen_amount:0,cost_basis:63.162,last_sale_price:60.18000030517578,available_close_amount:3500)}, 'positions_value': 423809.97734069824, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 423809.97734069824})
    -------------------------------cash_avg  is-------------------------------------
    215521.55472432557
    *******context.portfolio.cash is*******
    653797.7962809296
    *******cash_for_buy is*******
    323282.3320864884
    *******cash_for_sell is*******
    -114993.90947011564
    *******positions is*******
    {'002281.SZA': 213179.98962402344, '002792.SZA': 210629.9877166748}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1077607.7736216278
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215521.55472432557
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198219.65438950103
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    210629.9877166748
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    4891.567007650767
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    210629.9877166748
    ******* cash is*******
    4891.567007650767
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    60.179996
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125062.67769698732
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    213179.98962402344
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2341.565100302134
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    213179.98962402344
    ******* cash is*******
    2341.565100302134
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(49 [002281.SZA])
    ******* current_price is*******
    62.699997
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    274 2016-07-14  002792.SZA  0.147442         1
    275 2016-07-14  002281.SZA -0.080116         2
    276 2016-07-14  600030.SHA -0.080387         3
    277 2016-07-14  000063.SZA -0.105358         4
    278 2016-07-14  600487.SHA -0.132256         5
    279 2016-07-14  600498.SHA -0.134882         6
    280 2016-07-14  601688.SHA -0.176985         7
    281 2016-07-14  002194.SZA -0.186923         8
    282 2016-07-14  300383.SZA -0.193479         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    50
    *******context.portfolio is*******
    Portfolio({'capital_used': -346202.2037190704, 'starting_cash': 1000000, 'portfolio_value': 1085463.7825327606, 'pnl': 85463.78253276064, 'returns': 0.08546378253276064, 'cash': 653797.7962809296, 'actual_cash': 653797.7962809296, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:63.939998626708984,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3500,today_amount:0,frozen_amount:0,cost_basis:63.162,last_sale_price:61.220001220703125,available_close_amount:3500)}, 'positions_value': 431665.98625183105, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 431665.98625183105})
    -------------------------------cash_avg  is-------------------------------------
    217092.75650655213
    *******context.portfolio.cash is*******
    653797.7962809296
    *******cash_for_buy is*******
    325639.1347598282
    *******cash_for_sell is*******
    -111065.90501454924
    *******positions is*******
    {'002281.SZA': 217395.99533081055, '002792.SZA': 214269.9909210205}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '002281.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1085463.7825327606
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    217092.75650655213
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    199664.72133256146
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    214269.9909210205
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2822.765585531626
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    214269.9909210205
    ******* cash is*******
    2822.765585531626
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    61.219997
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    0
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125974.41342726671
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    217395.99533081055
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -303.23882425841293
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    217395.99533081055
    ******* cash is*******
    -303.23882425841293
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    283 2016-07-15  600030.SHA  0.119035         1
    284 2016-07-15  000063.SZA  0.024937         2
    285 2016-07-15  002281.SZA -0.019339         3
    286 2016-07-15  002792.SZA -0.047351         4
    287 2016-07-15  300383.SZA -0.066504         5
    288 2016-07-15  601688.SHA -0.073853         6
    289 2016-07-15  600498.SHA -0.095832         7
    290 2016-07-15  600487.SHA -0.134882         8
    291 2016-07-15  002194.SZA -0.192152         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    51
    *******context.portfolio is*******
    Portfolio({'capital_used': -346202.2037190704, 'starting_cash': 1000000, 'portfolio_value': 1087641.7747812958, 'pnl': 87641.7747812958, 'returns': 0.0876417747812958, 'cash': 653797.7962809296, 'actual_cash': 653797.7962809296, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:64.91000366210938,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3500,today_amount:0,frozen_amount:0,cost_basis:63.162,last_sale_price:60.900001525878906,available_close_amount:3500)}, 'positions_value': 433843.9785003662, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 433843.9785003662})
    -------------------------------cash_avg  is-------------------------------------
    217528.35495625917
    *******context.portfolio.cash is*******
    653797.7962809296
    *******cash_for_buy is*******
    326292.53243438876
    *******cash_for_sell is*******
    -109976.90889028166
    *******positions is*******
    {'002281.SZA': 220693.98651123047, '002792.SZA': 213149.99198913574}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '000063.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1087641.7747812958
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    217528.35495625917
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    200065.35028247774
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    217528.35495625917
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.82
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    11800
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    126227.18215191098
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    217528.35495625917
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(235 [000063.SZA])
    ******* current_price is*******
    14.55
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    8600
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    292 2016-07-18  601688.SHA  0.380674         1
    293 2016-07-18  002792.SZA  0.212279         2
    294 2016-07-18  600030.SHA  0.113220         3
    295 2016-07-18  002281.SZA -0.030067         4
    296 2016-07-18  600498.SHA -0.081046         5
    297 2016-07-18  000063.SZA -0.093206         6
    298 2016-07-18  300383.SZA -0.094984         7
    299 2016-07-18  600487.SHA -0.130348         8
    300 2016-07-18  002194.SZA -0.204682         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    52
    *******context.portfolio is*******
    Portfolio({'capital_used': -669349.1107725529, 'starting_cash': 1000000, 'portfolio_value': 1077821.8815064998, 'pnl': 77821.88150649983, 'returns': 0.07782188150649984, 'cash': 330650.8892274471, 'actual_cash': 330650.8892274471, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(49 [002281.SZA]): Position(asset:Equity(49 [002281.SZA]),amount:3400,today_amount:0,frozen_amount:0,cost_basis:63.473,last_sale_price:63.900001525878906,available_close_amount:3400), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3500,today_amount:0,frozen_amount:0,cost_basis:63.162,last_sale_price:58.849998474121094,available_close_amount:3500), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:11800,today_amount:11800,frozen_amount:0,cost_basis:16.7,last_sale_price:16.520000457763672,available_close_amount:11800), Equity(235 [000063.SZA]): Position(asset:Equity(235 [000063.SZA]),amount:8600,today_amount:8600,frozen_amount:0,cost_basis:14.65,last_sale_price:15.0,available_close_amount:8600)}, 'positions_value': 747170.9922790527, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 747170.9922790527})
    -------------------------------cash_avg  is-------------------------------------
    215564.37630129996
    *******context.portfolio.cash is*******
    330650.8892274471
    *******cash_for_buy is*******
    323346.5644519499
    *******cash_for_sell is*******
    208260.05152580276
    *******positions is*******
    {'002281.SZA': 217259.99221801758, '002792.SZA': 205974.99465942383, '600030.SHA': 194936.00540161133, '000063.SZA': 129000.0}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002281.SZA': Equity(49 [002281.SZA]), '002792.SZA': Equity(95 [002792.SZA]), '600030.SHA': Equity(9 [600030.SHA]), '000063.SZA': Equity(235 [000063.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['000063.SZA', '002281.SZA', '600030.SHA', '002792.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    000063.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    79260.05152580276
    *******for instrument in instruments:*******
    *******instrument is*******
    002281.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -137999.94069221482
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['601688.SHA', '002792.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1077821.8815064998
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215564.37630129998
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198259.03828406843
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    215564.37630129998
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    20.019999
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    9900
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125087.52616788143
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    205974.99465942383
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    9589.381641876156
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    205974.99465942383
    ******* cash is*******
    9589.381641876156
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    58.85
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    301 2016-07-19  601688.SHA  0.586734         1
    302 2016-07-19  600030.SHA  0.194486         2
    303 2016-07-19  002792.SZA  0.128567         3
    304 2016-07-19  300383.SZA -0.048137         4
    305 2016-07-19  002281.SZA -0.077576         5
    306 2016-07-19  000063.SZA -0.107143         6
    307 2016-07-19  600498.SHA -0.120059         7
    308 2016-07-19  002194.SZA -0.129568         8
    309 2016-07-19  600487.SHA -0.130400         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    53
    *******context.portfolio is*******
    Portfolio({'capital_used': -534735.8367769582, 'starting_cash': 1000000, 'portfolio_value': 1075954.1519315378, 'pnl': 75954.15193153778, 'returns': 0.07595415193153777, 'cash': 465264.1632230418, 'actual_cash': 465264.1632230418, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:3600,today_amount:100,frozen_amount:0,cost_basis:63.074,last_sale_price:59.400001525878906,available_close_amount:3600), Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:11800,today_amount:0,frozen_amount:0,cost_basis:16.7,last_sale_price:16.600000381469727,available_close_amount:11800), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:9900,today_amount:9900,frozen_amount:0,cost_basis:20.03,last_sale_price:20.299999237060547,available_close_amount:9900)}, 'positions_value': 610689.9887084961, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 610689.9887084961})
    -------------------------------cash_avg  is-------------------------------------
    215190.83038630756
    *******context.portfolio.cash is*******
    465264.1632230418
    *******cash_for_buy is*******
    322786.24557946133
    *******cash_for_sell is*******
    72712.91274272709
    *******positions is*******
    {'002792.SZA': 213839.9917602539, '600030.SHA': 195880.00450134277, '601688.SHA': 200969.9924468994}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'002792.SZA': Equity(95 [002792.SZA]), '600030.SHA': Equity(9 [600030.SHA]), '601688.SHA': Equity(273 [601688.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['002792.SZA', '600030.SHA', '601688.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002792.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -141127.07901752682
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['601688.SHA', '600030.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1075954.1519315378
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    215190.83038630756
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    197915.48034034856
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200969.9924468994
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    14220.837939408142
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200969.9924468994
    ******* cash is*******
    14220.837939408142
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(273 [601688.SHA])
    ******* current_price is*******
    20.3
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    700
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124870.76523911273
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    195880.00450134277
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    19310.825884964783
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    195880.00450134277
    ******* cash is*******
    19310.825884964783
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.6
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1100
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    310 2016-07-20  002194.SZA  0.450576         1
    311 2016-07-20  600498.SHA  0.299110         2
    312 2016-07-20  601688.SHA  0.093608         3
    313 2016-07-20  600030.SHA  0.062850         4
    314 2016-07-20  002792.SZA -0.019741         5
    315 2016-07-20  300383.SZA -0.048137         6
    316 2016-07-20  000063.SZA -0.107143         7
    317 2016-07-20  002281.SZA -0.133538         8
    318 2016-07-20  600487.SHA -0.161875         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    54
    *******context.portfolio is*******
    Portfolio({'capital_used': -353820.1161083525, 'starting_cash': 1000000, 'portfolio_value': 1072651.8761935884, 'pnl': 72651.87619358837, 'returns': 0.07265187619358837, 'cash': 646179.8838916474, 'actual_cash': 646179.8838916474, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:1100,frozen_amount:0,cost_basis:16.691,last_sale_price:16.559999465942383,available_close_amount:12900), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:10600,today_amount:700,frozen_amount:0,cost_basis:20.047,last_sale_price:20.079999923706055,available_close_amount:10600)}, 'positions_value': 426471.9923019409, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 426471.9923019409})
    -------------------------------cash_avg  is-------------------------------------
    214530.37523871768
    *******context.portfolio.cash is*******
    646179.8838916474
    *******cash_for_buy is*******
    321795.56285807653
    *******cash_for_sell is*******
    -109853.94579485324
    *******positions is*******
    {'600030.SHA': 213623.99311065674, '601688.SHA': 212847.99919128418}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1072651.8761935884
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    214530.37523871768
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    197308.04601081024
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    214530.37523871768
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    14.38
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    13700
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124487.51684726626
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    214530.37523871768
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    26.300001
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    4700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    319 2016-07-21  002194.SZA  0.437616         1
    320 2016-07-21  002792.SZA  0.108309         2
    321 2016-07-21  600030.SHA  0.029141         3
    322 2016-07-21  300383.SZA  0.007130         4
    323 2016-07-21  601688.SHA -0.027964         5
    324 2016-07-21  000063.SZA -0.044381         6
    325 2016-07-21  600498.SHA -0.047351         7
    326 2016-07-21  002281.SZA -0.187520         8
    327 2016-07-21  600487.SHA -0.229760         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    55
    *******context.portfolio is*******
    Portfolio({'capital_used': -674399.5261363916, 'starting_cash': 1000000, 'portfolio_value': 1082047.4571056433, 'pnl': 82047.45710564335, 'returns': 0.08204745710564335, 'cash': 325600.47386360844, 'actual_cash': 325600.47386360844, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.700000762939453,available_close_amount:12900), Equity(273 [601688.SHA]): Position(asset:Equity(273 [601688.SHA]),amount:10600,today_amount:0,frozen_amount:0,cost_basis:20.047,last_sale_price:20.479999542236328,available_close_amount:10600), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:13700,today_amount:13700,frozen_amount:0,cost_basis:14.36,last_sale_price:14.4399995803833,available_close_amount:13700), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:4700,today_amount:4700,frozen_amount:0,cost_basis:26.33,last_sale_price:26.829999923706055,available_close_amount:4700)}, 'positions_value': 756446.9832420349, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 756446.9832420349})
    -------------------------------cash_avg  is-------------------------------------
    216409.49142112868
    *******context.portfolio.cash is*******
    325600.47386360844
    *******cash_for_buy is*******
    324614.23713169305
    *******cash_for_sell is*******
    215423.2546892133
    *******positions is*******
    {'600030.SHA': 215429.98523712158, '601688.SHA': 217087.99514770508, '002194.SZA': 197827.99425125122, '600498.SHA': 126101.00860595703}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '601688.SHA': Equity(273 [601688.SHA]), '002194.SZA': Equity(104 [002194.SZA]), '600498.SHA': Equity(73 [600498.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600498.SHA', '601688.SHA', '600030.SHA', '002194.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    89322.24608325626
    *******for instrument in instruments:*******
    *******instrument is*******
    601688.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -127765.74906444881
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '002792.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1082047.4571056433
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    216409.49142112868
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    199036.30822899842
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    197827.99425125122
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    18581.49716987746
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    197827.99425125122
    ******* cash is*******
    18581.49716987746
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(104 [002194.SZA])
    ******* current_price is*******
    14.44
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1200
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125577.9289026946
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    216409.49142112868
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    57.8
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    2100
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    328 2016-07-22  002194.SZA  0.318734         1
    329 2016-07-22  600498.SHA  0.292046         2
    330 2016-07-22  300383.SZA  0.112953         3
    331 2016-07-22  000063.SZA  0.102018         4
    332 2016-07-22  601688.SHA  0.049400         5
    333 2016-07-22  600030.SHA  0.028247         6
    334 2016-07-22  002792.SZA  0.009957         7
    335 2016-07-22  600487.SHA -0.166503         8
    336 2016-07-22  002281.SZA -0.181367         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    56
    *******context.portfolio is*******
    Portfolio({'capital_used': -475574.40771998087, 'starting_cash': 1000000, 'portfolio_value': 1070943.5678964742, 'pnl': 70943.56789647415, 'returns': 0.07094356789647416, 'cash': 524425.5922800191, 'actual_cash': 524425.5922800191, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.6200008392334,available_close_amount:12900), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:14900,today_amount:1200,frozen_amount:0,cost_basis:14.359,last_sale_price:14.40999984741211,available_close_amount:14900), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:2100,today_amount:2100,frozen_amount:0,cost_basis:57.8,last_sale_price:55.90999984741211,available_close_amount:2100)}, 'positions_value': 546517.9756164551, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 546517.9756164551})
    -------------------------------cash_avg  is-------------------------------------
    214188.71357929482
    *******context.portfolio.cash is*******
    524425.5922800191
    *******cash_for_buy is*******
    321283.0703689422
    *******cash_for_sell is*******
    11046.191668217973
    *******positions is*******
    {'600030.SHA': 214397.98622131348, '002194.SZA': 214708.99772644043, '002792.SZA': 117410.99166870117}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '002194.SZA': Equity(104 [002194.SZA]), '002792.SZA': Equity(95 [002792.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002792.SZA', '600030.SHA', '002194.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002792.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -106364.8000004832
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002194.SZA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1070943.5678964742
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    214188.71357929485
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    196993.81267978414
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    214708.99772644043
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -520.2841471455758
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    214708.99772644043
    ******* cash is*******
    -520.2841471455758
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    124289.25768915804
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    214188.71357929485
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    26.36
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    4700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    337 2016-07-25  600487.SHA  0.668960         1
    338 2016-07-25  300383.SZA  0.292046         2
    339 2016-07-25  601688.SHA  0.292046         3
    340 2016-07-25  002792.SZA  0.284304         4
    341 2016-07-25  002194.SZA  0.234691         5
    342 2016-07-25  600030.SHA  0.057679         6
    343 2016-07-25  600498.SHA  0.038413         7
    344 2016-07-25  000063.SZA -0.019791         8
    345 2016-07-25  002281.SZA -0.212733         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    57
    *******context.portfolio is*******
    Portfolio({'capital_used': -481961.75000611943, 'starting_cash': 1000000, 'portfolio_value': 1063212.2534995873, 'pnl': 63212.2534995873, 'returns': 0.0632122534995873, 'cash': 518038.24999388057, 'actual_cash': 518038.24999388057, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.56999969482422,available_close_amount:12900), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:14900,today_amount:0,frozen_amount:0,cost_basis:14.359,last_sale_price:14.130000114440918,available_close_amount:14900), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:4700,today_amount:4700,frozen_amount:0,cost_basis:26.38,last_sale_price:25.719999313354492,available_close_amount:4700)}, 'positions_value': 545174.0035057068, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 545174.0035057068})
    -------------------------------cash_avg  is-------------------------------------
    212642.45069991745
    *******context.portfolio.cash is*******
    518038.24999388057
    *******cash_for_buy is*******
    318963.67604987614
    *******cash_for_sell is*******
    13567.876755913021
    *******positions is*******
    {'600030.SHA': 213752.99606323242, '002194.SZA': 210537.00170516968, '600498.SHA': 120884.00573730469}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '002194.SZA': Equity(104 [002194.SZA]), '600498.SHA': Equity(73 [600498.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600498.SHA', '600030.SHA', '002194.SZA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -107316.12898139167
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600487.SHA', '300383.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1063212.2534995873
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    212642.45069991748
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    195571.6825641326
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    212642.45069991748
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(234 [600487.SHA])
    ******* current_price is*******
    14.57
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    13400
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    123391.99348574349
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    212642.45069991748
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(182 [300383.SZA])
    ******* current_price is*******
    40.24
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    3000
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    346 2016-07-26  600487.SHA  0.469118         1
    347 2016-07-26  600498.SHA  0.041261         2
    348 2016-07-26  002792.SZA  0.023070         3
    349 2016-07-26  601688.SHA -0.021881         4
    350 2016-07-26  000063.SZA -0.037152         5
    351 2016-07-26  300383.SZA -0.040690         6
    352 2016-07-26  600030.SHA -0.047803         7
    353 2016-07-26  002281.SZA -0.125448         8
    354 2016-07-26  002194.SZA -0.163378         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    58
    *******context.portfolio is*******
    Portfolio({'capital_used': -676525.5396022467, 'starting_cash': 1000000, 'portfolio_value': 1085242.454038653, 'pnl': 85242.45403865306, 'returns': 0.08524245403865306, 'cash': 323474.4603977533, 'actual_cash': 323474.4603977533, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.81999969482422,available_close_amount:12900), Equity(104 [002194.SZA]): Position(asset:Equity(104 [002194.SZA]),amount:14900,today_amount:0,frozen_amount:0,cost_basis:14.359,last_sale_price:14.960000038146973,available_close_amount:14900), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:13400,today_amount:13400,frozen_amount:0,cost_basis:14.7,last_sale_price:14.84000015258789,available_close_amount:13400), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3000,today_amount:3000,frozen_amount:0,cost_basis:40.25,last_sale_price:41.0099983215332,available_close_amount:3000)}, 'positions_value': 761767.9936408997, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 761767.9936408997})
    -------------------------------cash_avg  is-------------------------------------
    217048.49080773062
    *******context.portfolio.cash is*******
    323474.4603977533
    *******cash_for_buy is*******
    323474.4603977533
    *******cash_for_sell is*******
    217048.49080773062
    *******positions is*******
    {'600030.SHA': 216977.99606323242, '002194.SZA': 222904.0005683899, '600487.SHA': 198856.00204467773, '300383.SZA': 123029.99496459961}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '002194.SZA': Equity(104 [002194.SZA]), '600487.SHA': Equity(234 [600487.SHA]), '300383.SZA': Equity(182 [300383.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['002194.SZA', '600030.SHA', '300383.SZA', '600487.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    002194.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -5855.509760659275
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600487.SHA', '600498.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1085242.454038653
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    217048.49080773062
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    198337.45732420386
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    198856.00204467773
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    18192.488763052883
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    198856.00204467773
    ******* cash is*******
    18192.488763052883
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(234 [600487.SHA])
    ******* current_price is*******
    14.84
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1200
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    125137.00307354938
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    217048.49080773062
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(73 [600498.SHA])
    ******* current_price is*******
    26.26
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    4700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    355 2016-07-27  600030.SHA  0.788330         1
    356 2016-07-27  600487.SHA  0.453411         2
    357 2016-07-27  002792.SZA  0.453123         3
    358 2016-07-27  000063.SZA  0.181018         4
    359 2016-07-27  601688.SHA  0.178167         5
    360 2016-07-27  300383.SZA  0.070694         6
    361 2016-07-27  600498.SHA  0.045631         7
    362 2016-07-27  002194.SZA -0.116531         8
    363 2016-07-27  002281.SZA -0.187227         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    59
    *******context.portfolio is*******
    Portfolio({'capital_used': -597867.41692714, 'starting_cash': 1000000, 'portfolio_value': 1065124.5777399132, 'pnl': 65124.57773991325, 'returns': 0.06512457773991324, 'cash': 402132.58307286, 'actual_cash': 402132.58307286, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.649999618530273,available_close_amount:12900), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:14600,today_amount:1200,frozen_amount:0,cost_basis:14.702,last_sale_price:14.449999809265137,available_close_amount:14600), Equity(182 [300383.SZA]): Position(asset:Equity(182 [300383.SZA]),amount:3000,today_amount:0,frozen_amount:0,cost_basis:40.25,last_sale_price:38.79999923706055,available_close_amount:3000), Equity(73 [600498.SHA]): Position(asset:Equity(73 [600498.SHA]),amount:4700,today_amount:4700,frozen_amount:0,cost_basis:26.45,last_sale_price:25.709999084472656,available_close_amount:4700)}, 'positions_value': 662991.9946670532, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 662991.9946670532})
    -------------------------------cash_avg  is-------------------------------------
    213024.91554798264
    *******context.portfolio.cash is*******
    402132.58307286
    *******cash_for_buy is*******
    319537.37332197395
    *******cash_for_sell is*******
    130429.70579709657
    *******positions is*******
    {'600030.SHA': 214784.99507904053, '600487.SHA': 210969.997215271, '300383.SZA': 116399.99771118164, '600498.SHA': 120837.00466156006}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '600487.SHA': Equity(234 [600487.SHA]), '300383.SZA': Equity(182 [300383.SZA]), '600498.SHA': Equity(73 [600498.SHA])}
    ****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]))])))***
    *******instruments is*******
    ['600498.SHA', '300383.SZA', '600487.SHA', '600030.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600498.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    9592.70113553651
    *******for instrument in instruments:*******
    *******instrument is*******
    300383.SZA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -106807.29657564513
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '600487.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1065124.5777399132
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    213024.91554798267
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    195923.4434360166
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    214784.99507904053
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    -1760.0795310578542
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    214784.99507904053
    ******* cash is*******
    -1760.0795310578542
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    123613.92988595732
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    210969.997215271
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2054.918332711677
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    210969.997215271
    ******* cash is*******
    2054.918332711677
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(234 [600487.SHA])
    ******* current_price is*******
    14.45
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    364 2016-07-28  600030.SHA  0.487442         1
    365 2016-07-28  002792.SZA  0.482324         2
    366 2016-07-28  000063.SZA  0.147235         3
    367 2016-07-28  601688.SHA  0.003355         4
    368 2016-07-28  300383.SZA -0.047791         5
    369 2016-07-28  002281.SZA -0.074847         6
    370 2016-07-28  600498.SHA -0.085332         7
    371 2016-07-28  002194.SZA -0.152444         8
    372 2016-07-28  600487.SHA -0.188548         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    60
    *******context.portfolio is*******
    Portfolio({'capital_used': -364092.5957884105, 'starting_cash': 1000000, 'portfolio_value': 1066218.3978830068, 'pnl': 66218.39788300684, 'returns': 0.06621839788300683, 'cash': 635907.4042115895, 'actual_cash': 635907.4042115895, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:12900,today_amount:0,frozen_amount:0,cost_basis:16.691,last_sale_price:16.309999465942383,available_close_amount:12900), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:14700,today_amount:100,frozen_amount:0,cost_basis:14.699,last_sale_price:14.960000038146973,available_close_amount:14700)}, 'positions_value': 430310.99367141724, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 430310.99367141724})
    -------------------------------cash_avg  is-------------------------------------
    213243.67957660137
    *******context.portfolio.cash is*******
    635907.4042115895
    *******cash_for_buy is*******
    319865.51936490205
    *******cash_for_sell is*******
    -102798.20527008607
    *******positions is*******
    {'600030.SHA': 210398.99311065674, '600487.SHA': 219912.0005607605}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '002792.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1066218.3978830068
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    213243.67957660137
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    196124.64526105506
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    210398.99311065674
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    2844.686465944629
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    210398.99311065674
    ******* cash is*******
    2844.686465944629
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.31
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    123740.87410384696
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    213243.67957660137
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    51.89
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    2300
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    373 2016-07-29  600030.SHA  0.487442         1
    374 2016-07-29  002792.SZA  0.414187         2
    375 2016-07-29  000063.SZA  0.178155         3
    376 2016-07-29  300383.SZA -0.017428         4
    377 2016-07-29  600498.SHA -0.027535         5
    378 2016-07-29  601688.SHA -0.039017         6
    379 2016-07-29  002281.SZA -0.074847         7
    380 2016-07-29  600487.SHA -0.129568         8
    381 2016-07-29  002194.SZA -0.229409         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    61
    *******context.portfolio is*******
    Portfolio({'capital_used': -485090.4006342733, 'starting_cash': 1000000, 'portfolio_value': 1062461.6017956887, 'pnl': 62461.60179568874, 'returns': 0.062461601795688736, 'cash': 514909.5993657267, 'actual_cash': 514909.5993657267, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:13000,today_amount:100,frozen_amount:0,cost_basis:16.689,last_sale_price:16.219999313354492,available_close_amount:13000), Equity(234 [600487.SHA]): Position(asset:Equity(234 [600487.SHA]),amount:14700,today_amount:0,frozen_amount:0,cost_basis:14.699,last_sale_price:14.739999771118164,available_close_amount:14700), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:2300,today_amount:2300,frozen_amount:0,cost_basis:51.88,last_sale_price:52.18000030517578,available_close_amount:2300)}, 'positions_value': 547552.0024299622, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 547552.0024299622})
    -------------------------------cash_avg  is-------------------------------------
    212492.32035913775
    *******context.portfolio.cash is*******
    514909.5993657267
    *******cash_for_buy is*******
    318738.48053870664
    *******cash_for_sell is*******
    16321.201532117702
    *******positions is*******
    {'600030.SHA': 210859.9910736084, '600487.SHA': 216678.01065444946, '002792.SZA': 120014.0007019043}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    ****equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}***
    *******equities is*******
    {'600030.SHA': Equity(9 [600030.SHA]), '600487.SHA': Equity(234 [600487.SHA]), '002792.SZA': Equity(95 [002792.SZA])}
    ****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]))])))***
    *******instruments is*******
    ['600487.SHA', '002792.SZA', '600030.SHA']
    ***rank order for sell %s' % instruments***
    *******for instrument in instruments:*******
    *******instrument is*******
    600487.SHA
    ***cash_for_sell -= positions[instrument]***
    *******cash_for_sell is*******
    -200356.80912233176
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['600030.SHA', '002792.SZA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1062461.6017956887
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    212492.32035913775
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    195433.60456863567
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    210859.9910736084
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    1632.3292855293548
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    210859.9910736084
    ******* cash is*******
    1632.3292855293548
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(9 [600030.SHA])
    ******* current_price is*******
    16.22
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    123304.87597007095
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    120014.0007019043
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    92478.31965723346
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    120014.0007019043
    ******* cash is*******
    92478.31965723346
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    52.18
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    1700
    --------------------------------------------------------------------------------
    ------------------ranker_prediction  is-----------------------------------------
              date  instrument     score  position
    382 2016-08-01  002792.SZA  0.639553         1
    383 2016-08-01  600487.SHA  0.399342         2
    384 2016-08-01  002194.SZA  0.282800         3
    385 2016-08-01  000063.SZA  0.170555         4
    386 2016-08-01  600030.SHA  0.168996         5
    387 2016-08-01  002281.SZA  0.098000         6
    388 2016-08-01  601688.SHA  0.056139         7
    389 2016-08-01  600498.SHA -0.025011         8
    390 2016-08-01  300383.SZA -0.130400         9
    1. 资金分配
    ----------context.trading_day_index  is-----------------------------------------
    62
    *******context.portfolio is*******
    Portfolio({'capital_used': -365234.4489540197, 'starting_cash': 1000000, 'portfolio_value': 1046730.5399452113, 'pnl': 46730.53994521126, 'returns': 0.046730539945211265, 'cash': 634765.5510459803, 'actual_cash': 634765.5510459803, 'start_date': Timestamp('2016-05-03 00:00:00+0000', tz='UTC', freq='C'), 'positions': {Equity(9 [600030.SHA]): Position(asset:Equity(9 [600030.SHA]),amount:13100,today_amount:100,frozen_amount:0,cost_basis:16.685,last_sale_price:16.149999618530273,available_close_amount:13100), Equity(95 [002792.SZA]): Position(asset:Equity(95 [002792.SZA]),amount:4000,today_amount:1700,frozen_amount:0,cost_basis:51.974,last_sale_price:50.099998474121094,available_close_amount:4000)}, 'positions_value': 411964.98889923096, 'total_margin': 0.0, 'total_margin_long': 0.0, 'total_margin_short': 0.0, 'positions_exposure': 411964.98889923096})
    -------------------------------cash_avg  is-------------------------------------
    209346.10798904224
    *******context.portfolio.cash is*******
    634765.5510459803
    *******cash_for_buy is*******
    314019.16198356333
    *******cash_for_sell is*******
    -111400.28107337473
    *******positions is*******
    {'600030.SHA': 211564.99500274658, '002792.SZA': 200399.99389648438}
    2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
    3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
    *******context.stock_weights is*******
    [0.6131471927654584, 0.3868528072345415]
    *******buy_instruments is*******
    ['002792.SZA', '600487.SHA']
    ***max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument***
    *******context.portfolio.portfolio_value is*******
    1046730.5399452113
    *******context.max_cash_per_instrument is*******
    0.2
    ******* max_cash_per_instrument is*******
    209346.10798904227
    ******* Number of stock to buy is*******
    0
    ***cash = cash_for_buy * buy_cash_weights[i]***
    192539.9676447836
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    200399.99389648438
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    8946.114092557895
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    True
    ***cash > max_cash_per_instrument - positions.get(instrument, 0):***
    ******* positions.get(instrument, 0) is*******
    200399.99389648438
    ******* cash is*******
    8946.114092557895
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(95 [002792.SZA])
    ******* current_price is*******
    50.1
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    100
    ******* Number of stock to buy is*******
    1
    ***cash = cash_for_buy * buy_cash_weights[i]***
    121479.1943387797
    ******判断是否跳入补仓金额判断******
    ******if cash > max_cash_per_instrument - positions.get(instrument, 0):******
    ******positions.get(instrument, 0)******
    0
    ******max_cash_per_instrument - positions.get(instrument, 0)******
    209346.10798904227
    ******cash > max_cash_per_instrument - positions.get(instrument, 0)******
    False
    ***current_price = data.current(context.symbol(instrument), 'price')***
    ******* context.symbol(instrument) is*******
    Equity(234 [600487.SHA])
    ******* current_price is*******
    14.31
    ***amount = math.floor(cash / current_price / 100) * 100***
    ******* amount is*******
    8400
    
    • 收益率4.67%
    • 年化收益率20.04%
    • 基准收益率0.64%
    • 阿尔法0.16
    • 贝塔0.58
    • 夏普比率1.14
    • 胜率0.66
    • 盈亏比1.15
    • 收益波动率14.37%
    • 信息比率0.08
    • 最大回撤4.35%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-886ef9a0ba254f20b0047218d16774fc"}/bigcharts-data-end

    (adhaha111) #2

    您好,我们的策略都是在每日收盘后拿到了当日行情数据才开始更新的。

    为了后面表示,我们设 当日总交易金额 m = 当日交易的各股票的交易金额+手续费
    "capital_used"是账户买卖所消耗的净资产,为:昨日的 capital_used - m
    "cash"为账户现有现金,为:昨日 cash - m
    “pnl”为总的持仓收益,为:各股票当时的价格 * 股数 - 买入时的成本

    我拿这几天计算是正确的,可能会有小数上的差距,这只是精度不同造成的误差


    (BOLO) #3

    首先,很感谢您的回答,我又算了一遍,发现之前对portfolio的这几个变量理解有误,造成我算例里面的5.31~6.3的数值对不上,为了方便其他朋友,我在这里也提醒下吧:1)回测里面我设置了购买股票(buy-fee)的最低手续费为5;2)我误解了cost_basis的意思,以为是开盘价了,其实是持仓成本,但是该成本是没有剔除股票买/卖交易成本的;3)pnl是总的持仓收益,是(last_sale_price - cost_basis)*amout -∑所有买入时的手续费。
    其次,问题来了,就是算例中的6.6日的数值又有差别了,因为6.3日做了卖出,所以卖出的钱应该会在6.6日能用,也就是说,6.6的m应该考虑加上6.3卖出的金额以及减去卖出手续费(0.0013)。而pnl也应该加上6.3日卖出股票的盈利并减去卖出手续费。我不知道我考虑得对不对,但是6.6日的capital_used, pnl, cash 都差个几百块钱。
    请您再帮我看看吧,谢谢!!


    (adhaha111) #4

    您好,我这边6月3日并没有卖出记录


    (BOLO) #5

    多谢点拨,已经找到原因了,我误以为6.3进行了卖出。其实都是转天进行买和卖。
    再次感谢!!!