返回列表 发布新帖

回测passorder不按指定价格执行

1160 6
发表于 2024-5-13 22:00:12 | 显示全部楼层 阅读模式
按照指定价格13.70下单, 回测报告"[系统]warning: 指定价不在当前周期最低最高价区间[13.89, 13.89], 使用最新价13.89."

这个warning的意思是我指定的价格不合法,然后qmt自己另取了个价格下单成交?

如果我指定的价格不合法,qmt应该直接拒绝执行,并报告错误,而不是悄悄改动价格。这个行为导致交易不可控,可能造成重大损失。

问题如上,请问该如何解决?

评论6

细雨湿流光楼主
发表于 2024-5-13 22:22:39 | 显示全部楼层
回测用的是国金版本的qmt客户端,前几天刚更新,应该是最新版本的。
细雨湿流光楼主
发表于 2024-5-13 22:25:31 | 显示全部楼层
另外有个问题,就是回测模式下get_last_order_id到底有没有用,以及通过get_trade_detail_data获取deal到底行不行?我发现拿到的order_id永远都是-1, 查到的deal永远是空。
迅投kiki
发表于 2024-5-14 10:06:15 | 显示全部楼层
都贴一下代码看看
细雨湿流光楼主
发表于 2024-5-14 18:49:04 | 显示全部楼层
迅投kiki 发表于 2024-5-14 10:06
都贴一下代码看看
  1. #encoding:gbk

  2. import numpy as np
  3. import pandas as pd

  4. import types

  5. import logging


  6. logger = logging.getLogger(__name__)
  7. logging.basicConfig(level=logging.DEBUG)

  8. trade = types.SimpleNamespace(
  9.     account_id=None,
  10.     stock_code=None,
  11. )

  12. def init(ContextInfo):
  13.     trade.account_id = 'test'
  14.     trade.stock_code = f'{ContextInfo.stockcode}.{ContextInfo.market}'

  15.     ContextInfo.start = "2024-04-01 09:30:00"
  16.     ContextInfo.end = "2024-04-10 15:00:00"
  17.     ContextInfo.capital = 1e5


  18. def handlebar(ContextInfo):
  19.     index = ContextInfo.barpos
  20.     timetag = ContextInfo.get_bar_timetag(index)
  21.     logging.info(f'bar: {timetag_to_datetime(timetag, "%Y-%m-%d %H:%M:%S")}')

  22.     # 注意,这里取到的数据未复权
  23.     latest_price = ContextInfo.get_market_data_ex(
  24.         fields=['close'], period='follow', count=1,
  25.         stock_code=[trade.stock_code],
  26.         end_time=timetag_to_datetime(timetag, "%Y%m%d%H%M%S"),
  27.         dividend_type='none',
  28.     )[trade.stock_code].iloc[0, 0]

  29.     logging.info(f'最新股价: {latest_price}')

  30.     balance, cash = list(map(sum, zip(*list(
  31.         (account.m_dBalance, account.m_dAvailable)
  32.         for account in get_trade_detail_data(trade.account_id, 'STOCK', 'ACCOUNT')
  33.     ))))

  34.     logging.info(f'总资产: {balance} 元, 现金: {cash} 元')

  35.     # 持仓数据
  36.     positions = get_trade_detail_data(trade.account_id, 'STOCK', 'POSITION')

  37.     holdings = sum(p.m_nVolume for p in positions)
  38.     free_holdings = sum(p.m_nYesterdayVolume for p in positions)
  39.     logging.info(f'持仓: {holdings} 股, 其中 {free_holdings} 股可卖')

  40.     price = 13.70
  41.     volume = 100

  42.     if holdings < 100:
  43.         passorder(
  44.             23, # opType, 买入股票
  45.             1101, # orderType, 单股、单账号、普通、股/手方式下单
  46.             trade.account_id, # accountID
  47.             trade.stock_code, # orderCode
  48.             11, # prType, 指定价
  49.             price, # price
  50.             volume, # volume
  51.             '', # strategyName
  52.             1, # quickTrade,
  53.             '', # userOrderId
  54.             ContextInfo,
  55.         )

  56.         logging.info(f'发出建仓单, {price} 元 x {volume} 股')
复制代码

测试标的: 国泰君安 601211
开始时间: 2024-04-01 09:30:00
结束时间: 2024-04-10 15:00:00
复权方式:不复权
默认周期:3分钟
其他参数取默认值,对结果没有太大影响。

下面是日志开头的一部分:

  1. 【2024-05-13 22:10:06.773】  start back test mode

  2. 【2024-05-13 22:10:06.914】  INFO:root:bar: 2024-04-01 09:33:00
  3. 【2024-05-13 22:10:06.977】  INFO:root:最新股价: 13.98
  4. 【2024-05-13 22:10:06.978】  INFO:root:总资产: 100000.0 元, 现金: 100000.0 元
  5. 【2024-05-13 22:10:06.978】  INFO:root:持仓: 0 股, 其中 0 股可卖
  6. 【2024-05-13 22:10:06.990】  [系统]WARNING:指定价13.7不在当前周期最低最高价间[13.89,14.03],使用最新价13.98, 代码:601211.SH, 日期时间 : 20240401 09:33:00
  7. 【2024-05-13 22:10:06.990】  INFO:root:发出建仓单, 13.7 元 x 100 股

  8. 【2024-05-13 22:10:07.013】  INFO:root:bar: 2024-04-01 09:36:00
  9. 【2024-05-13 22:10:07.013】  INFO:root:最新股价: 13.95
  10. 【2024-05-13 22:10:07.013】  INFO:root:总资产: 99997.0 元, 现金: 98602.0 元
  11. 【2024-05-13 22:10:07.013】  INFO:root:持仓: 100 股, 其中 0 股可卖

  12. 【2024-05-13 22:10:07.013】  INFO:root:bar: 2024-04-01 09:39:00
  13. 【2024-05-13 22:10:07.016】  INFO:root:最新股价: 13.95
  14. 【2024-05-13 22:10:07.017】  INFO:root:总资产: 99997.0 元, 现金: 98602.0 元
  15. 【2024-05-13 22:10:07.018】  INFO:root:持仓: 100 股, 其中 0 股可卖
复制代码





细雨湿流光楼主
发表于 2024-5-14 18:55:06 | 显示全部楼层
迅投kiki 发表于 2024-5-14 10:06
都贴一下代码看看

客户经理说get_last_order_id和get_trade_data_detail在回测模式下获取不到数据,是"特性",我接受了,这两个接口我就不折腾了。
*******5012
发表于 2024-10-23 15:59:34 | 显示全部楼层
遇到同样问题,请问这个问题解决了吗

回复

您需要登录后才可以回帖 登录 | 立即注册

客服专线

400-080-8112

用思考的速度交易,用真诚的态度合作,我们是认真的!
  • 关注公众号
  • 添加微信客服
Copyright © 2001-2025 迅投QMT社区 版权所有 All Rights Reserved. 蜀ICP备19002686号-2
关灯 快速发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表