多个模型,各自有若干对开平策略,写法也各不相同,没法整合为一个模型。
有没办法通过引用各模型的持仓状态,来达到以下目的:
当每个模型都holding<0的时候,开仓做空;
其中一个模型反多或平仓的时候,平空。
可以的,通过stkindi函数,引用N个模型的持仓,然后汇总起来处理即可:
if c1+c2+...=N and holding=0 then buyshort(1,1,market);
if c1+c2+...>N and holding<0 then sellshort(1,1,market);
以下是引用Ivan在2014/4/8 0:39:56的发言:
可以的,通过stkindi函数,引用N个模型的持仓,然后汇总起来处理即可:
if c1+c2+...=N and holding=0 then buyshort(1,1,market);
if c1+c2+...>N and holding<0 then sellshort(1,1,market);
问题就是如何引用持仓?
如下写法正确吗?
C1:=stkindi('','holding,模型1',0,1);
貌似不对。
rr1:=stkindiex('if00','qq20.持仓',0,21,2,0);
rr2:=stkindi('if00','qq7.持仓',0,1);
//rr3:=stkindi('if00','qq12.持仓',0,22,110);
//rr4:=stkindi('if00','qq12.持仓',0,22,125);
//rr5:=stkindi('if00','qq12.持仓',0,22,130);
//rr6:=stkindi('if00','qq12.持仓',0,22,95);
//rr7:=stkindi('if00','qq12.持仓',0,22,90);
//r11:=stkindi('if00','qq31.持仓',0,11);
r12:=rr1+rr2;
//********************************
hd:=if(islastbar,3,2.0);
hd1:=if(islastbar,3,0.1);
//********************************
if holding=0 and r12>0 then buy(1,r12,limitr,c+hd1);
if holding=0 and r12<0 then buyshort(1,abs(r12),limitr,c-hd1);
if holding>0 and r12>0 and holding>r12 then sell(1,holding-r12,limitr,c-hd1);
if holding>0 and r12>0 and holding<r12 then buy(1,r12-holding,limitr,c+hd1);
if holding>0 and r12<0 then
begin
sell(1,holding,limitr,c-hd1);
buyshort(1,abs(r12),limitr,c-hd1);
end
if holding<0 and r12<0 and holding>r12 then buyshort(1,holding-r12,limitr,c-hd1);
if holding<0 and r12<0 and holding<r12 then sellshort(1,r12-holding,limitr,c+hd1);
if holding<0 and r12>0 then
begin
sellshort(1,holding,limitr,c+hd1);
buy(1,r12,limitr,c+hd1);
end
[此贴子已经被作者于2014/4/8 21:22:51编辑过]