欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件高级功能研发区 → 套利增强

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有6178人关注过本帖树形打印复制链接

主题:套利增强

帅哥哟,离线,有人找我吗?
夏小飞
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:45 积分:270 威望:0 精华:0 注册:2010/10/14 16:38:31
套利增强  发帖心情 Post By:2010/11/15 17:33:11 [只看该作者]

'///////////////////////////////////////////////////////////////////////////////////////
dim OrderID, ConSign, Filled, Remaining, Action, OrderType, LmtPrice, Account, Kaiping, Code, Market
dim CodeT1,MarketT1
dim CodeT2,MarketT2
dim submitted09
dim submitted11
dim tradeing09,tradeing11,interestarbitrage
tradeing09=0
tradeing11=0
submitted09=0
submitted11=0
interestarbitrage=0'套利开始符
orderid09=0
orderid11=0

'//////////////////////////////////////////////////////////////////////////////////////////////
Sub APPLICATION_VBAStart()
  '设置一个定时器
  call Application.SetTimer(2,1000)
End Sub
'//////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                                                                                                                                                                                                                                                                                                                                                              
Sub TLStart()
 '注册CF09和CF11品种
 call marketdata.RegReportNotify("CF09","ZQ")
 call marketdata.RegReportNotify("CF11","ZQ")
End Sub

'响应注册的品种行情变化通知
Sub MARKETDATA_ReportNotify(ReportData)

 '得到这两个品种的行情报价
 Set Report1 = marketdata.GetReportData("CF09","ZQ")
 Set Report2 = marketdata.GetReportData("CF11","ZQ")
 
 '得到品种的持仓量等信息
 dim BuyHoding1
 dim BuyHlding2
 dim BuyTodayHoding1
 dim BuyTodayHoding2
 dim SellHoding1
 dim SellHoding2
 dim SellTodayHoding1
 dim SellTodayHoding2
 dim BuyCost
 dim SellCost
 dim PNL
 Dim UseMargin

 '取指定持仓品种信息
 call Order.HoldingInfoByCode2("CF09","ZQ",BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
 call Order.HoldingInfoByCode2("CF11","ZQ",BuyHoding2,BuyCost,BuyTodayHoding2,SellHoding2,SellCost,SellTodayHoding2,PNL,UseMargin)
 
 '当差价出现大于1800时进行套利开仓
 '假设是09买 11卖
 Diff = Report1.SellPrice1 - Report2.BuyPrice1 '分别取卖价和买价计算差价
 if Diff > 1800 and BuyHoding1 = 0 and interestarbitrage=0 then'当套利开始符=0时
    orderid09= Order.Buy(0,1,Report1.SellPrice1,0,"CF09","ZQ","",0)
    orderid11= Order.BuyShort(0,1,Report2.BuyPrice1,0,"CF11","ZQ","",0)
   interestarbitrage=1'套利开始进行
 end if
 
 '当差价小于1000时进行套利平仓
 Diff = Report1.BuyPrice1 - Report2.SellPrice1
 if diff < 1000 and BuyHoding1 > 0 and interestarbitrage=1 then'当套利开始符=1时
  call Order.Sell(0,1,Report1.BuyPrice1,0,"CF09","ZQ","",0)
  call Order.Sellshort(0,1,Report2.SellPrice1,0,"CF11","ZQ","",0)
 end if
End Sub

'//////////////////////////////////////////////////////////////////////
Sub ORDER_OrderStatus(OrderID, Status, Filled, Remaining, Price, Code, Market)

 Set Report1 = marketdata.GetReportData("AU09","SQ")
 Set Report2 = marketdata.GetReportData("AU11","SQ")

if Status="Submitted" and tradeing09=0 and tradeing11=0 then
msgbox "已提交"
if Code="AU09"and Market="SQ" then
submitted09=1'已经提交订单,在下面的if里处理已经提交的订单
end if
if Code="AU11"and Market="SQ" then
submitted11=1
end if
end if

if Status="Tradeing" or Status="Filled"  then
 
 if  Code="AU09"and Market="SQ" and submitted09=0 then
 msgbox "09已成交"
 tradeing09=1
 end if
 
 if  Code="AU11"and Market="SQ" and submitted11=0 then
 msgbox "11已成交"
 tradeing11=1
 end if
 
 if  Code="AU09"and Market="SQ" and submitted09=1 then
 msgbox "09已成交"
 tradeing09=1
 end if

 if  Code="AU11"and Market="SQ" and submitted11=1 then
 msgbox "11已成交"
 tradeing11=1
 end if

 if  tradeing09=1 and tradeing11=1 then
 msgbox "套利已完成"
 end if
 
 if tradeing09=1 or tradeing11=1 then
  if tradeing11=1 then'09没有交易
   Set Report1 = marketdata.GetReportData("AU11","SQ")
   Set Re1= Order.Sell(0,1,Report1.SellPrice1,0,"AU11","SQ","",0)
   If Re1 = 0 Then
   msgbox "11没有平成功"
   end if 
  end if
'/////////////////////////////////////////
  if tradeing09=1 then'11没有交易
   Set Report2 = marketdata.GetReportData("AU09","SQ")
   'Set Re2=
   call Order.Sell(0,1,Report2.SellPrice1,0,"AU09","SQ","",0) 
   'If Re2 =0 Then
   'msgbox "09没有平成功"
   'end if
  end if  
 end if
 msgbox "已成交"
end if

if Status="Cancelled" then
msgbox "已扯单"
end if
if Status="Inactive" then
msgbox "本次委托无效"
end if
end sub


dim Timecount09,Timecount11
Timecount09=0
Timecount11=0

Sub APPLICATION_Timer(ID)
 
 if submitted09=1 and tradeing09=0 and interestarbitrage=1 then'当套利开始符=1时
 Timecount09=Timecount09+1
 if Timecount09>5 then
 CancelOrder(orderid09)
 end if
 end if
 
 if submitted11=1 and tradeing11=0 and interestarbitrage=1 then'当套利开始符=1时
 Timecount11=Timecount11+1
 if Timecount11>5 then
 CancelOrder(orderid11)
 end if
 end if
 
End Sub


 回到顶部
帅哥哟,离线,有人找我吗?
solarhe2006
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:252 积分:1001 威望:0 精华:0 注册:2010/2/15 16:47:58
  发帖心情 Post By:2012/8/22 14:20:29 [只看该作者]

套利增强  发帖心情 Post By:2010-11-15 17:33:11 [只看该作者]

'///////////////////////////////////////////////////////////////////////////////////////
dim OrderID, ConSign, Filled, Remaining, Action, OrderType, LmtPrice, Account, Kaiping, Code, Market
dim CodeT1,MarketT1
dim CodeT2,MarketT2
dim submitted09
dim submitted11
dim tradeing09,tradeing11,interestarbitrage
tradeing09=0
tradeing11=0
submitted09=0
submitted11=0
interestarbitrage=0'套利开始符
orderid09=0
orderid11=0

'//////////////////////////////////////////////////////////////////////////////////////////////
Sub APPLICATION_VBAStart()
  '设置一个定时器
  call Application.SetTimer(2,1000)
End Sub
'//////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                                                                                                                                                                                                                                                                                                                                                              
Sub TLStart()
 '注册CF09和CF11品种
 call marketdata.RegReportNotify("CF09","ZQ")
 call marketdata.RegReportNotify("CF11","ZQ")
End Sub

'响应注册的品种行情变化通知
Sub MARKETDATA_ReportNotify(ReportData)

 '得到这两个品种的行情报价
 Set Report1 = marketdata.GetReportData("CF09","ZQ")
 Set Report2 = marketdata.GetReportData("CF11","ZQ")
 
 '得到品种的持仓量等信息
 dim BuyHoding1
 dim BuyHlding2
 dim BuyTodayHoding1
 dim BuyTodayHoding2
 dim SellHoding1
 dim SellHoding2
 dim SellTodayHoding1
 dim SellTodayHoding2
 dim BuyCost
 dim SellCost
 dim PNL
 Dim UseMargin

 '取指定持仓品种信息
 call Order.HoldingInfoByCode2("CF09","ZQ",BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
 call Order.HoldingInfoByCode2("CF11","ZQ",BuyHoding2,BuyCost,BuyTodayHoding2,SellHoding2,SellCost,SellTodayHoding2,PNL,UseMargin)
 
 '当差价出现大于1800时进行套利开仓
 '假设是09买 11卖
 Diff = Report1.SellPrice1 - Report2.BuyPrice1 '分别取卖价和买价计算差价
 if Diff > 1800 and BuyHoding1 = 0 and interestarbitrage=0 then'当套利开始符=0时
    orderid09= Order.Buy(0,1,Report1.SellPrice1,0,"CF09","ZQ","",0)
    orderid11= Order.BuyShort(0,1,Report2.BuyPrice1,0,"CF11","ZQ","",0)
   interestarbitrage=1'套利开始进行
 end if
 
 '当差价小于1000时进行套利平仓
 Diff = Report1.BuyPrice1 - Report2.SellPrice1
 if diff < 1000 and BuyHoding1 > 0 and interestarbitrage=1 then'当套利开始符=1时
  call Order.Sell(0,1,Report1.BuyPrice1,0,"CF09","ZQ","",0)
  call Order.Sellshort(0,1,Report2.SellPrice1,0,"CF11","ZQ","",0)
 end if
End Sub

'//////////////////////////////////////////////////////////////////////
Sub ORDER_OrderStatus(OrderID, Status, Filled, Remaining, Price, Code, Market)

 Set Report1 = marketdata.GetReportData("AU09","SQ")
 Set Report2 = marketdata.GetReportData("AU11","SQ")

if Status="Submitted" and tradeing09=0 and tradeing11=0 then
msgbox "已提交"
if Code="AU09"and Market="SQ" then
submitted09=1'已经提交订单,在下面的if里处理已经提交的订单
end if
if Code="AU11"and Market="SQ" then
submitted11=1
end if
end if

if Status="Tradeing" or Status="Filled"  then
 
 if  Code="AU09"and Market="SQ" and submitted09=0 then
 msgbox "09已成交"
 tradeing09=1
 end if
 
 if  Code="AU11"and Market="SQ" and submitted11=0 then
 msgbox "11已成交"
 tradeing11=1
 end if
 
 if  Code="AU09"and Market="SQ" and submitted09=1 then
 msgbox "09已成交"
 tradeing09=1
 end if

 if  Code="AU11"and Market="SQ" and submitted11=1 then
 msgbox "11已成交"
 tradeing11=1
 end if

 if  tradeing09=1 and tradeing11=1 then
 msgbox "套利已完成"
 end if
 
 if tradeing09=1 or tradeing11=1 then
  if tradeing11=1 then'09没有交易
   Set Report1 = marketdata.GetReportData("AU11","SQ")
   Set Re1= Order.Sell(0,1,Report1.SellPrice1,0,"AU11","SQ","",0)
   If Re1 = 0 Then
   msgbox "11没有平成功"
   end if 
  end if
'/////////////////////////////////////////
  if tradeing09=1 then'11没有交易
   Set Report2 = marketdata.GetReportData("AU09","SQ")
   'Set Re2=
   call Order.Sell(0,1,Report2.SellPrice1,0,"AU09","SQ","",0) 
   'If Re2 =0 Then
   'msgbox "09没有平成功"
   'end if
  end if  
 end if
 msgbox "已成交"
end if

if Status="Cancelled" then
msgbox "已扯单"
end if
if Status="Inactive" then
msgbox "本次委托无效"
end if
end sub


dim Timecount09,Timecount11
Timecount09=0
Timecount11=0

Sub APPLICATION_Timer(ID)
 
 if submitted09=1 and tradeing09=0 and interestarbitrage=1 then'当套利开始符=1时
 Timecount09=Timecount09+1
 if Timecount09>5 then
 CancelOrder(orderid09)
 end if
 end if
 
 if submitted11=1 and tradeing11=0 and interestarbitrage=1 then'当套利开始符=1时
 Timecount11=Timecount11+1
 if Timecount11>5 then
 CancelOrder(orderid11)
 end if
 end if
 
End Sub


 回到顶部
帅哥哟,离线,有人找我吗?
guotx2010
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:蜘蛛侠 帖子:1366 积分:5210 威望:0 精华:7 注册:2010/12/11 18:00:33
  发帖心情 Post By:2012/8/23 8:18:33 [只看该作者]

不错的,欠缺一点就是,如果要实现多种组合,这个代码就需要扩展了。

 回到顶部
帅哥哟,离线,有人找我吗?
sunset0920
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:36 积分:192 威望:0 精华:0 注册:2012/5/4 9:50:50
  发帖心情 Post By:2012/8/23 14:06:36 [只看该作者]

嘻嘻 不错呀

这位大侠这么早  2010-11-15 17:33:11  都搞出来了。

 

这个系统比较麻烦的是 每个月合约到期或移仓换月 需要调合约代码

 

 

对于套利,我所知道 guotx2010的郭大侠在这方面 应该有很多好东东

[此贴子已经被作者于2012-8-23 14:12:37编辑过]

 回到顶部