Rss & SiteMap

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

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

标题:[求助]我想用这种方法自动筛选主力合约

1楼
明心 发表于:2010/7/30 14:59:15

请问如何在整个期货市场或者上海期货市场比较每个品种合约的持仓量

我想用这种方法自动筛选主力合约。

在VBA中如何实现。

2楼
admin 发表于:2010/7/30 18:20:02

'该示例从郑州市场筛选SR合约得最大持仓量做为主力合约

 Sub Test()
 
 Dim MaxCode
 Dim MaxVolume
 
 '得到市场所有品种
 Count = MarketData.GetReportCount("ZQ")
 
 For i = 0 To Count-1
  Set Report1 = MarketData.GetReportDataByIndex("ZQ",i)
  '只处理SR合约
  if Left(Report1.Label,2) = "SR" Then
   '只处理有效合约
   if Right(Report1.Label,2) >= "01" And Right(Report1.Label,2) <= "12" Then
    If Report1.Volume > MaxVolume Then
     MaxCode = Report1.Label
     MaxVolume = Report1.Volume
    End if
   end if
  End if
 Next
 
 '显示成交量最大得合约
 MsgBox MaxCode
 
End Sub

[此贴子已经被作者于2010-7-30 18:20:47编辑过]
3楼
wattwei 发表于:2010/7/30 22:03:55
 '枚举合约,将主力合约的代码和对应市场代码分别作为键和值存入字典容器,供后续操作调用
sub test()
    Dim marketName
    Set dominantContract=CreateObject("Scripting.Dictionary")
    marketName=Array("SQ","DQ","ZQ","ZJ")
    prefixStockNameOld=""
    c00" And suffixStockNameCur<"99" Then
                If prefixStockNameCur<>prefixStockNameOld Then
                    If contractLabel<>"" Then
                        dominantContract.Add contractLabel,marketName(j)
                    End If
                    prefixStockNameOld=prefixStockNameCur
                    contractLabel=reportData.Label
                    contractVol=reportData.Volume
                ElseIf reportData.Volume>contractVol then
                    contractLabel=reportData.Label
                    contractVol=reportData.Volume
                End If
            End If
        Next     
    Next
    dominantContract.Add contractLabel,marketName(j-1)
    
    output=""
    labels=dominantContract.Keys
    markets=dominantContract.Items
    For i = 0 To dominantContract.Count-1
        output=output+labels(i)+vbTab+markets(i)+vbCrLf
    Next
    MsgBox output

end sub
4楼
明心 发表于:2010/8/1 14:22:48
以下是引用wattwei在2010-7-30 22:03:55的发言:
 '枚举合约,将主力合约的代码和对应市场代码分别作为键和值存入字典容器,供后续操作调用
sub test()
    Dim marketName
    Set dominantContract=CreateObject("Scripting.Dictionary")
    marketName=Array("SQ","DQ","ZQ","ZJ")
    prefixStockNameOld=""
    c00" And suffixStockNameCur<"99" Then
                If prefixStockNameCur<>prefixStockNameOld Then
                    If contractLabel<>"" Then
                        dominantContract.Add contractLabel,marketName(j)
                    End If
                    prefixStockNameOld=prefixStockNameCur
                    contractLabel=reportData.Label
                    contractVol=reportData.Volume
                ElseIf reportData.Volume>contractVol then
                    contractLabel=reportData.Label
                    contractVol=reportData.Volume
                End If
            End If
        Next     
    Next
    dominantContract.Add contractLabel,marketName(j-1)
    
    output=""
    labels=dominantContract.Keys
    markets=dominantContract.Items
    For i = 0 To dominantContract.Count-1
        output=output+labels(i)+vbTab+markets(i)+vbCrLf
    Next
    MsgBox output

end sub

这个测试通不过。

5楼
wattwei 发表于:2010/8/1 14:48:30
不太会贴代码啊,贴上来的代码掉了一截,我试试再贴上来
[此贴子已经被作者于2010-8-1 14:52:54编辑过]
6楼
wattwei 发表于:2010/8/1 14:57:24
'枚举合约,将主力合约的代码和对应市场代码分别作为键和值存入字典容器,供后续操作调用
sub test()
        Dim marketName
        Set dominantContract=CreateObject("Scripting.Dictionary")
        marketName=Array("SQ","DQ","ZQ","ZJ")
        prefixStockNameOld=""
        c00" And suffixStockNameCur < "99" Then
                                If prefixStockNameCur <> prefixStockNameOld Then
                                        If contractLabel <> "" Then
                                                dominantContract.Add contractLabel,marketName(j)
                                        End If
                                        prefixStockNameOld=prefixStockNameCur
                                        contractLabel=reportData.Label
                                        contractVol=reportData.Volume
                                ElseIf reportData.Volume > contractVol then
                                        contractLabel=reportData.Label
                                        contractVol=reportData.Volume
                                End If
                        End If
                Next   
        Next
        dominantContract.Add contractLabel,marketName(j-1)
        output=""
        labels=dominantContract.Keys
        markets=dominantContract.Items
        For i = 0 To dominantContract.Count-1
                output=output+labels(i)+vbTab+markets(i)+vbCrLf
        Next
        MsgBox output

end sub


[此贴子已经被作者于2010-8-1 15:21:28编辑过]
7楼
wattwei 发表于:2010/8/1 15:29:14
 '枚举合约,将主力合约的代码和对应市场代码分别作为键和值存入字典容器,供后续操作调用
sub test()
        Dim marketName
        Set dominantContract=CreateObject("Scripting.Dictionary")
        marketName=Array("SQ","DQ","ZQ","ZJ")
        prefixStockNameOld=""
        c00" And suffixStockNameCur < "99" Then
                                If prefixStockNameCur <> prefixStockNameOld Then
                                        If contractLabel <> "" Then
                                                dominantContract.Add contractLabel,marketName(j)
                                        End If
                                        prefixStockNameOld=prefixStockNameCur
                                        contractLabel=reportData.Label
                                        contractVol=reportData.Volume
                                ElseIf reportData.Volume > contractVol then
                                        contractLabel=reportData.Label
                                        contractVol=reportData.Volume
                                End If
                        End If
                Next    
        Next
        dominantContract.Add contractLabel,marketName(j-1)
        output=""
        labels=dominantContract.Keys
        markets=dominantContract.Items
        For i = 0 To dominantContract.Count-1
                output=output+labels(i)+vbTab+markets(i)+vbCrLf
        Next
        MsgBox output

end sub

8楼
wattwei 发表于:2010/8/1 15:37:39
还是不对,发送之前在哪里预览啊?找不到预览的按钮 图片点击可在新窗口打开查看
9楼
明心 发表于:2010/8/1 15:39:01

直接发给我吧。

 

10楼
明心 发表于:2010/8/1 15:41:44
QQ80779898
共16 条记录, 每页显示 10 条, 页签: [1] [2]


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