""" 发单逻辑部分 """def tqz_synchronization_position_cffex_lock_mode(self, market_vt_symbol, now_price, offset_price, strategy_position_net, real_position_net):"""synchronization position with lock mode(cffex mode)"""vt_orderids = []buy_price = min(now_price + offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_up)sell_price = max(now_price - offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_down)if strategy_position_net >= 0 and real_position_net >= 0:if strategy_position_net > real_position_net:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_net-real_position_net)print(f'开多 {str(lot)} 手', end="  ")vt_orderids = self.buy(vt_symbol=market_vt_symbol, price=buy_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif strategy_position_net < real_position_net:lot = TQZPositionData.tqz_risk_control(lot=real_position_net - strategy_position_net)print(f'平多 {str(lot)} 手', end="  ")vt_orderids = self.sell(vt_symbol=market_vt_symbol, price=sell_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif strategy_position_net is real_position_net:print(f'净仓相等, 不做处理')elif strategy_position_net >= 0 and real_position_net <= 0:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_net-real_position_net)print(f'开多 {str(lot)} 手', end="  ")vt_orderids = self.buy(vt_symbol=market_vt_symbol, price=buy_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif strategy_position_net <= 0 and real_position_net >= 0:lot = TQZPositionData.tqz_risk_control(lot=real_position_net - strategy_position_net)print(f'开空 {str(lot)} 手', end="  ")vt_orderids = self.short(vt_symbol=market_vt_symbol, price=sell_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif strategy_position_net <= 0 and real_position_net <= 0:if abs(strategy_position_net) > abs(real_position_net):lot = TQZPositionData.tqz_risk_control(lot=abs(strategy_position_net)-abs(real_position_net))print(f'开空 {str(lot)} 手', end="  ")vt_orderids = self.short(vt_symbol=market_vt_symbol, price=sell_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif abs(strategy_position_net) < abs(real_position_net):lot = TQZPositionData.tqz_risk_control(lot=abs(real_position_net) - abs(strategy_position_net))print(f'平空 {str(lot)} 手', end="  ")vt_orderids = self.cover(vt_symbol=market_vt_symbol, price=buy_price, volume=lot, lock=True)print(f'vt_orderids: {vt_orderids}')elif strategy_position_net is real_position_net:print(f'净仓相等, 不做处理')return vt_orderidsdef tqz_synchronization_position_min_netting_mode(self, market_vt_symbol, now_price, offset_price, strategy_position_buy, strategy_position_sell, real_position_buy, real_position_sell):"""synchronization position in min netting with double direction(buy direction & sell direction) mode."""net_buy_abs = abs(strategy_position_buy - real_position_buy)net_sell_abs = abs(strategy_position_sell - real_position_sell)buy_vt_orderids = []sell_vt_orderids = []buy_price = min(now_price + offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_up)sell_price = max(now_price - offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_down)interval = " | "print(market_vt_symbol, end="  ")if net_buy_abs >= net_sell_abs:if strategy_position_buy < real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=real_position_buy - strategy_position_buy)print(f'平多 {str(lot)} 手', end="  ")buy_vt_orderids = self.sell(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'sell_result: {buy_vt_orderids}', end=interval)if strategy_position_sell > real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_sell - real_position_sell)print(f'开空 {str(lot)} 手', end="  ")sell_vt_orderids = self.short(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'short_result: {sell_vt_orderids}')else:if strategy_position_buy > real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_buy - real_position_buy)print(f'开多 {str(lot)} 手', end="  ")buy_vt_orderids = self.buy(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'buy_result: {buy_vt_orderids}', end=interval)if strategy_position_sell < real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=real_position_sell - strategy_position_sell)print(f'平空 {str(lot)} 手', end="  ")sell_vt_orderids = self.cover(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'cover_result: {sell_vt_orderids}')return list(set(buy_vt_orderids + sell_vt_orderids))def tqz_synchronization_position_double_direction_mode(self, market_vt_symbol, now_price, offset_price, strategy_position_buy, strategy_position_sell, real_position_buy, real_position_sell):buy_vt_orderids = []sell_vt_orderids = []buy_price = min(now_price + offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_up)sell_price = max(now_price - offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_down)interval = " | "print(market_vt_symbol, end="  ")if strategy_position_buy > real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_buy - real_position_buy)print(f'开多 {str(lot)} 手', end="  ")buy_vt_orderids = self.buy(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'buy_result: {buy_vt_orderids}', end=interval)elif strategy_position_buy < real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=real_position_buy - strategy_position_buy)print(f'平多 {str(lot)} 手', end="  ")buy_vt_orderids = self.sell(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'sell_result: {buy_vt_orderids}', end=interval)elif strategy_position_buy is real_position_buy:print("多单匹配 不处理", end=interval)if strategy_position_sell > real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_sell - real_position_sell)print(f'开空 {str(lot)} 手', end="  ")sell_vt_orderids = self.short(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'short_result: {sell_vt_orderids}')elif strategy_position_sell < real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=real_position_sell - strategy_position_sell)print(f'平空 {str(lot)} 手', end="  ")sell_vt_orderids = self.cover(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'cover_result: {sell_vt_orderids}')elif strategy_position_sell is real_position_sell:print("空单匹配 不处理")return list(set(buy_vt_orderids + sell_vt_orderids))def tqz_synchronization_position_net_mode(self, market_vt_symbol, now_price, offset_price, strategy_position_buy, strategy_position_sell, real_position_buy, real_position_sell):buy_vt_orderids = []sell_vt_orderids = []if strategy_position_buy > strategy_position_sell:strategy_position_buy, strategy_position_sell = strategy_position_buy - strategy_position_sell, 0elif strategy_position_buy < strategy_position_sell:strategy_position_sell, strategy_position_buy = strategy_position_sell - strategy_position_buy, 0elif strategy_position_buy is strategy_position_sell:strategy_position_buy, strategy_position_sell = 0, 0buy_price = min(now_price + offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_up)sell_price = max(now_price - offset_price, self.vt_symbols_limit_prices[market_vt_symbol].limit_down)interval = " | "print(market_vt_symbol, end="  ")if strategy_position_buy > real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_buy - real_position_buy)print(f'开多 {str(lot)} 手', end="  ")buy_vt_orderids = self.buy(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'buy_result: {buy_vt_orderids}', end=interval)elif strategy_position_buy < real_position_buy:lot = TQZPositionData.tqz_risk_control(lot=real_position_buy - strategy_position_buy)print(f'平多 {str(lot)} 手', end="  ")buy_vt_orderids = self.sell(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'sell_result: {buy_vt_orderids}', end=interval)elif strategy_position_buy is real_position_buy:print("多单匹配 不处理", end=interval)if strategy_position_sell > real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=strategy_position_sell - real_position_sell)print(f'开空 {str(lot)} 手', end="  ")sell_vt_orderids = self.short(vt_symbol=market_vt_symbol, price=sell_price, volume=lot)print(f'short_result: {sell_vt_orderids}')elif strategy_position_sell < real_position_sell:lot = TQZPositionData.tqz_risk_control(lot=real_position_sell - strategy_position_sell)print(f'平空 {str(lot)} 手', end="  ")sell_vt_orderids = self.cover(vt_symbol=market_vt_symbol, price=buy_price, volume=lot)print(f'cover_result: {sell_vt_orderids}')elif strategy_position_sell is real_position_sell:print("空单匹配 不处理")return list(set(buy_vt_orderids + sell_vt_orderids))

量化交易之vnpy篇 - 几种同步发单模式(中金所股指锁仓模式、最小单边轧差操作模式、双边同步模式,净头寸模式)相关推荐

  1. 量化交易之数据获取篇

    该篇主要是是用来展示量化交易的效果,不构成任何投资建议,仅供参考 先说说思路 该篇主要是教你怎么去获取数据,包括怎么去选取一支好的基金,怎么去获取基金往期的历史数据 先说说怎么去选取一支好的基金吧 个 ...

  2. python 组合优化 回撤最小_Python进阶量化交易专栏场外篇23-Markowitz实现股票最优组合...

    欢迎大家订阅<教你用 Python 进阶量化交易>专栏!为了能够提供给大家更轻松的学习过程,笔者在专栏内容之外已陆续推出一些手记来辅助同学们学习本专栏内容,目前推出的扩展篇链接如下: 股票 ...

  3. 当深度学习遇上量化交易——公开信息篇

    ©PaperWeekly 原创 · 作者|桑运鑫 单位|上海交通大学硕士生 研究方向|图神经网络在金融领域的应用 本文主要回顾三篇利用文本信息和音频信息进行量化交易的文章. StockNet 论文标题 ...

  4. 当深度学习遇上量化交易——因子挖掘篇

    ©PaperWeekly 原创 · 作者|桑运鑫 学校|上海交通大学博士生 研究方向|图神经网络在金融领域的应用 在深度学习的所有应用场景中,股价预测也无疑是其中一个异常诱人的场景.随着传统线性模型的 ...

  5. pb 调用虹软_Python进阶量化交易专栏场外篇12-股票分笔数据跨周期处理

    欢迎大家订阅<教你用 Python 进阶量化交易>专栏!为了能够提供给大家更轻松的学习过程,笔者在专栏内容之外已陆续推出一些手记来辅助同学们学习本专栏内容,目前推出的扩展篇链接如下: 在专 ...

  6. 【量化交易】94篇论文分析股市预测的深度学习技术

    论文 | Stock Market Prediction via Deep Learning Techniques: A Survey 作者 | Jinan Zou, Qingying Zhao, Y ...

  7. python选股票进阶_Python进阶量化交易专栏场外篇27-股票数据的除权和复权

    欢迎大家订阅<教你用 Python 进阶量化交易>专栏!为了能够提供给大家更轻松的学习过程,笔者在专栏内容之外已陆续推出一些手记来辅助同学们学习本专栏内容,目前推出的扩展篇链接如下: 在行 ...

  8. python gui插件_Python进阶量化交易专栏场外篇17- GUI控件在回测工具上的添加

    欢迎大家订阅<教你用 Python 进阶量化交易>专栏!为了能够提供给大家更轻松的学习过程,笔者在专栏内容之外已陆续推出一些手记来辅助同学们学习本专栏内容,目前推出的扩展篇链接如下: 为了 ...

  9. python做excel数据分析带gui_Python进阶量化交易专栏场外篇25-GUI工具实现excel功能...

    欢迎大家订阅<教你用 Python 进阶量化交易>专栏!为了能够提供给大家更轻松的学习过程,笔者在专栏内容之外已陆续推出一些手记来辅助同学们学习本专栏内容,目前推出的扩展篇链接如下: 为了 ...

最新文章

  1. java 格式匹配,java匹配电话格式的正则表达式
  2. [转载] 中华典故故事(孙刚)——13 马虎
  3. libevent源码深度剖析八
  4. 【离散数学】图的基本概念和结论
  5. python中的列表排序
  6. 中药说明书实体识别抽取top1
  7. 盘古分词工具学习笔记
  8. Robocup 仿真2D 学习笔记(一) ubuntu16.04 搭建 robocup 仿真2D环境
  9. win11注册表打不开解决办法,提示被管理员禁用(亲测)(两种方法)
  10. 设备巡检的痛点和巡检方案
  11. 闰年,闰月对应的天数快速记忆法
  12. ThinkBook 14 G2 ITL 重装系统 笔记
  13. 基于matlab的动态心形图案
  14. 蔡康永的说话之道总结
  15. Oracle GL - 使用标准程序获取/创建CCID
  16. 【系统分析师之路】第七章 系统分析架构篇记忆敲出
  17. 2009奥巴马的秋季开学演讲稿
  18. java windows wifi密码_windows10 通过命令行来查看wifi密码
  19. Matlab:生成日期与时间的序列
  20. 安卓仿微信界面,导航,右上角菜单栏

热门文章

  1. 三种常见mq的优缺点比较
  2. PHP环境提取m3u8,PHP读取转发M3U8的方法 PHP解码转发M3U8
  3. Android,java知识点总结(三)
  4. 电脑PDF阅读器哪个好用?这三个阅读器值得收藏
  5. Win7系统禁用驱动程序强制签名的方法(win7 64加载未签名驱动 免签名)
  6. electron应用通过web页面按钮唤醒
  7. wps中,文字编辑换行后空格变大
  8. 从王者荣耀这款游戏分析unity3d开发游戏需要的资源
  9. 设计模式-责任链模式变体之管道模式
  10. JsonObject null 的神坑