官方教程地址:https://doc.yutiansut.com/indicators
按照官方教程学下来,遇到问题:
import QUANTAXIS as QA
data = QA.QA_fetch_stock_day_adv(["002410",'002555','000166'],'2020-01-01','2020-8-10')
df=data.data
#data=data.to_hfq() # 批量后复权
data=data.to_qfq() # 批量前复权
ind=data.add_func(QA.QA_indicator_KDJ)
inc = QA.QA_DataStruct_Indicators(ind)
J = inc.get_timerange('2020-01-14', '2020-01-31', '002555')
报错 ValueError('CANNOT FOUND THIS TIME RANGE'),查看源码,发现排序level = ‘code’,所以加一条语句:
ind = ind.sort_index(level='date')
inc = QA.QA_DataStruct_Indicators(ind),
J = inc.get_timerange('2020-01-14', '2020-01-31', '002555')
正常!
J = inc.get_indicator('2020-01-14','002555'),报错,查看源码,发现get_indicator方面参数 indicator_name = None 没处理,遂改动源码为:
def get_indicator(self, time, code, indicator_name=None):
"""
获取某一时间的某一只股票的指标
"""
try:
if indicator_name:
return self.data.loc[(pd.Timestamp(time), code), indicator_name]
else:
return self.data.loc[(pd.Timestamp(time), code), :]
except:
raise ValueError('CANNOT FOUND THIS DATE&CODE')
OK !