import numpy as np
import tushare as ts
import aiohttp
import asyncio
import time
codes = ['787819', '787317', '787317', '600320', '600191', '600191', '600967', '600765', '600238', '603650']
cvs_30 = []
start = time.time()
async def get_index(code):
all_data = ts.get_hist_data(code, start='2020-05-12', end='2020-12-28')
if all_data is None:
cv_30 = 0
# 加入相对应的列表
cvs_30.append(cv_30)
else:
data = all_data['close']
cv_30 = np.std(data.head(30)) / np.mean(data.head(30))
# 加入相对应的列表
cvs_30.append(cv_30 * 1000)
tasks = [asyncio.ensure_future(get_index(code)) for code in codes]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time()
print(end - start)
import numpy as np
import tushare as ts
import asyncio
import time
# import tushare as t1
codes = ['787819', '787317', '787317', '600320', '600191', '600191', '600967', '600765', '600238', '603650']
cvs_30 = []
start = time.time()
async def get_hist_data(code):
all_data = ts.get_hist_data(code, start='2020-05-12', end='2020-12-28')
return all_data
async def cv_append(all_data):
print(all_data)
if all_data is None:
cv_30 = 0
# 加入相对应的列表
cvs_30.append(cv_30)
else:
data = all_data['close']
cv_30 = np.std(data.head(30)) / np.mean(data.head(30))
# 加入相对应的列表
cvs_30.append(cv_30 * 1000)
async def get_index(code):
all_data = await get_hist_data(code)
await cv_append(all_data)
tasks = [asyncio.ensure_future(get_index(code)) for code in codes]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time()
print(end - start)
园豆我怎么给你,我第一次发帖。
@乡村小三: 结贴就好了,不过这豆子都是浮云