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

如何在 QMT 中配置 VP 跟量和 PINLINE 跟价智能算法下单?(附 Python 完整代码)

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

问题描述

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

Title: QMT 智能算法交易:VP 跟量与 PINLINE 跟价算法配置教程

Question: 如何在 QMT 中配置 VP 跟量和 PINLINE 跟价智能算法下单?

解决方案

如何在 QMT 中配置 VP 跟量和 PINLINE 跟价智能算法下单?

在 QMT(迅投量化系统)中,为了减少对大盘或单只股票的价格冲击、隐蔽交易意图,投资者通常会采用智能算法交易。QMT 提供了 smart_algo_passorder 函数,支持多种智能算法,包括 VP(Volume Participation,跟量算法)PINLINE(跟价算法)


一、智能算法交易函数 smart_algo_passorder 语法

smart_algo_passorder(
    opType, 
    orderType, 
    accountid, 
    orderCode, 
    prType, 
    modelprice, 
    volume, 
    strageName, 
    quickTrade, 
    userid, 
    smartAlgoType, 
    limitOverRate, 
    minAmountPerOrder, 
    [targetPriceLevel], 
    [startTime], 
    [endTime], 
    ContextInfo
)

关键参数解析:

  1. opType:操作类型,例如 23 为股票买入,24 为股票卖出。
  2. orderType:下单方式,例如 1101(单股单账号股数下单)、1102(单股单账号金额下单)。
  3. prType:选价类型,例如 5(最新价)、11(指定模型价)。
  4. smartAlgoType:智能算法类型字符串:
    • VP:跟量算法
    • PINLINE:跟价算法
  5. limitOverRate:量比上限(0-100),控制算法参与市场成交的比率。
  6. minAmountPerOrder:单笔最小委托金额(元),默认为 0。
  7. startTime / endTime:算法生效与截止时间(格式如 '09:30:00', '14:30:00')。

二、VP(跟量算法)配置与示例

VP 算法原理:

VP 算法根据市场实时成交量的变化,按照预设的量比比例(limitOverRate)同步进行跟量下单,保持对市场成交量的固定参与度。

Python 示例代码:

#coding:gbk

def init(ContextInfo):
    ContextInfo.set_account('600000105')

def handlebar(ContextInfo):
    if ContextInfo.is_last_bar():
        # 账号 600000105 最新价买入 100,000 股平安银行(000001.SZ)
        # 采用 VP 算法,量比控制在 15%,单笔最小金额 5000 元,交易时间 09:30:00 - 14:30:00
        smart_algo_passorder(
            23,                  # opType: 股票买入
            1101,                # orderType: 单股/单账号/股数下单
            '600000105',         # accountid: 资金账号
            '000001.SZ',         # orderCode: 股票代码
            5,                   # prType: 最新价
            -1,                  # modelprice: 忽略
            100000,              # volume: 10万股
            "MyStrategy",        # strageName: 策略名
            1,                   # quickTrade: 立即触发
            "VP_Trade",          # userid: 投资备注
            "VP",                # smartAlgoType: VP跟量算法
            15,                  # limitOverRate: 15%量比
            5000,                # minAmountPerOrder: 5000元
            1,                   # targetPriceLevel: 己方盘口1
            '09:30:00',          # startTime
            '14:30:00',          # endTime
            ContextInfo
        )

三、PINLINE(跟价算法)配置与示例

PINLINE 算法原理:

PINLINE 算法密切监控盘口价格变动,在指定的价格区间内跟随价格动态进行挂单和撤单,优化成交均价。

Python 示例代码:

#coding:gbk

def init(ContextInfo):
    ContextInfo.set_account('600000105')

def handlebar(ContextInfo):
    if ContextInfo.is_last_bar():
        # 账号 600000105 买入 50,000 股浦发银行(600000.SH)
        # 采用 PINLINE 跟价算法,量比上限 20%,最小金额 10000 元
        smart_algo_passorder(
            23,                  # opType: 股票买入
            1101,                # orderType: 股数下单
            '600000105',         # accountid: 资金账号
            '600000.SH',         # orderCode: 股票代码
            5,                   # prType: 最新价
            -1,                  # modelprice
            50000,               # volume: 5万股
            "MyStrategy",        # strageName
            1,                   # quickTrade
            "PINLINE_Trade",     # userid
            "PINLINE",           # smartAlgoType: PINLINE跟价算法
            20,                  # limitOverRate: 20%量比
            10000,               # minAmountPerOrder: 10000元
            1,                   # targetPriceLevel
            '09:30:00',          # startTime
            '15:00:00',          # endTime
            ContextInfo
        )

四、注意事项与最佳实践

  1. 快速交易模式(quickTrade):实盘调用时推荐将 quickTrade 设为 1(立即触发下单),避免等待下一根 K 线产生。
  2. 最小委托金额:建议根据标的股价合理设置 minAmountPerOrder,防止产生大量碎单或频繁低金额委托引发风控警告。
  3. 账户绑定:必须在 init() 函数中使用 ContextInfo.set_account() 绑定资金账号,确保智能算法主推和回报正常接收。