: | : | :期货量化学习 | :期货量化 |
返回列表 发帖

鼎元C++程序化策略超市产品 第010款 “套利半自动交易系统“

鼎元C++程序化策略超市产品 第010款 “套利半自动交易系统“


说明:

1、此套利系统为半自动系统。做一轮后就自动停止了。

2、使用方法:

(1)、先选定两个做套利的品种,以rb2510和hc2510为例。
(2)、做两者的价差,做法是,若是预判后价差会扩大,则买第一腿,卖第二腿。为了成交,我们用对手价委托,所以第一腿我们采用的价格是卖价,第二腿我们采用的价格是买价。所以这时价差 = 第一腿卖价 - 第二腿的买价。若是预判后期价差会缩小,则要做空第一腿,做多第二腿,为了保证成交,我们要用第一腿买价减第二腿的卖价。所以这时价差 = 第一腿的买价减第二腿的卖价。
(3)、开仓情况:先人为判断市场价差,认为若是价差到某一个小的标准价差会进入变大趋势,所以要做多第一腿,做空第二腿;认为若是价差到某一个价位后会转为减小趋势,这时就要做空第一腿,做多第二腿。
(4)、若是做多第一腿,做空第二腿后价差一如预期扩大达到某一个标准,则就要平仓,即卖出第一腿平仓,买入第二腿平仓;若是做空第一腿,做多第二腿后,价差一如判断缩小到某一个值,就要买入第一腿平仓,卖出第二腿平仓。

3、此半自动策略会含有很多的变量参数:
(1)、以第一腿为例,包含第一腿是开仓还是平仓,第一腿是买入还是卖出。【买入开仓,卖出开仓;买入平仓,卖出平仓】
(2)、条件价差方向:做价差扩大还是做价差缩小

论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   1.本站发布源码(包括函数、指标、策略等)均属开放源码,用意在于让使用者学习程序化语法撰写,使用者可以任意修改语法內容并调整参数。仅限用于个人学习使用,请勿转载、滥用,严禁私自连接实盘账户交易
  2.本站发布资讯(包括文章、视频、历史记录、教材、评论、资讯、交易方案等)均系转载自网络主流媒体,内容仅为作者当日个人观点,本网转载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。本网不对该类信息或数据做任何保证。不对您构成任何投资建议,不能依靠信息而取代自身独立判断,不对因使用本篇文章所诉信息或观点等导致的损失承担任何责任。
  3.本站发布资源(包括书籍、杂志、文档、软件等)均从互联网搜索而来,仅供个人免费交流学习,不可用作商业用途,本站不对显示的内容承担任何责任。请在下载后24小时内删除。如果喜欢,请购买正版,谢谢合作!
  4.龙听期货论坛原创文章属本网版权作品,转载须注明来源“龙听期货论坛”,违者本网将保留追究其相关法律责任的权力。本论坛除发布原创文章外,亦致力于优秀财经文章的交流分享,部分文章推送时若未能及时与原作者取得联系并涉及版权问题时,请及时联系删除。联系方式:http://www.qhlt.cn/thread-262-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

核心策略模块,我做了一个注释:
  1. if (bsfx == "0")//做价差扩大时价差是第一腿卖价减第二腿买价
  2.         {
  3.                 jc = mapMd[dyt].AskPrice1 - mapMd[det].BidPrice1;//价差等于第一腿的卖价减第二腿的买价
  4.         }
  5.         else if (bsfx == "1")//做价差缩小时价差是第一腿的买价减第二腿的卖价
  6.         {
  7.                 jc = mapMd[dyt].BidPrice1 - mapMd[det].AskPrice1;//价差等于第一腿的买价减第二腿的卖价
  8.         }
  9.         //条件价差方向是1(做多价差扩大),价差大于条件价差,第一腿的卖一量大于挂单量要求,第二腿的买单量大于挂单量要求,或者:条件价差方向是-1(做空价差缩小),价差小于等于条件价差,第一腿的买一单量大地挂单量要求,第二腿的卖单量大于挂单量【第一腿为买有两种情况:一是做价差扩大的建仓,二是做价差缩小后的平仓】
  10.         if ((tjjcfx == "1" && jc >= tjjc && mapMd[dyt].AskVolume1 > gdl && mapMd[det].BidVolume1 > gdl) || (tjjcfx == "-1" && jc <= tjjc && mapMd[dyt].BidVolume1 > gdl && mapMd[det].AskVolume1 > gdl))
  11.         {
  12.                 if (bsfx == "0") //第一腿是买(做价差扩大)【买有两种,一是做多开仓,二是做空平仓】
  13.                 {
  14.                         if (ocfx == "0") //建仓期(开仓买入)
  15.                         {
  16.                                 dytcj = false; //第一腿没有成交
  17.                                 detcj = false; //第二腿没有成交
  18.                                 map<string, double>::iterator it;
  19.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  20.                                 {
  21.                                         int ss = (int)floor(it->second * sl);
  22.                                         OrderInsert(it->first, dyt, '0', '0', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");//第一腿买单指令
  23.                                         OrderInsert(it->first, det, '1', '0', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");//第二腿卖单指令
  24.                                         yfd = true;
  25.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件买入开仓,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  26.                                         maps[num] = s;
  27.                                         num++;
  28.                                         InsertLog(it->first + "    达到套利价差交易条件买入开仓,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  29.                                 }
  30.                         }
  31.                         else if (ocfx == "1") //平仓期(平仓卖出)
  32.                         {
  33.                                 dytcj = false; //第一腿没有成交
  34.                                 detcj = false;//第二腿没有成交
  35.                                 map<string, double>::iterator it;
  36.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  37.                                 {
  38.                                         int ss = (int)floor(it->second * sl);
  39.                                         OrderInsert(it->first, dyt, '0', '1', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
  40.                                         OrderInsert(it->first, det, '1', '1', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
  41.                                         yfd = true;
  42.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件买入平仓,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  43.                                         maps[num] = s;
  44.                                         num++;
  45.                                         InsertLog(it->first + "    达到套利价差交易条件买入平仓,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  46.                                 }
  47.                         }
  48.                         else if (ocfx == "3")//平今
  49.                         {
  50.                                 dytcj = false;
  51.                                 detcj = false;
  52.                                 map<string, double>::iterator it;
  53.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  54.                                 {
  55.                                         int ss = (int)floor(it->second * sl);
  56.                                         OrderInsert(it->first, dyt, '0', '3', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick, "", "");
  57.                                         OrderInsert(it->first, det, '1', '3', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
  58.                                         yfd = true;
  59.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件买入平今,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  60.                                         maps[num] = s;
  61.                                         num++;
  62.                                         InsertLog(it->first + "    达到套利价差交易条件买入平今,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  63.                                 }
  64.                         }
  65.                         else if (ocfx == "4")//平昨
  66.                         {
  67.                                 dytcj = false;
  68.                                 detcj = false;
  69.                                 map<string, double>::iterator it;
  70.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  71.                                 {
  72.                                         int ss = (int)floor(it->second * sl);
  73.                                         OrderInsert(it->first, dyt, '0', '4', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick, "", "");
  74.                                         OrderInsert(it->first, det, '1', '4', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
  75.                                         yfd = true;
  76.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件买入平昨,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  77.                                         maps[num] = s;
  78.                                         num++;
  79.                                         InsertLog(it->first + "    达到套利价差交易条件买入平昨,第一腿价格    " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  80.                                 }
  81.                         }

  82.                 }
  83.                 else if (bsfx == "1")//第一腿做卖出,有两种情况:一是做价差缩小的建仓,二是价差扩大后的平仓卖单
  84.                 {
  85.                         if (ocfx == "0") //建仓期(开仓卖出)
  86.                         {
  87.                                 dytcj = false;
  88.                                 detcj = false;
  89.                                 map<string, double>::iterator it;
  90.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  91.                                 {
  92.                                         int ss = (int)floor(it->second * sl);
  93.                                         OrderInsert(it->first, dyt, '1', '0', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
  94.                                         OrderInsert(it->first, det, '0', '0', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
  95.                                         yfd = true;
  96.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件卖出开仓,第一腿价格    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);
  97.                                         maps[num] = s;
  98.                                         num++;
  99.                                         InsertLog(it->first + "    达到套利价差交易条件卖出开仓,第一腿价格    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  100.                                 }
  101.                         }
  102.                         else if (ocfx == "1")//平仓期(平仓卖出)
  103.                         {
  104.                                 dytcj = false; detcj = false;
  105.                                 map<string, double>::iterator it;
  106.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  107.                                 {
  108.                                         int ss = (int)floor(it->second * sl);
  109.                                         OrderInsert(it->first, dyt, '1', '1', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
  110.                                         OrderInsert(it->first, det, '0', '1', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
  111.                                         yfd = true;
  112.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件卖出平仓,第一腿价格    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);
  113.                                         maps[num] = s;
  114.                                         num++;
  115.                                         InsertLog(it->first + "    达到套利价差交易条件卖出平仓,第一腿价格    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  116.                                 }
  117.                         }
  118.                         else if (ocfx == "3")//平今
  119.                         {
  120.                                 dytcj = false;
  121.                                 detcj = false;
  122.                                 map<string, double>::iterator it;
  123.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  124.                                 {
  125.                                         int ss = (int)floor(it->second * sl);
  126.                                         OrderInsert(it->first, dyt, '1', '3', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
  127.                                         OrderInsert(it->first, det, '0', '3', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
  128.                                         yfd = true;
  129.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件,第一腿价格卖出平今    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  130.                                         maps[num] = s;
  131.                                         num++;
  132.                                         InsertLog(it->first + "    达到套利价差交易条件,第一腿价格卖出平今    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  133.                                 }
  134.                         }
  135.                         else if (ocfx == "4")//平昨
  136.                         {
  137.                                 dytcj = false;
  138.                                 detcj = false;
  139.                                 map<string, double>::iterator it;
  140.                                 for (it = mapSub.begin(); it != mapSub.end(); it++)
  141.                                 {
  142.                                         int ss = (int)floor(it->second * sl);
  143.                                         OrderInsert(it->first, dyt, '1', '4', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
  144.                                         OrderInsert(it->first, det, '0', '4', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
  145.                                         yfd = true;
  146.                                         string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + "    " + it->first + "    达到套利价差交易条件,第一腿价格卖出平昨    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc);

  147.                                         maps[num] = s;
  148.                                         num++;
  149.                                         InsertLog(it->first + "    达到套利价差交易条件,第一腿价格卖出平昨    " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + "    第二蹆价格    " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + "   对手价差  " + to_string(jc));
  150.                                 }
  151.                         }
  152.                 }
  153.                 if (num != 0)shuchurizhi();
  154.                 tm = 0;
  155.         }
复制代码
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP



通过上图,我们做一个说明:

一、以主合约买或卖分两类,第一类:买

1、做价差扩大时,我们设定的100价差是启动交易时的价差标准,只要后面的价差大于这个值,我们就主合约买开,次合约卖开【图中(1)位置】。

2、做价差缩小时,我们设定的100是收敛后的价差标准,只要后面的价差小于这个值,我们就主合约买平,次合约卖平。【图中(4)位置】。

二、以主合约买或卖卖两类,第二类:卖

1、做价差缩小时,我们设定的100价差是启动交易时的价差标准,只要后面的价差小于这个值,我们就主合约卖开,次合约买开。【图中(3)位置】

2、做价扩大时,我们设定的100是扩大后的价差标准,只要后面的价差大于这个值,我们就主合约卖平,次合约买平。【图中(2)位置】
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

策略参数部分说明:

1、第一腿合约:做价差的主合约。这里我以rb2510为例说明。
2、第二腿合约:做价差的次合约。这里我以hc2510为例说明。
3、第一腿买卖:主合约的操作方向,0为买,1为卖。
4、第一腿开平:主力合约的开平仓,0为开仓,1为平仓,3为平今仓,4为平昨仓。
5、交易数量:交易的合约数量,两个合约数量一定要相等。单位是手。
6、条件价差:我们认为达到标准的价差,是人为判断的。这里要设置一个具体的数值,是主合约减次合约的价差。
7、条件价差方向:1为做价差扩大,-1为做价差缩小。
8、滑点值:为了尽可能立马成交让出的跳,默认是一跳。
9、是否重发:委托后没有成交,要不要撤回重新发委托。0是不重发,1是重发。
10、时间间隔:委托后多少秒判断撤回重发,默认是5秒。
11、挂单量:有价差不一定能成交,所以还要参考相应的价差报价挂单够不够多,我们认为50手的挂单足够,少于这一量就不能交易。
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

鼎元C++量化经典策略【C++策略模板源码汇总】:http://www.qhlt.cn/thread-163908-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

返回列表