🚀 AI 一键生成 qmt 策略代码
立即体验

QMT 平台如何编写可转债转股溢价率监控与抢筹策略?(附 Python 源码)

qmt | 发布时间: 2026/7/31
以下内容由 EasyQuant 生成。

问题描述

请根据以下 SEO 主题生成完整页面内容:

Title: QMT 可转债转股溢价率监控与自动化抢筹策略

Question: 请帮我写一个基于 QMT 的可转债折溢价实时监控与下单策略

解决方案

QMT 可转债转股溢价率监控与自动化抢筹策略

在量化交易中,可转债折溢价套利或折价抢筹是非常经典的策略。本文将详细介绍如何在 QMT (迅投量化终端) 中使用 Python API 实时监控可转债转股溢价率,并在满足条件时自动触发快速下单。

一、转股溢价率计算公式

  1. 转股价值 (Convertible Value)
    $$\text{转股价值} = \frac{\text{正股最新价}}{\text{转股价}} \times 100$$
  2. 转股溢价率 (Premium Rate)
    $$\text{转股溢价率} = \left( \frac{\text{可转债最新价}}{\text{转股价值}} - 1 \right) \times 100%$$
    当溢价率 $< 0%$ 时,表示转股价值高于转债价格,即处于折价状态,存在套利或抢筹空间。

二、QMT 核心 API 说明

  • ContextInfo.get_full_tick(stock_code):获取转债与正股的最新分笔数据。
  • ContextInfo.get_instrumentdetail(stock_code):获取合约详细信息(用于提取标的特征)。
  • passorder(opType, orderType, accountid, orderCode, prType, price, volume, strategyName, quickTrade, ...):执行买卖下单操作。通过设置 quickTrade=1 实现盘中触发即刻下单。

三、Python 策略源码实现

#encoding:gbk
import pandas as pd

def init(ContextInfo):
    # 1. 策略基础配置
    ContextInfo.accID = '6000000001' # 请替换为实际交易账号
    ContextInfo.set_account(ContextInfo.accID)
    
    # 2. 配置可转债与正股及转股价的映射关系字典
    # 格式: '转债代码': {'stock': '正股代码', 'convert_price': 当前转股价}
    ContextInfo.cb_map = {
        '113050.SH': {'stock': '600519.SH', 'convert_price': 1800.00},
        '128012.SZ': {'stock': '002415.SZ', 'convert_price': 25.50}
    }
    
    # 3. 策略监控阈值:转股溢价率低于 -1.5% 时触发抢筹下单
    ContextInfo.threshold = -1.5
    
    # 4. 下单标志位(防止重复下单)
    ContextInfo.traded_list = []

def handlebar(ContextInfo):
    # 仅在最新 Bar/Tick 驱动时运行
    if not ContextInfo.is_last_bar():
        return

    for cb_code, info in ContextInfo.cb_map.items():
        if cb_code in ContextInfo.traded_list:
            continue
            
        stock_code = info['stock']
        convert_price = info['convert_price']
        
        # 获取转债和正股的最新 Tick
        tick_data = ContextInfo.get_full_tick([cb_code, stock_code])
        if cb_code not in tick_data or stock_code not in tick_data:
            continue
            
        cb_price = tick_data[cb_code]['lastPrice']
        stock_price = tick_data[stock_code]['lastPrice']
        
        if cb_price <= 0 or stock_price <= 0 or convert_price <= 0:
            continue
            
        # 计算转股价值与转股溢价率
        convert_value = (stock_price / convert_price) * 100
        premium_rate = ((cb_price / convert_value) - 1) * 100
        
        print(f"[监控] 转债: {cb_code}, 现价: {cb_price}, 正股价格: {stock_price}, 转股价值: {convert_value:.2f}, 溢价率: {premium_rate:.2f}%")
        
        # 判断是否满足折价抢筹条件
        if premium_rate <= ContextInfo.threshold:
            print(f"[触发信号] 溢价率 {premium_rate:.2f}% 低于阈值 {ContextInfo.threshold}%,执行买入转债!")
            
            # 执行普通股票买入模式(opType=23, orderType=1101, prType=5最新价, quickTrade=1快速交易)
            passorder(23, 1101, ContextInfo.accID, cb_code, 5, 0, 10, 'CB_Arbitrage', 1, cb_code, ContextInfo)
            
            # 记录已交易,避免重复下单
            ContextInfo.traded_list.append(cb_code)

四、策略运行注意事项

  1. 数据准确性:由于可转债转股价格可能因派息、增发、送股等原因发生下修,请确保 convert_price 为最新转股价。
  2. 账户与环境配置:在实盘运行前,务必在 QMT 界面“模型交易”中正确绑定资金账号,并确保该账号开启了转债交易权限。
  3. 滑点与冲击成本:抢筹策略对时效性要求较高,建议设置合适的价格类型(如对手价或最新价超价)以确保快速成交。