vn.py官网
Veighna量化社区 | 你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 3
声望: 0

自己写的策略,在CTA策略模块进行初始化时报错如下,有哪位知道如何解决吗

[tesdf1] 触发异常已停止
Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc
return self._engine.get_loc(key)
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 623, in call_strategy_func
func()
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 129, in on_init
self.load_bar(1)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\template.py", line 306, in load_bar
use_database
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 590, in load_bar
callback(bar)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 173, in on_bar
self.short(bar.close_price, abs(self.df.loc[self.grid2, 'position']))
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1762, in getitem
return self._getitem_tuple(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1272, in _getitem_tuple
return self._getitem_lowerdim(tup)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1389, in _getitem_lowerdim
section = self._getitem_axis(key, axis=i)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1965, in _getitem_axis
return self._get_label(key, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 625, in _get_label
return self.obj._xs(label, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\generic.py", line 3537, in xs
loc = self.index.get_loc(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31

Member
avatar
加入于:
帖子: 106
声望: 8

sikei wrote:

自己写的策略,在CTA策略模块进行初始化时报错如下,有哪位知道如何解决吗

[tesdf1] 触发异常已停止
Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc
return self._engine.get_loc(key)
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 623, in call_strategy_func
func()
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 129, in on_init
self.load_bar(1)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\template.py", line 306, in load_bar
use_database
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 590, in load_bar
callback(bar)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 173, in on_bar
self.short(bar.close_price, abs(self.df.loc[self.grid2, 'position']))
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1762, in getitem
return self._getitem_tuple(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1272, in _getitem_tuple
return self._getitem_lowerdim(tup)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1389, in _getitem_lowerdim
section = self._getitem_axis(key, axis=i)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1965, in _getitem_axis
return self._get_label(key, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 625, in _get_label
return self.obj._xs(label, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\generic.py", line 3537, in xs
loc = self.index.get_loc(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31
你是用示例策略跑回测的时候报错的嘛?还有你pandas的版本是什么?

Member
avatar
加入于:
帖子: 3
声望: 0

有原 wrote:

sikei wrote:

自己写的策略,在CTA策略模块进行初始化时报错如下,有哪位知道如何解决吗

[tesdf1] 触发异常已停止
Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc
return self._engine.get_loc(key)
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 623, in call_strategy_func
func()
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 129, in on_init
self.load_bar(1)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\template.py", line 306, in load_bar
use_database
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\engine.py", line 590, in load_bar
callback(bar)
File "D:\python3.7\lib\site-packages\vnpy_ctastrategy\strategies\gen_signal_strategy.py", line 173, in on_bar
self.short(bar.close_price, abs(self.df.loc[self.grid2, 'position']))
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1762, in getitem
return self._getitem_tuple(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1272, in _getitem_tuple
return self._getitem_lowerdim(tup)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1389, in _getitem_lowerdim
section = self._getitem_axis(key, axis=i)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 1965, in _getitem_axis
return self._get_label(key, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\indexing.py", line 625, in _get_label
return self.obj._xs(label, axis=axis)
File "D:\python3.7\lib\site-packages\pandas\core\generic.py", line 3537, in xs
loc = self.index.get_loc(key)
File "D:\python3.7\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 31
你是用示例策略跑回测的时候报错的嘛?还有你pandas的版本是什么?
谢谢您的回复,我是自己写的策略,在CTA策略模块跑的实盘;示例策略不会出现上述报错
pandas版本是1.0.3

Member
avatar
加入于:
帖子: 3
声望: 0

问题已解决,谢谢

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】