昨天开始出现这个错误,有些参数组能正常运行,很多时候运行到最后就报这个错误,麻烦大神帮忙看看
【已完成|运行中|待运行】: [0|0|216]. [0|8|208]. ……………………………………………………[182|8|26]. [182|8|26]. [183|7|26].
KeyError Traceback (most recent call last)
<ipython-input-22-4bc0e22cca0f> in <module>()
6 initial_cash = '10000000',
7 param_names = ['N','R_period', 'HOLD'],
----> 8 param_values = [range(8,20,2),range(45,71,5),range(2,13,2)]
9 )
<ipython-input-20-d81d57d08a84> in get_backtest_data(self, algorithm_id, benchmark_id, file_name, running_max, start_date, end_date, frequency, initial_cash, param_names, param_values)
231 initial_cash=initial_cash,
232 param_names=param_names,
--> 233 param_values=param_values
234 )
235 # 回测结果指标中加入 log 收益率和超额收益率等指标
<ipython-input-20-d81d57d08a84> in run_backtest(self, algorithm_id, running_max, start_date, end_date, frequency, initial_cash, param_names, param_values)
87 for i in range(pointer, pointer+to_run):
88 # 备选的参数排列组合的 df 中第 i 行变成 dict,每个 key 为列名字,value 为 df 中对应的值
---> 89 params = to_run_df.ix[i].to_dict()
90 # 记录策略回测结果的 id,调整参数 extras 使用 params 的内容
91 backtest = create_backtest(algorithm_id = algorithm_id,
/opt/conda/envs/python2/lib/python2.7/site-packages/pandas/core/indexing.pyc in __getitem__(self, key)
68 return self._getitem_tuple(key)
69 else:
---> 70 return self._getitem_axis(key, axis=0)
71
72 def _get_label(self, label, axis=0):
/opt/conda/envs/python2/lib/python2.7/site-packages/pandas/core/indexing.pyc in _getitem_axis(self, key, axis)
927 return self._get_loc(key, axis=axis)
928
--> 929 return self._get_label(key, axis=axis)
930
931 def _getitem_iterable(self, key, axis=0):
/opt/conda/envs/python2/lib/python2.7/site-packages/pandas/core/indexing.pyc in _get_label(self, label, axis)
84 raise IndexingError('no slices here, handle elsewhere')
85
---> 86 return self.obj._xs(label, axis=axis)
87
88 def _get_loc(self, key, axis=0):
/opt/conda/envs/python2/lib/python2.7/site-packages/pandas/core/generic.pyc in xs(self, key, axis, level, copy, drop_level)
1471 drop_level=drop_level)
1472 else:
-> 1473 loc = self.index.get_loc(key)
1474
1475 if isinstance(loc, np.ndarray):
/opt/conda/envs/python2/lib/python2.7/site-packages/pandas/core/index.pyc in get_loc(self, key, method)
1570 """
1571 if method is None:
-> 1572 return self._engine.get_loc(_values_from_object(key))
1573
1574 indexer = self.get_indexer([key], method=method)
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3824)()
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3704)()
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:7224)()
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:7162)()
KeyError: 216
2018-07-20