共11 条记录, 每页显示 10 条, 页签:
[1]
[2]
[浏览完整版]
标题:【高频策略】利用挂单价差实现高频交易的策略
1楼
大侠鸟 发表于:2015/9/24 23:03:22
策略原理:
高频交易的种类很多,比如我们常见的跨期套利,通过一个合约的2个相近的月份2个合约,通过价差波动的相关性进行套利,实现稳定盈利的目的。
本文通过另外一种高频交易模式,即同一个品种的买卖价差来实现盈利。
以IC00为例,我们通过一个简单公式在分笔周期上就能出买一和卖一价差每天都会有大量的价差波动,并且从分析上讲机会很多,例如:
测试公式如下:
挂单价差:BIDPRICE - ASKPRICE;
效果图
此主题相关图片如下:qq截图20150924223702.jpg

通过上面的效果图不难看出,只要我们在点差较大时能同时持有多空双方的2个头寸,就会像套利一样锁定了利润空间,待价差缩小后就可以实现平仓盈利。
利用VBA制作的模型源码如下:
'订阅数据,这里范例订阅IC00合约
Sub APPLICATION_VBAStart()
marketdata.RegReportNotify "IC00", "ZJ"
call application.SetTimer(1,500)
End Sub
BuyOrder = 0
SellOrder = 0
HoldOk = 1
ModeStatus = 0 '0无持仓 1持仓状态
Sub MARKETDATA_ReportNotify(ReportData)
'计算挂单价差
Diff = ReportData.SellPrice1 - ReportData.BuyPrice1
If ModeStatus =0 And HoldOk = 1 Then
if Diff >= 5 Then
'当价差达到5个价位时,触发交易
'application.MsgOut "diff"&diff
HoldOk = 0
ModeStatus = 1
'使用钓鱼方式挂单,比现有价格优惠一个变动价位,然后等待市场客户卖出给你
BuyOrder = Order.Buy(0,1,ReportData.BuyPrice1+0.2,0,"IC00","ZJ","",0)
SellOrder = Order.BuyShort(0,1,ReportData.SellPrice1-0.2,0,"IC00","ZJ","",0)
End If
End If
If ModeStatus = 1 And HoldOk = 1 Then
If Diff <= 0.4 Then
'当价差缩回去时,市价平掉仓位
'application.MsgOut "diff2"&diff
HoldOk = 0
ModeStatus = 0
BuyOrder = Order.Sell(1,1,0,0,"IC00","ZJ","",0)
SellOrder = Order.SellShort(1,1,0,0,"IC00","ZJ","",0)
End If
End If
End Sub
'收到成交回报后对标志位进行处理
Sub ORDER_OrderStatusEx2(OrderID, Status, Filled, Remaining, Price, Code, Market, OrderType, Aspect, Kaiping, Account, AccountType)
OkThis = 0
If Status = "Tradeing" Then
If OrderID = BuyOrder Then
OkThis = 1
BuyOrder = 0
End If
If OrderID = SellOrder Then
OkThis = 1
SellOrder = 0
End If
If BuyOrder = 0 And SellOrder = 0 And OkThis = 1 Then
HoldOk = 1
End If
End If
'下面的是不成交的追单处理模式
if status="Cancelled" and remaining>0 and Holdok=0 then
if aspect=0 then
if kaiping=0 then
BuyOrder = order.Buy(1,remaining,0,0,Code,market,Account,0)
else
SellOrder = order.sellshort(1,remaining,0,0,code,market,Account,0)
end if
end if
if aspect=1 then
if kaiping=0 then
SellOrder = order.Buyshort(1,remaining,0,0,code,market,Account,0)
else
BuyOrder = order.sell(1,remaining,0,0,code,market,Account,0)
end if
end if
end if
End Sub
'定时器,用于处理挂单的不成交追单,这里不考虑价格是否合适,使用时还请用户自己更改算法
sub application_timer(id)
IF ID =1 THEN
for i=0 to order.OrderNum2-1
call order.OrderInfo2(i, OrderID, ConSign, Filled, Remaining, Action, OrderType, LmtPrice, Account, Kaiping, Code, Market)
OrdTime=right(Order.OrderInfoTime2(i),8)
aa=Datediff("s",OrdTime,Cdate(time))
'application.MsgOut "ordtime="&aa
'application.MsgOut "cdsj="&cdsj
if aa-2>=0 then
'超过间隔指定的秒数,
Call Order.CancelOrder(OrderID,account)
end if
next
end if
END SUB
该高频的模型目前还仅在雏形阶段,需要解决如下几个问题:
1,测试时是根据中金所IC品种的常规手续费进行的,如今平今手续费奇高,所以对IC品种已经不适合,用户需要找其他交易所的合适品种,适合该高频模式的品种需要比较大的合约价格,因为只有合约比较大了后才会出现较大挂单价差,另外一个就是该合约的交易量即不是很大也不是很小,很大的交易量势必导致套利空间缩小,较小的流通性又会导致频繁的开仓单腿问题存在。
2,由于是钓鱼方式开仓挂单,容易出现单腿情况,因此范例代码未考虑如何去解决单腿问题及单腿后的更多问题,本文仅起到抛砖引玉的作用,需要用户自行去完善了
2楼
陈伟明 发表于:2015/11/10 22:03:54
3楼
风度翩翩 发表于:2015/12/24 17:40:40
4楼
zyglys 发表于:2016/10/8 16:36:01
5楼
量化资产 发表于:2018/9/26 9:10:57
用在锌上试试
diff:=5;手数:=1;多持:=tbuyholding(1);空持:=tsellholding(1);
持价:=TAVGENTERPRICE;
挂单价差:(ASKPRICE-BIDPRICE)/diff,NOAXIS;
DEBUGFILE('C:\TEST.TXT','挂单价差 %.0f', 挂单价差);DEBUGOUT('挂单价差 %.0f', 挂单价差);
//开平仓条件
开仓条件:=挂单价差>=5;平仓条件:=挂单价差<=2;
//开仓挂单
if 多持=0 and 空持=0 then begin
tcancel(开仓条件=0 and tisremain(1)>0 ,1); //不满足条件就撤单
tcancel(开仓条件=0 and tisremain(3)>0 ,3);
tbuy (开仓条件 and tisremain(1)=0,手数,lmt,BIDPRICE+diff,0);
tbuyshort(开仓条件 and tisremain(3)=0,手数,lmt,ASKPRICE-diff,0);
end
//平仓挂单
if 多持>0 and 空持>0 then begin
tcancel(平仓条件=0 and tisremain(2)>0 ,2); //不满足条件就撤单
tcancel(平仓条件=0 and tisremain(4)>0 ,4);
tsell (平仓条件 and tisremain(2)=0,多持,lmt,ASKPRICE,0);
tsellshort(平仓条件 and tisremain(4)=0,空持,lmt,BIDPRICE,0);
end
//单腿处理
if 多持=0 and 空持>0 then begin
买单挂条件 :=BIDPRICE<=持价-3*diff;卖单止损条件:=ASKPRICE>=持价+3*diff and not(买单挂条件);
tcancel (卖单止损条件 or TSUBMIT(1)>60,1); //满足卖单止损条件,就撤开多单
tcancel (卖单止损条件=0 or TSUBMIT(4)>60,4); //不满足卖单止损条件或者平空单60秒未成交,就撤平空单
tbuy (卖单止损条件=0 and tisremain(4)=0 and tisremain(1)=0,手数,lmt,BIDPRICE+diff,0);
tsellshort(卖单止损条件 and tisremain(4)=0 and tisremain(1)=0,空持,lmt,BIDPRICE+diff,0);//满足卖单止损条件,就平空单,追单
end
if 多持>0 and 空持=0 then begin
卖单挂条件 :=ASKPRICE>=持价+3*diff;买单止损条件:=BIDPRICE<=持价-3*diff and not(卖单挂条件);
tcancel (买单止损条件 or TSUBMIT(1)>60,3);
tcancel (买单止损条件=0 or TSUBMIT(1)>60,2);
tbuyshort (买单止损条件=0 and tisremain(3)=0 and tisremain(2)=0,手数,lmt,ASKPRICE-diff,0);
tsell (买单止损条件 and tisremain(3)=0 and tisremain(2)=0,多持,lmt,ASKPRICE-diff,0);
end
6楼
量化资产 发表于:2018/9/26 14:48:02
如果双边可以顺利成交的话,把后成交的一边直接改为平仓,即可盈利!
7楼
量化资产 发表于:2018/9/26 15:33:39
diff:=5;手数:=1;
多持:=tbuyholdingex('623637' ,'',2 );空持:=tsellholdingex('623637' ,'',2 );
DEBUGFILE('C:\TEST.TXT','多持 %.0f', 多持);DEBUGOUT('多持 %.0f', 多持);
DEBUGFILE('C:\TEST.TXT','空持 %.0f', 空持);DEBUGOUT('空持 %.0f', 空持);
持价:=TAVGENTERPRICE;挂单价差:(ASKPRICE-BIDPRICE)/diff,NOAXIS;
DEBUGFILE('C:\TEST.TXT','挂单价差 %.0f', 挂单价差);DEBUGOUT('挂单价差 %.0f', 挂单价差);
//开仓
开仓条件:=挂单价差>=5;
if 多持=0 and 空持=0 then begin
tbuy (开仓条件 and tisremain(1)=0,手数,lmt,BIDPRICE+diff,0);
tbuyshort(开仓条件 and tisremain(3)=0,手数,lmt,ASKPRICE-diff,0);
end
//平仓
if 多持=0 and 空持>0 then begin
tcancel (1,1); //撤开多单
//钓鱼挂止盈单//3跳利润
tsellshort(tisremain(4)=0,手数,lmt,持价-3*diff,0);
//即时成交
即时成交止盈条件:=ASKPRICE<持价;//即时成交止盈单//1跳利润
即时成交止损条件:=ASKPRICE>=持价+5*diff;//即时成交止损单//5跳止损
if 即时成交止盈条件 or 即时成交止损条件 then begin
tcancel (1,4); //撤钓鱼单
tsellshort(tisremain(4)=0,手数,lmt,ASKPRICE,0);
end
END
if 多持>0 and 空持=0 then begin
tcancel (1,3);//撤开空单
tsell (tisremain(2)=0,手数,lmt,持价+3*diff,0);
即时成交止盈条件:=BIDPRICE>持价;
即时成交止损条件:=BIDPRICE<=持价-5*diff;
if 即时成交止盈条件 or 即时成交止损条件 then begin
tcancel (1,2);
tsell (tisremain(2)=0,手数,lmt,BIDPRICE,0);
end
END
8楼
量化资产 发表于:2018/9/26 23:12:57
后台 固定1秒轮询。
diff:=5;手数:=1;
多持:=tbuyholdingex('623637' ,'',2 );空持:=tsellholdingex('623637' ,'',2 );
DEBUGFILE('C:\TEST.TXT','多持 %.0f', 多持);DEBUGOUT('多持 %.0f', 多持);
DEBUGFILE('C:\TEST.TXT','空持 %.0f', 空持);DEBUGOUT('空持 %.0f', 空持);
持价:=TAVGENTERPRICE;挂单价差:(ASKPRICE-BIDPRICE)/diff,NOAXIS;
DEBUGFILE('C:\TEST.TXT','挂单价差 %.0f', 挂单价差);DEBUGOUT('挂单价差 %.0f', 挂单价差);
//开仓
开仓条件:=挂单价差>=5;
if 多持=0 and 空持=0 then begin
tbuy (开仓条件 and tisremain(1)=0,手数,lmt,BIDPRICE+diff,0);
tbuyshort(开仓条件 and tisremain(3)=0,手数,lmt,ASKPRICE-diff,0);
end
//平仓
if 多持=0 and 空持>0 then begin
tcancel (1,1); //撤开多单
//即时成交
即时成交止盈条件:=ASKPRICE<持价;//即时成交止盈单//1跳利润
即时成交止损条件:=ASKPRICE>=持价+5*diff;//即时成交止损单//5跳止损
if 即时成交止盈条件 or 即时成交止损条件 then begin
tcancel (1,4); //撤钓鱼单//撤单后,到下一个TICK才能发出平仓单,因为撤单回报需要时间。
tsellshort(tisremain(4)=0,手数,lmt,ASKPRICE,0);
end
//钓鱼挂止盈单//3跳利润
tsellshort(tisremain(4)=0,手数,lmt,持价-3*diff,0);
END
if 多持>0 and 空持=0 then begin
tcancel (1,3);//撤开空单
即时成交止盈条件:=BIDPRICE>持价;
即时成交止损条件:=BIDPRICE<=持价-5*diff;
if 即时成交止盈条件 or 即时成交止损条件 then begin
tcancel (1,2);
tsell (tisremain(2)=0,手数,lmt,BIDPRICE,0);
end
tsell (tisremain(2)=0,手数,lmt,持价+3*diff,0);
END
9楼
量化资产 发表于:2018/9/27 14:32:39
diff:=0.2;手数:=1;
多持:=tbuyholdingex('623637' ,'',2 );空持:=tsellholdingex('623637' ,'',2 );
持价:=TAVGENTERPRICE;挂单价差:(ASKPRICE-BIDPRICE)/diff,NOAXIS;
DEBUGFILE('C:\TEST.TXT','挂单价差 %.0f', 挂单价差);DEBUGOUT('挂单价差 %.0f', 挂单价差);
//开仓
if 多持=0 and 空持=0 and 挂单价差>=5 then begin
tbuy (tisremain(1)=0,手数,lmt,BIDPRICE+diff,0);
tbuyshort(tisremain(3)=0,手数,lmt,ASKPRICE-diff,0);
end
//单腿
//即时成交止损单//5-10跳止损
if 多持=0 and 空持>0 and 挂单价差<3 and DYNAINFO(7)>=持价+10*diff then begin
tsellshort(tisremain(4)=0,手数,lmt,ASKPRICE+5*diff,0);
tcancel (1,1);
END
tcancel ( TSUBMIT(4)>10,4);
if 多持>0 and 空持=0 and 挂单价差<3 and DYNAINFO(7)<=持价-10*diff then begin
tsell (tisremain(2)=0,手数,lmt,BIDPRICE-5*diff,0);
tcancel (1,3);
END
tcancel ( TSUBMIT(2)>10,2);
//平仓
//即时成交止损单
if 多持>0 and 空持>0 and 挂单价差<2 then begin
tsellshort(tisremain(4)=0,手数,lmt,ASKPRICE+5*diff,0);
tsell (tisremain(2)=0,手数,lmt,BIDPRICE-5*diff,0);
END
10楼
15776220786 发表于:2019/3/24 23:31:46
麻烦问下,
持价:=T***GENTERPRICE;挂单价差:(ASKPRICE-BIDPRICE)/diff,NOAXIS; 系统说不识别,谢谢
共11 条记录, 每页显示 10 条, 页签:
[1]
[2]