有2个模型组合的策略如下,要求
若模型1当天盈利大于a则模型1第二天第三天都不交易(模型1连续休息二天,模型2仍开仓交易),
若模型2当天盈利大于b则模型2第二天第三天都不交易(模型2连续休息二天,模型1仍开仓交易),
若整个组合策略当天盈利大于c则整个策略第二天第三天都不交易(模型1模型2都连续休息2天都不开仓交易),如何写?
请老师直接把改写部分(以红字)加在如下组合策略中。谢谢
input:cang1(1,0,10,1),cang2(1,0,10,1);
variable:cc1=0,cc2=0;
/////////////////////////////////模型1——10周期反手
hi:=ref(hhv(h,10),1);
lo:=ref(llv(l,10),1);
if cc1>0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=0;
end
if cc1<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=0;
end
if cc1=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=1;
end
if cc1=0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=-1;
end
/////////////////////////////////以上是模型1
/////////////////////////////////模型2——20周期反手
hi:=ref(hhv(h,20),1);
lo:=ref(llv(l,20),1);
if cc2>0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=0;
end
if cc2<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=0;
end
if cc2=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=1;
end
if cc2=0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=-1;
end
/////////////////////////////////以上是模型2
input:cang1(1,0,10,1),cang2(1,0,10,1);
variable:cc1=0,cc2=0;
variable:bj=0;
/////////////////////////////////模型1——10周期反手
hi:=ref(hhv(h,10),1);
lo:=ref(llv(l,10),1);
if cc1>0 and l<lo and bj=0 then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=0;
end
if cc1<0 and h>hi and bj=0 then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=0;
end
if cc1=0 and h>hi and bj=0 then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=1;
end
if cc1=0 and l<lo and bj=0 then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=-1;
end
yl:valuewhen(time=closetime(0),asset-ref(asset,todaybar));
yll:stkindi('','模型2.yl',0,datatype);
if time=closetime(0) and bj=0 then begin
if yl>a then bj:=1;
if yl+yll>c then bj:=1;
end
bb:=valuewhen(bj=1 and ref(bj=0,1),barpos);
if barpos>bb+2*ref(todaybar,todaybar) and todaybar=1 then bj:=0;
input:cang1(1,0,10,1),cang2(1,0,10,1);
variable:cc1=0,cc2=0;
variable:bj=0;
hi:=ref(hhv(h,20),1);
lo:=ref(llv(l,20),1);
if cc2>0 and l<lo and bj=0 then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=0;
end
if cc2<0 and h>hi and bj=0 then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=0;
end
if cc2=0 and h>hi and bj=0 then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=1;
end
if cc2=0 and l<lo and bj=0
then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=-1;
end
yl:valuewhen(time=closetime(0),asset-ref(asset,todaybar));
yll:stkindi('','模型1.yl',0,datatype);
if time=closetime(0) and bj=0 then begin
if yl>b then bj:=1;
if yl+yll>c then bj:=1;
end
bb:=valuewhen(bj=1 and ref(bj=0,1),barpos);
if barpos>bb+2*ref(todaybar,todaybar) and todaybar=1 then bj:=0;
/////////////////////////////////以上是模型2
如果是两个策略就用上面的写
如果是一个策略则无法分清盈利情况
哦,谢谢老师。
強大的金字塔也难住了。