以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  汇总持仓量到指定合约  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=4977)

--  作者:明心
--  发布时间:2011/1/25 11:32:04
--  汇总持仓量到指定合约
说明:代码需要机器较好者使用,不然死机。因为数据运算较多。
Set dominantContract=CreateObject("Scripting.Dictionary")

\'枚举合约,将主力合约的代码和对应市场代码分别作为键和值存入字典容器,供后续操作调用
sub GetDominantContract()
 Dim marketName
 dominantContract.RemoveAll
 marketName=Array("SQ","DQ","ZQ","ZJ")
 prefixStockNameOld=""
 c"
 contractVol=0
  
 For j=0 To UBound(marketName)
  n=marketData.GetReportCount(marketName(j))
  For i=0 To n-1
   Set reportData=marketdata.GetReportDataByIndex(marketName(j),i)
   prefixStockNameCur=left(reportData.StockName,2)
   suffixStockNameCur=right(reportData.StockName,2)
   If suffixStockNameCur="连续" And reportData.Volume>0 Then   \'这里指定的是连续合约,可以根据需要修改
     If contractLabel<>"" Then
      dominantContract.Add contractLabel,contractMarket
     End If
     prefixStockNameOld=prefixStockNameCur
     contractLabel=reportData.Label
     contractMarket=marketName(j)
   End If
  Next  
 Next
 dominantContract.Add contractLabel,contractMarket
 
end sub

Sub chuli()
 labels=dominantContract.Keys
 markets=dominantContract.Items
 \'创建主力合约输出暂存对象
 \'Set b = CreateObject("Stock.Block")
 \'output=""
    zhouqi=Array(0,1,5)
   
 For i = 0 To dominantContract.Count-1
      Set reportData=marketdata.GetReportData(labels(i),markets(i))
      longstr = len(reportData.StockName)
      name = left(reportData.StockName,longstr-4)
         For j=0 To UBound(zhouqi)
             Set History = marketdata.GetHistoryData(labels(i),markets(i),zhouqi(j))
                 for k = 0 to History.Count-1
                     date2 =  History.date(k)
                     Count = MarketData.GetReportCount(markets(i))
                     for w =0 to Count-1
                     Set ReportData1 = MarketData.GetReportDataByIndex(markets(i),w)
                     longstr1 = len(reportData1.StockName)
                  name1 = left(reportData1.StockName,longstr1-4)
                         \'只处理该品种合约
                         if name1 = name Then
                            \'只处理有效合约
                            if Right(ReportData1.Label,2) >= "01" And Right(ReportData1.Label,2) <= "12" Then
                               Openint = History1.Openint(k)
                               date1 =  History1.date(k)
                               if date1 = date2 then
                                  ccl = Openint+ccl
                               end if
                             End if
                         end if
                     Next

                     History.Openint(k) = ccl
                     call History.SaveData(labels(i),markets(i),zhouqi(j))
                 Next
         Next
    Next
    application.MsgOut "连续合约持仓数据更新完毕!"

End Sub

Sub lianxuchicang()

call GetDominantContract()
call chuli()

End Sub

 


 

由于论坛的原因,部分VBS代码无法贴出,给出文本文件

http://www.weistock.com/download/ccl.txt 


--  作者:明心
--  发布时间:2011/1/25 11:32:55
--  
要求加精给金币。嘿嘿
--  作者:明心
--  发布时间:2011/1/25 11:47:28
--  
就2个金币啊。管理员太小气了。图片点击可在新窗口打开查看