Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共6 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:新年献礼:获取主力合约最简单的VBA代码

1楼
guotx2010 发表于:2012/1/29 14:00:47

'本过程需要两个参数

'1.sMarketCode市场代码,如中金所是ZJ,上期所SQ,郑商所ZQ,大连所DQ

'2.sStockPre品种代码的前缀,如股指IF,螺纹钢RB等,就是合约代码的符号,不要月份。

'调用方法:GetContractCode 'ZJ','IF'      '返回股指期货的主力合约

'调用上述过程之后,ZhuLiCode就保存了主力合约的代码

'本方法是通过判断那个合约的成交量与连续合约的成交量相等的方式来判断主力合约的,跟金字塔内部的方式一致。

 

public ZhuLiCode     '主力合约代码

Sub GetContractCode(sMarketCode,sStockPre)    '根据市场编码取得主力合约编码
 If sMarketCode="" then
  sMarketCode="ZJ"
 End if 
 
 n = marketdata.GetReportCount(sMarketCode)
 
 For j = 0 To n - 1
  Set report1 = marketdata.GetReportDataByIndex(sMarketCode, j)
  suffixlabel = Right(report1.Label, 2)
  If sStockPre=left(report1.Label,len(sStockPre)) then
   If suffixlabel = "00" Then
    ZhuLiVol=report1.volume
   End If
 
   If cdbl(suffixlabel) >= 1 And cdbl(suffixlabel) <= 12 Then
    If report1.volume = ZhuLiVol Then
     ZhuLiCode = report1.Label
     'application.MsgOut ZhuLiCode
     exit for
    End If
   End If
  End if 
 Next
End Sub

2楼
meteor528528 发表于:2012/2/2 11:28:53
图片点击可在新窗口打开查看
3楼
solarhe2006 发表于:2012/5/6 23:33:36

'本过程需要两个参数

'1.sMarketCode市场代码,如中金所是ZJ,上期所SQ,郑商所ZQ,大连所DQ

'2.sStockPre品种代码的前缀,如股指IF,螺纹钢RB等,就是合约代码的符号,不要月份。

'调用方法:GetContractCode 'ZJ','IF'      '返回股指期货的主力合约

'调用上述过程之后,ZhuLiCode就保存了主力合约的代码

'本方法是通过判断那个合约的成交量与连续合约的成交量相等的方式来判断主力合约的,跟金字塔内部的方式一致。

 

public ZhuLiCode     '主力合约代码

Sub GetContractCode(sMarketCode,sStockPre)    '根据市场编码取得主力合约编码
 If sMarketCode="" then
  sMarketCode="ZJ"
 End if 
 
 n = marketdata.GetReportCount(sMarketCode)
 
 For j = 0 To n - 1
  Set report1 = marketdata.GetReportDataByIndex(sMarketCode, j)
  suffixlabel = Right(report1.Label, 2)
  If sStockPre=left(report1.Label,len(sStockPre)) then
   If suffixlabel = "00" Then
    ZhuLiVol=report1.volume
   End If
 
   If cdbl(suffixlabel) >= 1 And cdbl(suffixlabel) <= 12 Then
    If report1.volume = ZhuLiVol Then
     ZhuLiCode = report1.Label
     'application.MsgOut ZhuLiCode
     exit for
    End If
   End If
  End if 
 Next
End Sub

4楼
shawaverage 发表于:2012/9/10 19:12:44
粘贴进去,公式测评显示语句末尾缺少分号,麻烦请指导下。谢谢
5楼
guotx2010 发表于:2012/9/10 22:03:28
朋友,这个是vba代码,不是pel语言的,不能用在公式或策略中的。
6楼
sunset0920 发表于:2012/9/20 11:08:02

 非常感兴趣的是 如何获取次主力合约代码

 

没见到有强人在讨论。

共6 条记录, 每页显示 10 条, 页签: [1]


Powered By Dvbbs Version 8.3.0
Processed in 0.03223 s, 2 queries.