执行二次金叉时报错,代码如下:
macd_week = get_macd('000001.XSHE', 200, datetime.datetime.now().date(), '1w')
show_two_low_cross(macd_week)
value = is_second_low_gold_cross(macd_week)
if value:
print('当前金叉是0轴下二次金叉')
else:
print('当前金叉不是0轴下二次金叉')
**********************************************
报错:
KeyError Traceback (most recent call last)
< ipython-input-27-cd49264d5013> in < module>
1 macd_week = get_macd('000001.XSHE', 200, datetime.datetime.now().date(), '1w')
2 show_two_low_cross(macd_week)
----> 3 value = is_second_low_gold_cross(macd_week)
4 if value:
5 print('当前金叉是0轴下二次金叉')
< ipython-input-8-83866b6b5b55> in is_second_low_gold_cross(macd_list)
148 cross_list = []
149 # 判断当前是否发生金叉,并且位置在0轴之下
--> 150 if macdDIFF[-2] < macdDEA[-2] and macdDIFF[-1] > macdDEA[-1] and macdDIFF[-1] < 0:
151 for i in range(4, len(macd)):
152 if macdDIFF[i-1] < macdDEA[i-1] and macdDIFF[i] > macdDEA[i]:
g:\Users\mocool\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
765 key = com._apply_if_callable(key, self)
766 try:
--> 767 result = self.index.get_value(self, key)
768
769 if not is_scalar(result):
g:\Users\mocool\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3116 try:
3117 return self._engine.get_value(s, k,
-> 3118 tz=getattr(series.dtype, 'tz', None))
3119 except KeyError as e1:
3120 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: -2
2020-05-18