论坛上,版主们讨论了如何判断主力合约。但是在跨期套利中,涉及到多个合约到期转换问题?
我的本意是通过成交量的排序来确定 相应主力合约、次月合约及季度合约,但结果却无法显示
sub heyuezhuanhuan()
Count = MarketData.GetReportCount("zj")
For i = 0 To Count-1
Set d = CreateObject("Stock.Array")
Set Report1 = MarketData.GetReportDataByIndex("zj",i)
if Left(Report1.Label,2) = "IF" Then
if Right(Report1.Label,2) >= "01" And Right(Report1.Label,2) <= "12" Then
d.AddBack(Report1.Volume)
d.sort(0)
For n = 1 To 12
application.MsgOut d.GetAt(n)
Next
End if
end if
Next
End Sub
结果数据都为0,请求大师们帮忙?
sub heyuezhuanhuan()
dim d
Set d = CreateObject("Stock.Array") '位置变了,你的代码放在循环中了,每次都会赋值
Count = MarketData.GetReportCount("ZJ")
application.MsgOut "Count:" &Count
For i = 0 To Count-1
Set Report1 = MarketData.GetReportDataByIndex("zj",i)
if Left(Report1.Label,2) = "IF" Then
if Right(Report1.Label,2) >= "01" And Right(Report1.Label,2) <= "12" Then
application.MsgOut "Volume:" &Report1.Volume
d.AddBack(cdbl(Report1.Volume))
End if
end if
Next
d.sort(0)
application.MsgOut "d.count:"&d.count
For n = 0 To d.count-1
application.MsgOut "数组中的值:"&n+1&":"&d.GetAt(n)
Next
End Sub
多使用信息输出可以快速发现问题。
谢谢 guo大师
您在套利方面的确深有研究
该贴对我和与之类似问题童鞋将有很大帮助的
通过成交量的排序来确定 相应主力合约、次月合约及季度合约
能把代码改成按持仓量的吗?
金字塔 这方面好像有点缺陷 也或许自己未找到
我之前找了好久,发现对象没有持仓量,只有成交量(volume)和成交额(Amount)。
所以 只好退而求次之,使用成交量。好在成交量与持仓量差距不是很大 。
郭大师,还是关于合约转换的问题。原意本来是通过成交量排序来确定主力、次月、季月合约等,在您的帮助下,已经完成这一步,但问题是成交量排序出来之后,无法返回去寻找到相对应的合约?
譬如,我要设最大成交量为主力合约,代码应该是IF09。但结果所有代码都是IF22.请问该如何处理?
{if Right(Report1.Label,2) >= "01" And Right(Report1.Label,2) <= "12" and Report1.Volume>0 Then} ,锁定为四个合约。
使用2维数组,来记录合约和对应的成交量,然后排序。