之前运行正常的复盘程序,最近莫名其妙出了问题,每次运行都会报错“TypeError: object of type 'int' has no len()”,经过排查发现是由于get_price函数参数赋值不当引起的。
官方文档中该函数的格式如下:
get_price(security, start_date=None, end_date=None, frequency='1d', fields=None, fq=None, count=None)
其中“start_date”、“end_date”要求以"20220101"格式的string赋值,而我之前一直是直接以int赋值,将int改为string后策略恢复正常。
我猜测是因为PTrade最近升级后修改了这个函数的参数处理逻辑所致,供大家参考。