一、调用tushare的ts.pro_bar方法时报错
def fetch_data(start_date, end_date):
'''
调tushare获取所有股票的历史价格
:param start_date: 历史开始日期,str类型,%Y%m%d格式,包含当天
:param end_date: 历史结束日期,str类型,%Y%m%d格式,包含当天
:return:
'''
for symbol in ALL_STOCK_LIST:
df = ts.pro_bar( # 关于pro_bar函数的参数说明参见 https://tushare.pro/document/2?doc_id=109
adj='hfq', # 量化模型一般都使用后复权
ts_code=symbol, start_date=start_date, end_date=end_date)
df = df[['trade_date', 'open', 'high', 'low', 'close', 'vol']] # 只选取所需要的列
df.sort_values(by='trade_date', inplace=True) # 按日期升序排列(默认是按日期降序排)
df.to_csv(os.path.join(OHLCV_DIR, symbol), index=False) # 价格数据写入文件,文件名就是股票代码
error.png
二、可能原因及解决方案:
1.未注册
注册地址: https://tushare.pro/register?reg=564135
2.积分不足
获取积分方法:https://tushare.pro/document/1?doc_id=13