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


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

   

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


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

主题:VBA套利模型范例

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


加好友 发短信
等级:管理员 帖子:7302 积分:32559 威望:1000 精华:45 注册:2003/12/30 16:34:32
VBA套利模型范例  发帖心情 Post By:2010/7/14 15:02:03 [显示全部帖子]

首先我们建立一个TLStart的宏,然后再响应品种报表数据变化事件,代码如下:

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 then
  call Order.Buy(0,1,Report1.SellPrice1,0,"CF09","ZQ","",0)
  call Order.BuyShort(0,1,Report2.BuyPrice1,0,"CF11","ZQ","",0)
 end if
 
 '当差价小于1000时进行套利平仓
 Diff = Report1.BuyPrice1 - Report2.SellPrice1
 if diff < 1000 and BuyHoding1 > 0 then
  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

 

代码编写完毕后Alt+F8,然后选择我们刚才建立的TLStart宏名即可

[此贴子已经被作者于2010-7-14 21:54:24编辑过]

[本帖被加为精华]
 回到顶部