3 分钟快速生成代码
输入想法,AI 即刻生成可运行代码
在 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
)
23 为股票买入,24 为股票卖出。1101(单股单账号股数下单)、1102(单股单账号金额下单)。5(最新价)、11(指定模型价)。VP:跟量算法PINLINE:跟价算法'09:30:00', '14:30:00')。VP 算法根据市场实时成交量的变化,按照预设的量比比例(limitOverRate)同步进行跟量下单,保持对市场成交量的固定参与度。
#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 算法密切监控盘口价格变动,在指定的价格区间内跟随价格动态进行挂单和撤单,优化成交均价。
#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
)
quickTrade 设为 1(立即触发下单),避免等待下一根 K 线产生。minAmountPerOrder,防止产生大量碎单或频繁低金额委托引发风控警告。init() 函数中使用 ContextInfo.set_account() 绑定资金账号,确保智能算法主推和回报正常接收。