以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  通过vba可以查出来,连续合约是哪个具体的合约吗?  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=67454)

--  作者:pyd
--  发布时间:2014/7/16 11:10:43
--  通过vba可以查出来,连续合约是哪个具体的合约吗?
请教:通过vba可以查出来,连续合约是哪个具体的合约吗?

--  作者:王锋
--  发布时间:2014/7/16 11:13:11
--  
做遍历即可查到
--  作者:guotx2010
--  发布时间:2014/7/16 12:14:19
--  

Function GetContractCode(sMarketCode,sStockPre)    \'根据市场编码取得主力合约编码
 GetCAX" then sStockPre="AY"
 if sStockPre="SRX" then sStockPre="SRY"
  
 For j = 1 To 12
  if j<10 then
   m="0" & cstr(j)
  else
   m=cstr(j)
  end if 
  Stock=ucase(sStockPre & m)
  \'application.MsgOut sMarketCode & "," & Stock
  on error resume next    
\'  Set report1 = marketdata.GetReportData(Stock,sMarketCode)
\'  if cdbl(report1.volume)>contractvolume then
\'   contractvolume=cdbl(report1.volume)
\'   ZhuLiCode = report1.Label
\'  end if 
  if marketdata.IsExistStock(Stock,sMarketCode) then
   set report1=marketdata.GetReportData(Stock,sMarketCode)
   if report1.IsMainInstrument=1 then
    GetContractCode=Stock
    exit function
   end if 
  end if 
 Next
End Function

 

以上函数返回主力合约代码,调用方法是:aaa=GetContractCode("ZJ","IF00"),aaa就是IF对应的主力合约