问题
大家常常在问,如何才能实时获取到换手率指标?在投研软件里面,利用两个简便的方法稍加计算就能能解决:
# 内置python
tick = C.get_full_tick([C.stock])[C.stock]
info = C.get_instrument_detail(C.stock)
vol = tick["volume"]
total_volume = info["TotalVolumn"]
turnover_rate = round((vol* 100/total_volume)*100,2)
# 原生python
tick = xtdata.get_full_tick([stock])[stock]
info = xtdata.get_instrument_detail(stock)
vol = tick["volume"]
total_volume = info["TotalVolume"]
turnover_rate = round((vol* 100/total_volume)*100,2)
利用上面代码片段中的 get_full_tick() 和 get_instrument_detail() 给我们的成交量和总股本数据,便能很快的计算出换手率指标。接下来只需要对以上代码进行一点小小的修饰,便能实时获取换手率指标了。
解答
内置Python

# coding:gbk
'''
内置python,实时获取换手率指标
'''
import time
def init(C):
C.stock = '000001.SZ'
return
def handlebar(C):
t = int(time.strftime('%H%M%S', time.localtime()))
tick = C.get_full_tick([C.stock])[C.stock]
info = C.get_instrument_detail(C.stock)
vol = tick["volume"]
total_volume = info["TotalVolumn"]
turnover_rate = round((vol* 100/total_volume)*100,2)
print(f"在{t}, {C.stock}的换手率是{turnover_rate}%")
return
返回结果
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053,000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.SZ的换手率是0.54%
在103053, 000001.Sz的换手率是0.54%
在103053, 000001.Sz的换手率是0.54%
在103053, 000001.Sz的换手率是0.54%
原生Python

'''
原生python,实时获取换手率指标
'''
import time
from xtquant import xtdata
xtdata.connect(port = 58622)
t = int(time.strftime('%H%M%S', time.localtime()))
stock = '000001.SZ'
while 90000 <= t <= 113000:
tick = xtdata.get_full_tick([stock])[stock]
info = xtdata.get_instrument_detail(stock)
vol = tick["volume"]
total_volume = info["TotalVolume"]
turnover_rate = round((vol* 100/total_volume)*100,2)
print(f"在{t},{stock}的换手率是{turnover_rate}%")
time.sleep(1)
t = int(time.strftime('%H%M%S', time.localtime()))
print("中午休盘开始,程序仍在运行中......")
time.sleep(5401)
t = int(time.strftime('%H%M%S', time.localtime()))
print("中午休盘结束!!")
while 130000 <= t <= 150000:
tick = xtdata.get_full_tick([stock])[stock]
info = xtdata.get_instrument_detail(stock)
vol = tick["volume"]
total_volume = info["TotalVolume"]
turnover_rate = round((vol* 100/total_volume)*100,2)
print(f"在{t},{stock}的换手率是{turnover_rate}%")
time.sleep(1)
t = int(time.strftime('%H%M%S', time.localtime()))
返回结果
在103041,000001.SZ的换手率是0.54%
在103042,000001.SZ的换手率是0.54%
在103043,000001.SZ的换手率是0.54%
在103044,000001.SZ的换手率是0.54%
在103045,000001.SZ的换手率是0.54%
在103046,000001.SZ的换手率是0.54%
在103047,000001.SZ的换手率是0.54%
在103048,000001.SZ的换手率是0.54%
在103049,000001.SZ的换手率是0.54%
在103050,000001.SZ的换手率是0.54%
在103051,000001.SZ的换手率是0.54%
在103052,000001.SZ的换手率是0.54%
在103053,000001.SZ的换手率是0.54%
在103054,000001.SZ的换手率是0.54%
在103055,000001.SZ的换手率是0.54%
在103056,000001.SZ的换手率是0.54%
在103057,000001.SZ的换手率是0.54%
在103058,000001.SZ的换手率是0.54%
在103059,000001.SZ的换手率是0.54%
在103100,000001.SZ的换手率是0.54%
在103101,000001.SZ的换手率是0.54%
在103102,000001.SZ的换手率是0.54%
在103103,000001.SZ的换手率是0.54%
在103104,000001.SZ的换手率是0.54%
不清楚的内容可添加下方助理微信咨询,有其他 QMT 小技巧想学习的吗?欢迎在下方留言,笔者将根据大家的留言持续更新哦!
欢迎和我一起加入迅投组建的 QMT 实战交流社群,交流群内有许多做量化交易的高手和大佬,具有良好的分享和互助氛围。且迅投官方会不定期为多次分享、乐于助人的群友申请送投研专业版的机会。
只需扫描下方的二维码,名额有限,限时加入。一起分享见解、交换信息、并共同进步,就像群友说的:“就算周末,晚上也有地方沟通交流!”
