有关日历价差的理论基础可以参考这篇文章https://wenku.baidu.com/view/b4ea95f651e79b896902260e.html?rec_flag=default&sxts=1586769610630
//cod1表示当月合约,code2是次月合约
code1:=OPOBYPRIRCE('QQ510050',2.7,0,202004,1);
code2:=OPOBYPRIRCE('QQ510050',2.7,0,202005,1);
ss:=2;
HistoryVolatility:= VOLATILITY(50 ,'QQ510050' );
Implied_volatility1:= OPTIONINFO2(12 , code1);//取近月合约的隐含波动率
Implied_volatility2:= OPTIONINFO2(12 , code2);;//取远月合约的隐含波动率
Cond:= Implied_volatility1 - HistoryVolatility + Implied_volatility1 - Implied_volatility2;//波动率差作为信号
If Cond > 0 and TsellHOLDINGEX('' ,code1 ,1)=0 and TBUYHOLDINGEX('' ,code2 ,1)=0 and OPTIONINFO2(8,code1)>8 then
begin
tbuyshort(1,ss,lmt,DYNAINFO2(7 ,code1 ));
tbuy(1,ss,lmt,DYNAINFO2(7 ,code2 ));
end
If TBUYHOLDINGEX('' ,code1 ,1) > 0 and TBUYHOLDINGEX('' ,code2 ,1) > 0 and OPTIONINFO2(8,code1)<= 8 then
begin
tsellshort(1,TsellHOLDINGEX('' ,code1 ,1),lmt,DYNAINFO2(7 ,code1 ));
tsell(1,TBUYHOLDINGEX('' ,code2 ,1),lmt,DYNAINFO2(7 ,code2 ));
End