import tushare as ts import datetime def has_five_consecutive_rises(data): close = data['close'] if len(close) < 5 or any(close[-5:] != close.iloc[-1]): return False for i in range(1, 5): if close.iloc[-i-1] >= close.iloc[-i]: return False return True today = datetime.datetime.now().strftime('%Y-%m-%d') three_months_ago = (datetime.datetime.now() - datetime.timedelta(days=90)).strftime('%Y-%m-%d') data = ts.get_hist_data('hs300', start=three_months_ago, end=today) for code in data.index: stock_data = ts.get_hist_data(code, start=three_months_ago, end=today) if has_five_consecutive_rises(stock_data): print(code)用聚宽运行上述代码
时间: 2024-02-22 20:00:24 浏览: 137
上述代码使用了tushare包,需要在聚宽中先安装tushare包并且获取tushare的token。同时,聚宽提供的get_price函数可以获取股票历史价格数据,可以用来替代tushare包中的get_hist_data函数。下面是修改后的代码:
```
import jqdatasdk as jq
import datetime
def has_five_consecutive_rises(data):
close = data['close']
if len(close) < 5 or any(close[-5:] != close.iloc[-1]):
return False
for i in range(1, 5):
if close.iloc[-i-1] >= close.iloc[-i]:
return False
return True
jq.auth('账号', '密码')
today = datetime.datetime.now().strftime('%Y-%m-%d')
three_months_ago = (datetime.datetime.now() - datetime.timedelta(days=90)).strftime('%Y-%m-%d')
data = jq.get_price('000300.XSHG', start_date=three_months_ago, end_date=today)
for code in data.index:
stock_data = jq.get_price(code, start_date=three_months_ago, end_date=today)
if has_five_consecutive_rises(stock_data):
print(code)
```
需要注意的是,聚宽为收费平台,使用聚宽平台需要注册账号并且购买相应的服务。
阅读全文