以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  当天盈利大于a则模型1第二天第三天都不交易如何写?  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=94507)

--  作者:LCY
--  发布时间:2016/3/8 20:32:58
--  当天盈利大于a则模型1第二天第三天都不交易如何写?

有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


--  作者:jinzhe
--  发布时间:2016/3/9 9:51:16
--  

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;

 

 


--  作者:jinzhe
--  发布时间:2016/3/9 9:53:17
--  

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


--  作者:LCY
--  发布时间:2016/3/9 13:20:57
--  
谢谢老师。
可能我没讲清楚,一楼的模型1与模型2组合成一个策略的,也就是说模是同一个策略里的二个组成部分。yl是整个策略的盈利yl>C,老师把模分拆成二个策略了。
请老师在同一个策略里修改。

--  作者:LCY
--  发布时间:2016/3/9 13:21:46
--  
谢谢老师。
可能我没讲清楚,一楼的模型1与模型2组合成一个策略的,也就是说模型1与模型2是同一个策略里的二个组成部分。yl是整个策略的盈利yl>C,老师把模型1与模型2分拆成二个策略了。
请老师在同一个策略里修改。

--  作者:jinzhe
--  发布时间:2016/3/9 13:26:01
--  

如果是两个策略就用上面的写

如果是一个策略则无法分清盈利情况


--  作者:LCY
--  发布时间:2016/3/9 13:29:29
--  
模型1(模型2)的当天盈利可否通过平仓价一开仓价来解决呢?
--  作者:jinzhe
--  发布时间:2016/3/9 13:31:49
--  
你写在一起,开仓价平仓价分不清是第一部分还是第二部分的
--  作者:LCY
--  发布时间:2016/3/9 14:24:38
--  

哦,谢谢老师。

 

強大的金字塔也难住了。


--  作者:JDS
--  发布时间:2016/3/9 15:40:52
--  
 请问老师如果模型1当天盈利大于a,第二天不休息继续交易只是自动由实盘帐户如123456#转为模拟帐户如600888#,怎么写?