在回测时,我使用ContextInfo.get_sector()去尝试获取中证小市值指数成分股,发现了两个问题。回测设置的起始时间是2025-10-20。
1 获取得到的结果比现在实际的数据多了30条。现在中证小市值(399101.SZ)成分股有961个,ContextInfo.get_sector("399101.SZ")返回了991个。返回结果包含了中航机电(002013.SZ)这种已经退市的股票。
2 ContextInfo.get_sector()接口,按照文档介绍,是可以支持两个参数,形式是ContextInfo.get_sector(stock, realtime),其中realtime是毫秒时间戳。分别尝试了秒级时间戳和毫秒时间戳,只要填了这个参数,返回的都是空数组。
想咨询一下,这个接口是不是有问题?还是我使用的方式不对?
附代码:
def handlebar(ContextInfo):
# 获取中证小市值成分股
stocks = ContextInfo.get_sector("399101.SZ")
print(stocks)
print("=" * 60)
# 获取2025-10-20 11:00:00时刻的中证小市值成分股,毫秒级时间戳
stocks = ContextInfo.get_sector("399101.SZ", 1760929200000)
print(stocks)
print("=" * 60)
# 获取2025-10-20 11:00:00时刻的中证小市值成分股,秒级时间戳
stocks = ContextInfo.get_sector("399101.SZ", 1760929200)
print(stocks)
|